Skip to content

Commit 45c1746

Browse files
committed
e2e: check PerformanceProfile replacement
Check that PerformanceProfile replacement doesn't add additional configmap status. This test is excersing the bug to avoid regressions in the future. Signed-off-by: Talor Itzhak <[email protected]>
1 parent 8d15ccd commit 45c1746

File tree

4 files changed

+97
-4
lines changed

4 files changed

+97
-4
lines changed

test/e2e/performanceprofile/functests/0_config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func printEnvs() {
264264
name, _ := os.LookupEnv(hypershift.HostedClusterNameEnv)
265265
testlog.Infof("%s=%s", hypershift.HostedClusterNameEnv, name)
266266

267-
v, _ := hypershift.GetManagementClusterNamespace()
267+
v, _ := hypershift.GetHostedControlPlaneNamespace()
268268
testlog.Infof("%s=%s", hypershift.HostedControlPlaneNamespaceEnv, v)
269269

270270
kcPath, _ := os.LookupEnv(hypershift.ManagementClusterKubeConfigEnv)

test/e2e/performanceprofile/functests/3_performance_status/status.go

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package __performance_status
33
import (
44
"context"
55
"encoding/json"
6+
"fmt"
67
"time"
78

89
"github.com/onsi/gomega/gcustom"
910
types2 "github.com/onsi/gomega/types"
10-
tunedutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/tuned"
11+
"k8s.io/apimachinery/pkg/labels"
1112

1213
. "github.com/onsi/ginkgo/v2"
1314
. "github.com/onsi/gomega"
@@ -21,8 +22,11 @@ import (
2122

2223
ign2types "github.com/coreos/ignition/config/v2_2/types"
2324
machineconfigv1 "github.com/openshift/api/machineconfiguration/v1"
25+
performancev2 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/performanceprofile/v2"
2426
tunedv1 "github.com/openshift/cluster-node-tuning-operator/pkg/apis/tuned/v1"
2527
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/components"
28+
"github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/hypershift"
29+
hypershiftconsts "github.com/openshift/cluster-node-tuning-operator/pkg/performanceprofile/controller/performanceprofile/hypershift/consts"
2630
testutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils"
2731
testclient "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/client"
2832
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/discovery"
@@ -32,6 +36,7 @@ import (
3236
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodepools"
3337
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/nodes"
3438
"github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/profiles"
39+
tunedutils "github.com/openshift/cluster-node-tuning-operator/test/e2e/performanceprofile/functests/utils/tuned"
3540
v1 "github.com/openshift/custom-resource-status/conditions/v1"
3641
)
3742

@@ -139,6 +144,74 @@ var _ = Describe("Status testing of performance profile", Ordered, func() {
139144
profiles.WaitForCondition(testutils.NodeSelectorLabels, v1.ConditionDegraded, corev1.ConditionTrue)
140145
})
141146
})
147+
148+
Context("Hypershift specific status validation", Label(string(label.HyperShift)), func() {
149+
var profile *performancev2.PerformanceProfile
150+
ctx := context.Background()
151+
BeforeEach(func() {
152+
profile, err = profiles.GetByNodeLabels(testutils.NodeSelectorLabels)
153+
Expect(err).ToNot(HaveOccurred())
154+
})
155+
156+
It("Should have ConfigMap status when running on HyperShift platform", Label(string(label.HyperShift)), func() {
157+
hcpNs, err := hypershiftutils.GetHostedControlPlaneNamespace()
158+
Expect(err).ToNot(HaveOccurred())
159+
160+
np, err := nodepools.GetNodePool(ctx, testclient.ControlPlaneClient)
161+
Expect(err).ToNot(HaveOccurred())
162+
163+
cm := &corev1.ConfigMap{}
164+
cmName := hypershift.GetStatusConfigMapName(fmt.Sprintf("%s-%s", profile.GetName(), np.GetName()))
165+
key := client.ObjectKey{Namespace: hcpNs, Name: cmName}
166+
Expect(testclient.ControlPlaneClient.Get(ctx, key, cm)).To(Succeed(), "failed to find ConfigMap %s/%s", hcpNs, cmName)
167+
})
168+
169+
It("Should not create more than a single ConfigMap status per nodePool when PerformanceProfile gets replace or updated", Label(string(label.HyperShift)), func() {
170+
hcpNs, err := hypershiftutils.GetHostedControlPlaneNamespace()
171+
Expect(err).ToNot(HaveOccurred())
172+
173+
np, err := nodepools.GetNodePool(ctx, testclient.ControlPlaneClient)
174+
Expect(err).ToNot(HaveOccurred())
175+
176+
newProfile := profile.DeepCopy()
177+
newProfile.Name = fmt.Sprintf("%s-2", profile.Name)
178+
Expect(testclient.ControlPlaneClient.Create(ctx, newProfile)).To(Succeed())
179+
180+
// Cleanup: revert back to the original profile and delete the temporary one
181+
defer func() {
182+
By("Reverting back to the original profile")
183+
Expect(nodepools.ReplaceTuningObject(ctx, testclient.ControlPlaneClient, profile, newProfile)).To(Succeed())
184+
185+
By("Waiting for node pool configuration to revert")
186+
Expect(nodepools.WaitForConfigToBeReady(ctx, testclient.ControlPlaneClient, np.Name, np.Namespace)).To(Succeed())
187+
188+
By("Deleting the temporary profile")
189+
Expect(testclient.ControlPlaneClient.Delete(ctx, newProfile)).To(Succeed())
190+
}()
191+
192+
Expect(nodepools.ReplaceTuningObject(ctx, testclient.ControlPlaneClient, newProfile, profile)).To(Succeed())
193+
194+
// nothing changed in the profile but the name, so the nodepool will be transition into updating state for a really
195+
// short time.
196+
// to make sure it's not being missing, the test will only wait for updated state.
197+
By("Waiting to see no more than a single configmap status created")
198+
Consistently(func() {
199+
cmList := &corev1.ConfigMapList{}
200+
opts := &client.ListOptions{
201+
Namespace: hcpNs,
202+
LabelSelector: labels.SelectorFromSet(map[string]string{
203+
hypershiftconsts.NTOGeneratedPerformanceProfileStatusConfigMapLabel: "true",
204+
hypershiftconsts.NodePoolNameLabel: np.GetName(),
205+
}),
206+
}
207+
Expect(testclient.ControlPlaneClient.List(ctx, cmList, opts)).To(Succeed())
208+
Expect(cmList.Items).To(HaveLen(1), "More than a single ConfigMap status was found")
209+
}).WithPolling(time.Second * 10).WithTimeout(time.Minute * 2)
210+
211+
By("Waiting for the node pool configuration to be ready")
212+
Expect(nodepools.WaitForConfigToBeReady(ctx, testclient.ControlPlaneClient, np.Name, np.Namespace)).To(Succeed())
213+
})
214+
})
142215
})
143216

144217
func createBadMachineConfig(name string) *machineconfigv1.MachineConfig {

test/e2e/performanceprofile/functests/utils/hypershift/hypershift.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func BuildControlPlaneClient() (client.Client, error) {
3434
if err != nil {
3535
return nil, err
3636
}
37-
ns, err := GetManagementClusterNamespace()
37+
ns, err := GetHostedControlPlaneNamespace()
3838
if err != nil {
3939
return nil, fmt.Errorf("failed to build management-cluster client for hypershift; err %v", err)
4040
}
@@ -57,7 +57,7 @@ func GetHostedClusterName() (string, error) {
5757
return v, nil
5858
}
5959

60-
func GetManagementClusterNamespace() (string, error) {
60+
func GetHostedControlPlaneNamespace() (string, error) {
6161
ns, ok := os.LookupEnv(HostedControlPlaneNamespaceEnv)
6262
if !ok {
6363
return "", fmt.Errorf("failed to retrieve management cluster namespace; %q environment var is not set", HostedControlPlaneNamespaceEnv)

test/e2e/performanceprofile/functests/utils/nodepools/nodepools.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,26 @@ func AttachTuningObjectToNodePool(ctx context.Context, cli client.Client, object
156156
return nil
157157
}
158158

159+
// ReplaceTuningObject works similar to AttachTuningObject but replaces one object with another instead of appending
160+
func ReplaceTuningObject(ctx context.Context, cli client.Client, newObject, oldObject client.Object) error {
161+
var err error
162+
np, err := GetNodePool(ctx, cli)
163+
if err != nil {
164+
return err
165+
}
166+
167+
updatedTuningConfig := corev1.LocalObjectReference{Name: newObject.GetName()}
168+
for i, tuningConfig := range np.Spec.TuningConfig {
169+
if tuningConfig.Name == oldObject.GetName() {
170+
np.Spec.TuningConfig[i] = updatedTuningConfig
171+
}
172+
}
173+
if cli.Update(ctx, np) != nil {
174+
return err
175+
}
176+
return nil
177+
}
178+
159179
func DeattachTuningObject(ctx context.Context, cli client.Client, object client.Object) error {
160180
np, err := GetNodePool(ctx, cli)
161181
if err != nil {

0 commit comments

Comments
 (0)