@@ -3,11 +3,12 @@ package __performance_status
33import  (
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
144217func  createBadMachineConfig (name  string ) * machineconfigv1.MachineConfig  {
0 commit comments