Skip to content

Commit 0c58628

Browse files
Merge pull request #5367 from isabella-janssen/ocpbugs-52302-4.20
[release-4.20] OCPBUGS-59766: Update timing of MCN desired config spec update to align with node annotation setting
2 parents b9dbf39 + bab0622 commit 0c58628

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

pkg/controller/node/node_controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
helpers "github.com/openshift/machine-config-operator/pkg/helpers"
12+
"github.com/openshift/machine-config-operator/pkg/upgrademonitor"
1213

1314
configv1 "github.com/openshift/api/config/v1"
1415
features "github.com/openshift/api/features"
@@ -1288,14 +1289,16 @@ func (ctrl *Controller) updateCandidateNode(mosc *mcfgv1.MachineOSConfig, mosb *
12881289
}
12891290

12901291
lns := ctrlcommon.NewLayeredNodeState(oldNode)
1292+
desiredConfig := ""
12911293
if !layered {
12921294
lns.SetDesiredStateFromPool(pool)
1295+
desiredConfig = pool.Spec.Configuration.Name
12931296
} else {
12941297
lns.SetDesiredStateFromMachineOSConfig(mosc, mosb)
1298+
desiredConfig = mosb.Spec.MachineConfig.Name
12951299
}
12961300

12971301
// Set the desired state to match the pool.
1298-
12991302
newData, err := json.Marshal(lns.Node())
13001303
if err != nil {
13011304
return err
@@ -1306,6 +1309,12 @@ func (ctrl *Controller) updateCandidateNode(mosc *mcfgv1.MachineOSConfig, mosb *
13061309
return nil
13071310
}
13081311

1312+
// Populate the desired config version and image annotations in the node's MCN
1313+
err = upgrademonitor.UpdateMachineConfigNodeSpecDesiredAnnotation(ctrl.fgHandler, ctrl.client, nodeName, desiredConfig)
1314+
if err != nil {
1315+
klog.Errorf("error populating MCN for desired config version and image updates: %v", err)
1316+
}
1317+
13091318
klog.V(4).Infof("Pool %s: layered=%v node %s update is needed", pool.Name, layered, nodeName)
13101319
patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, corev1.Node{})
13111320
if err != nil {

pkg/upgrademonitor/upgrade_monitor.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
339375
func GenerateAndApplyMachineConfigNodeSpec(fgHandler ctrlcommon.FeatureGatesHandler, pool string, node *corev1.Node, mcfgClient mcfgclientset.Interface) error {
340376
if fgHandler == nil || node == nil {

0 commit comments

Comments
 (0)