@@ -70,6 +70,35 @@ func (h *handler) Exists(ctx context.Context, profileName string) bool {
7070 return false
7171}
7272
73+ func (h * handler ) applyTuned (ctx context.Context , profile * performancev2.PerformanceProfile , mfs * manifestset.ManifestResultSet , cfgmap * corev1.ConfigMap ) ([]string , error ) {
74+ // Get mutated performance tuned.
75+ performanceTunedMutated , err := resources .GetMutatedTuned (ctx , h .controlPlaneClient , mfs .Tuned )
76+ if err != nil {
77+ return nil , err
78+ }
79+
80+ // The Tuned CR must be created first so the tuned operand can calculate bootcmdline.
81+ if performanceTunedMutated != nil {
82+ cm , err := EncapsulateObjInConfigMap (h .scheme , cfgmap , mfs .Tuned , profile .Name , hypershiftconsts .TuningKey , map [string ]string {hypershiftconsts .ControllerGeneratedTunedConfigMapLabel : "true" })
83+ if err != nil {
84+ return nil , err
85+ }
86+ err = createOrUpdateTunedConfigMap (ctx , h .controlPlaneClient , cm )
87+ if err != nil {
88+ return nil , err
89+ }
90+ }
91+
92+ // Get kernel arguments from tuned bootcmdline. This will wait for tuned to calculate and agree on them.
93+ // In other words, if bootcmdline is not ready or nodes disagree, an error is returned.
94+ kernelArguments , err := resources .GetKernelArgumentsFromTunedBootcmdline (ctx , h .dataPlaneClient , profile )
95+ if err != nil {
96+ return nil , err
97+ }
98+
99+ return kernelArguments , nil
100+ }
101+
73102func (h * handler ) Apply (ctx context.Context , obj client.Object , recorder record.EventRecorder , options * components.Options ) error {
74103 instance , ok := obj .(* corev1.ConfigMap )
75104 if ! ok {
@@ -91,25 +120,29 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
91120 klog .Infof ("ignoring reconcile loop for pause performance profile %s" , profile .Name )
92121 return nil
93122 }
94-
95123 // set missing options
96124 options .MachineConfig .MixedCPUsEnabled = options .MixedCPUsFeatureGateEnabled && profileutil .IsMixedCPUsEnabled (profile )
97125
98- // First, create components WITHOUT kernel arguments to bootstrap the system.
99- // The Tuned CR must be created first so the tuned operand can calculate bootcmdline.
100126 mfs , err := manifestset .GetNewComponents (profile , options )
101127 if err != nil {
102128 return err
103129 }
104130
105- // get mutated kubelet config
106- kcMutated , err := resources . GetMutatedKubeletConfig (ctx , h . controlPlaneClient , mfs . KubeletConfig )
131+ // The Tuned CR must be created first so the tuned operand can calculate bootcmdline.
132+ kernelArguments , err := h . applyTuned (ctx , profile , mfs , instance )
107133 if err != nil {
108134 return err
109135 }
136+ options .MachineConfig .KernelArguments = kernelArguments
110137
111- // get mutated performance tuned
112- performanceTunedMutated , err := resources .GetMutatedTuned (ctx , h .controlPlaneClient , mfs .Tuned )
138+ // get mutated machine config
139+ mcMutated , err := resources .GetMutatedMachineConfig (ctx , h .controlPlaneClient , mfs .MachineConfig )
140+ if err != nil {
141+ return err
142+ }
143+
144+ // get mutated kubelet config
145+ kcMutated , err := resources .GetMutatedKubeletConfig (ctx , h .controlPlaneClient , mfs .KubeletConfig )
113146 if err != nil {
114147 return err
115148 }
@@ -120,15 +153,23 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
120153 return err
121154 }
122155
123- // Create/Update Tuned, KubeletConfig, and RuntimeClass first (without waiting for bootcmdline)
124- if performanceTunedMutated != nil {
125- cm , err := EncapsulateObjInConfigMap (h .scheme , instance , mfs .Tuned , profile .Name , hypershiftconsts .TuningKey , map [string ]string {hypershiftconsts .ControllerGeneratedTunedConfigMapLabel : "true" })
156+ updated := mcMutated != nil ||
157+ kcMutated != nil ||
158+ runtimeClassMutated != nil
159+
160+ // do not update any resources if no changes are present and continue to the status update
161+ if ! updated {
162+ return nil
163+ }
164+
165+ if mcMutated != nil {
166+ cm , err := EncapsulateObjInConfigMap (h .scheme , instance , mfs .MachineConfig , profile .Name , hypershiftconsts .ConfigKey , map [string ]string {hypershiftconsts .NTOGeneratedMachineConfigLabel : "true" })
126167 if err != nil {
127- return fmt . Errorf ( "failed to encapsulate Tuned in ConfigMap: %w" , err )
168+ return err
128169 }
129- err = createOrUpdateTunedConfigMap (ctx , h .controlPlaneClient , cm )
170+ err = createOrUpdateMachineConfigConfigMap (ctx , h .controlPlaneClient , cm )
130171 if err != nil {
131- return fmt . Errorf ( "failed to create/update tuned ConfigMap: %w" , err )
172+ return err
132173 }
133174 }
134175
@@ -138,63 +179,23 @@ func (h *handler) Apply(ctx context.Context, obj client.Object, recorder record.
138179 hypershiftconsts .KubeletConfigConfigMapLabel : "true" ,
139180 })
140181 if err != nil {
141- return fmt . Errorf ( "failed to encapsulate KubeletConfig in ConfigMap: %w" , err )
182+ return err
142183 }
143184 err = createOrUpdateKubeletConfigConfigMap (ctx , h .controlPlaneClient , cm )
144185 if err != nil {
145- return fmt . Errorf ( "failed to create/update kubeletConfig ConfigMap: %w" , err )
186+ return err
146187 }
147188 }
148189
149190 if runtimeClassMutated != nil {
150- if err := resources .CreateOrUpdateRuntimeClass (ctx , h .dataPlaneClient , runtimeClassMutated ); err != nil {
151- return fmt .Errorf ("failed to create/update RuntimeClass: %w" , err )
152- }
153- }
154-
155- // Get kernel arguments from tuned bootcmdline. This will wait for tuned to calculate them.
156- kernelArguments , err := resources .GetKernelArgumentsFromTunedBootcmdline (ctx , h .dataPlaneClient , profile )
157- if err != nil {
158- return err
159- }
160-
161- // Update options with kernel arguments and create/update MachineConfig
162- options .MachineConfig .KernelArguments = kernelArguments
163- if err := h .syncMachineConfig (ctx , instance , profile , options ); err != nil {
164- return err
165- }
166-
167- klog .InfoS ("Processed ok" , "instanceName" , instance .Name )
168- recorder .Eventf (instance , corev1 .EventTypeNormal , "Creation succeeded" , "Succeeded to create all components for PerformanceProfile" )
169- return nil
170- }
171-
172- // syncMachineConfig creates or updates the MachineConfig with the provided kernel arguments
173- func (h * handler ) syncMachineConfig (ctx context.Context , instance * corev1.ConfigMap , profile * performancev2.PerformanceProfile , options * components.Options ) error {
174- // Generate MachineConfig with kernel arguments
175- mfs , err := manifestset .GetNewComponents (profile , options )
176- if err != nil {
177- return err
178- }
179-
180- // get mutated machine config with kernel arguments
181- mcMutated , err := resources .GetMutatedMachineConfig (ctx , h .controlPlaneClient , mfs .MachineConfig )
182- if err != nil {
183- return err
184- }
185-
186- // Create/Update MachineConfig only after bootcmdline is ready
187- if mcMutated != nil {
188- cm , err := EncapsulateObjInConfigMap (h .scheme , instance , mfs .MachineConfig , profile .Name , hypershiftconsts .ConfigKey , map [string ]string {hypershiftconsts .NTOGeneratedMachineConfigLabel : "true" })
189- if err != nil {
190- return err
191- }
192- err = createOrUpdateMachineConfigConfigMap (ctx , h .controlPlaneClient , cm )
191+ err = resources .CreateOrUpdateRuntimeClass (ctx , h .dataPlaneClient , runtimeClassMutated )
193192 if err != nil {
194193 return err
195194 }
196195 }
197196
197+ klog .InfoS ("Processed ok" , "instanceName" , instance .Name )
198+ recorder .Eventf (instance , corev1 .EventTypeNormal , "Creation succeeded" , "Succeeded to create all components for PerformanceProfile" )
198199 return nil
199200}
200201
0 commit comments