@@ -335,6 +335,42 @@ func isSingletonCondition(singletonConditionTypes []mcfgv1.StateProgress, condit
335335 return false
336336}
337337
338+ // UpdateMachineConfigNodeSpecDesiredAnnotation sets the desired config version in the `Spec` of an
339+ // existing MachineConfigNode resource
340+ func UpdateMachineConfigNodeSpecDesiredAnnotation (fgHandler ctrlcommon.FeatureGatesHandler , mcfgClient mcfgclientset.Interface , nodeName , desiredConfig string ) error {
341+ if fgHandler == nil {
342+ return nil
343+ }
344+
345+ // Check that the MachineConfigNode feature gate is enabled
346+ if ! fgHandler .Enabled (features .FeatureGateMachineConfigNodes ) {
347+ klog .Infof ("MachineConfigNode FeatureGate is not enabled." )
348+ return nil
349+ }
350+
351+ // Get the existing MCN
352+ mcn , mcnErr := mcfgClient .MachineconfigurationV1 ().MachineConfigNodes ().Get (context .TODO (), nodeName , metav1.GetOptions {})
353+ // Note that this function is only intended to update the Spec of an existing MCN. We should
354+ // not reach this point if there is not an existing MCN for a node, but we need to handle the
355+ // DNE and other potential error situations just in case.
356+ if mcnErr != nil {
357+ return mcnErr
358+ }
359+
360+ // Set the desired config annotation
361+ mcn .Spec .ConfigVersion .Desired = NotYetSet
362+ if desiredConfig != "" {
363+ mcn .Spec .ConfigVersion .Desired = desiredConfig
364+ }
365+
366+ // Update the MCN resource
367+ if _ , err := mcfgClient .MachineconfigurationV1 ().MachineConfigNodes ().Update (context .TODO (), mcn , metav1.UpdateOptions {FieldManager : "machine-config-operator" }); err != nil {
368+ return fmt .Errorf ("failed to update the %s mcn spec with the new desired config value: %w" , nodeName , err )
369+ }
370+
371+ return nil
372+ }
373+
338374// GenerateAndApplyMachineConfigNodeSpec generates and applies a new MCN spec based off the node state
339375func GenerateAndApplyMachineConfigNodeSpec (fgHandler ctrlcommon.FeatureGatesHandler , pool string , node * corev1.Node , mcfgClient mcfgclientset.Interface ) error {
340376 if fgHandler == nil || node == nil {
0 commit comments