Skip to content

Commit

Permalink
Merge pull request #4697 from djoshy/mcn-failures
Browse files Browse the repository at this point in the history
OCPBUGS-42816: MachineConfigNode objects should not produce too many invalid apply requests
  • Loading branch information
openshift-merge-bot[bot] authored Nov 15, 2024
2 parents ce3fe1f + c6f76c5 commit 47a4dc7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pkg/upgrademonitor/upgrade_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
applyconfigurationsmeta "k8s.io/client-go/applyconfigurations/meta/v1"
"k8s.io/klog/v2"

daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants"
)

const NotYetSet = "NotYetSet"
Expand Down Expand Up @@ -239,10 +241,10 @@ func generateAndApplyMachineConfigNodes(
}

// for now, keep spec and status aligned
if node.Annotations["machineconfiguration.openshift.io/currentConfig"] != "" {
if node.Annotations[daemonconsts.CurrentMachineConfigAnnotationKey] != "" {
newMCNode.Status.ConfigVersion = mcfgalphav1.MachineConfigNodeStatusMachineConfigVersion{
Desired: newMCNode.Status.ConfigVersion.Desired,
Current: node.Annotations["machineconfiguration.openshift.io/currentConfig"],
Current: node.Annotations[daemonconsts.CurrentMachineConfigAnnotationKey],
}
} else {
newMCNode.Status.ConfigVersion = mcfgalphav1.MachineConfigNodeStatusMachineConfigVersion{
Expand All @@ -251,16 +253,16 @@ func generateAndApplyMachineConfigNodes(
}
// if the update is compatible, we can set the desired to the one being used in the update
// this happens either if we get prepared == true OR literally any other parent condition, since if we get past prepared, then the desiredConfig is correct.
if newParentCondition.Type == string(mcfgalphav1.MachineConfigNodeUpdatePrepared) && newParentCondition.Status == metav1.ConditionTrue || newParentCondition.Type != string(mcfgalphav1.MachineConfigNodeUpdatePrepared) && node.Annotations["machineconfiguration.openshift.io/desiredConfig"] != "" {
newMCNode.Status.ConfigVersion.Desired = node.Annotations["machineconfiguration.openshift.io/desiredConfig"]
if newParentCondition.Type == string(mcfgalphav1.MachineConfigNodeUpdatePrepared) && newParentCondition.Status == metav1.ConditionTrue || newParentCondition.Type != string(mcfgalphav1.MachineConfigNodeUpdatePrepared) && node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey] != "" {
newMCNode.Status.ConfigVersion.Desired = node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey]
} else if newMCNode.Status.ConfigVersion.Desired == "" {
newMCNode.Status.ConfigVersion.Desired = NotYetSet
}

// if we do not need a new MCN, generate the apply configurations for this object
if !needNewMCNode {
statusconfigVersionApplyConfig := machineconfigurationalphav1.MachineConfigNodeStatusMachineConfigVersion().WithDesired(newMCNode.Status.ConfigVersion.Desired)
if node.Annotations["machineconfiguration.openshift.io/currentConfig"] != "" {
if node.Annotations[daemonconsts.CurrentMachineConfigAnnotationKey] != "" {
statusconfigVersionApplyConfig = statusconfigVersionApplyConfig.WithCurrent(newMCNode.Status.ConfigVersion.Current)
}
statusApplyConfig := machineconfigurationalphav1.MachineConfigNodeStatus().
Expand Down Expand Up @@ -294,7 +296,7 @@ func generateAndApplyMachineConfigNodes(
} else if node.Status.Phase != corev1.NodePending && node.Status.Phase != corev1.NodePhase("Provisioning") {
// there are cases where we get here before the MCO has settled and applied all of the MCnodes.
newMCNode.Spec.ConfigVersion = mcfgalphav1.MachineConfigNodeSpecMachineConfigVersion{
Desired: node.Annotations["machineconfiguration.openshift.io/desiredConfig"],
Desired: node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey],
}
if newMCNode.Spec.ConfigVersion.Desired == "" {
newMCNode.Spec.ConfigVersion.Desired = NotYetSet
Expand Down Expand Up @@ -362,9 +364,15 @@ func GenerateAndApplyMachineConfigNodeSpec(fgAccessor featuregates.FeatureGateAc
UID: node.ObjectMeta.UID,
},
}

newMCNode.Spec.ConfigVersion = mcfgalphav1.MachineConfigNodeSpecMachineConfigVersion{
Desired: node.Annotations["machineconfiguration.openshift.io/desiredConfig"],
Desired: node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey],
}
// Set desired config to NotYetSet if the annotation is empty to satisfy API validation
if newMCNode.Spec.ConfigVersion.Desired == "" {
newMCNode.Spec.ConfigVersion.Desired = NotYetSet
}

newMCNode.Spec.Pool = mcfgalphav1.MCOObjectReference{
Name: pool,
}
Expand Down

0 comments on commit 47a4dc7

Please sign in to comment.