Skip to content

Commit 447c3a8

Browse files
Fix MCN conditions not updating during OCL sync
1 parent 0b05692 commit 447c3a8

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

pkg/daemon/update.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,13 +886,43 @@ func (dn *Daemon) updateOnClusterLayering(oldConfig, newConfig *mcfgv1.MachineCo
886886
diff, reconcilableError := reconcilable(oldConfig, newConfig)
887887

888888
if reconcilableError != nil {
889+
if dn.featureGatesAccessor != nil {
890+
Nerr := upgrademonitor.GenerateAndApplyMachineConfigNodes(
891+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: fmt.Sprintf("Update Failed during the Checking for Compatibility phase")},
892+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateCompatible, Reason: fmt.Sprintf("%s%s", string(mcfgalphav1.MachineConfigNodeUpdatePrepared), string(mcfgalphav1.MachineConfigNodeUpdateCompatible)), Message: fmt.Sprintf("Error: MachineConfigs %v and %v are not compatible. Err: %s", oldConfigName, newConfigName, reconcilableError.Error())},
893+
metav1.ConditionTrue,
894+
metav1.ConditionFalse,
895+
dn.node,
896+
dn.mcfgClient,
897+
dn.featureGatesAccessor,
898+
)
899+
if Nerr != nil {
900+
klog.Errorf("Error making MCN for Preparing update failed: %v", Nerr)
901+
}
902+
}
889903
wrappedErr := fmt.Errorf("can't reconcile config %s with %s: %w", oldConfigName, newConfigName, reconcilableError)
890904
if dn.nodeWriter != nil {
891905
dn.nodeWriter.Eventf(corev1.EventTypeWarning, "FailedToReconcile", wrappedErr.Error())
892906
}
893907
return &unreconcilableErr{wrappedErr}
894908
}
895909

910+
// Set UpdatePrepared and UpdateCompatible to True since reconcilability check passed
911+
if dn.featureGatesAccessor != nil {
912+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
913+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: "Update is Compatible."},
914+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateCompatible, Reason: fmt.Sprintf("%s%s", string(mcfgalphav1.MachineConfigNodeUpdatePrepared), string(mcfgalphav1.MachineConfigNodeUpdateCompatible)), Message: "Update Compatible with on-cluster build"},
915+
metav1.ConditionTrue,
916+
metav1.ConditionTrue,
917+
dn.node,
918+
dn.mcfgClient,
919+
dn.featureGatesAccessor,
920+
)
921+
if err != nil {
922+
klog.Errorf("Error making MCN for Update Compatible: %v", err)
923+
}
924+
}
925+
896926
if err := dn.performDrain(); err != nil {
897927
return err
898928
}
@@ -936,6 +966,30 @@ func (dn *Daemon) updateOnClusterLayering(oldConfig, newConfig *mcfgv1.MachineCo
936966
}
937967
}()
938968

969+
// Set UpdateFilesAndOS condition
970+
if dn.featureGatesAccessor != nil {
971+
updatesNeeded := []string{"not", "not"}
972+
if diff.passwd {
973+
updatesNeeded[1] = ""
974+
}
975+
if diff.osUpdate || diff.extensions || diff.kernelType {
976+
updatesNeeded[0] = ""
977+
}
978+
979+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
980+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgalphav1.MachineConfigNodeUpdateFilesAndOS), Message: fmt.Sprintf("Updating the Files and OS on disk as a part of the in progress phase")},
981+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateFilesAndOS, Reason: fmt.Sprintf("%s%s", string(mcfgalphav1.MachineConfigNodeUpdateExecuted), string(mcfgalphav1.MachineConfigNodeUpdateFilesAndOS)), Message: fmt.Sprintf("Applying files and new OS config to node. OS will %s need an update. SSH Keys will %s need an update", updatesNeeded[0], updatesNeeded[1])},
982+
metav1.ConditionUnknown,
983+
metav1.ConditionUnknown,
984+
dn.node,
985+
dn.mcfgClient,
986+
dn.featureGatesAccessor,
987+
)
988+
if err != nil {
989+
klog.Errorf("Error making MCN for Updating Files and OS: %v", err)
990+
}
991+
}
992+
939993
// update files on disk that need updating
940994
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, skipCertificateWrite); err != nil {
941995
return err
@@ -1061,6 +1115,30 @@ func (dn *Daemon) updateOnClusterLayering(oldConfig, newConfig *mcfgv1.MachineCo
10611115
}
10621116
}()
10631117

1118+
// Set UpdateExecuted and UpdateFilesAndOS to True since files and OS updates completed
1119+
if dn.featureGatesAccessor != nil {
1120+
updatesNeeded := []string{"not", "not"}
1121+
if diff.passwd {
1122+
updatesNeeded[1] = ""
1123+
}
1124+
if diff.osUpdate || diff.extensions || diff.kernelType {
1125+
updatesNeeded[0] = ""
1126+
}
1127+
1128+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1129+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgalphav1.MachineConfigNodeUpdateFilesAndOS), Message: fmt.Sprintf("Updated the Files and OS on disk as a part of the in progress phase")},
1130+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateFilesAndOS, Reason: fmt.Sprintf("%s%s", string(mcfgalphav1.MachineConfigNodeUpdateExecuted), string(mcfgalphav1.MachineConfigNodeUpdateFilesAndOS)), Message: fmt.Sprintf("Applied files and new OS config to node. OS did %s need an update. SSH Keys did %s need an update", updatesNeeded[0], updatesNeeded[1])},
1131+
metav1.ConditionTrue,
1132+
metav1.ConditionTrue,
1133+
dn.node,
1134+
dn.mcfgClient,
1135+
dn.featureGatesAccessor,
1136+
)
1137+
if err != nil {
1138+
klog.Errorf("Error making MCN for Updated Files and OS: %v", err)
1139+
}
1140+
}
1141+
10641142
return dn.reboot(fmt.Sprintf("Node will reboot into image %s / MachineConfig %s", canonicalizeMachineConfigImage(newImage, newConfig).Spec.OSImageURL, newConfigName))
10651143
}
10661144

0 commit comments

Comments
 (0)