Skip to content

Commit 5ca4fb1

Browse files
added mcn conditions to ocl sync
1 parent 247c2c7 commit 5ca4fb1

File tree

1 file changed

+82
-4
lines changed

1 file changed

+82
-4
lines changed

pkg/daemon/update.go

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,13 +867,43 @@ func (dn *Daemon) updateOnClusterBuild(oldConfig, newConfig *mcfgv1.MachineConfi
867867
diff, reconcilableError := reconcilable(oldConfig, newConfig)
868868

869869
if reconcilableError != nil {
870+
if dn.featureGatesAccessor != nil {
871+
Nerr := upgrademonitor.GenerateAndApplyMachineConfigNodes(
872+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: fmt.Sprintf("Update Failed during the Checking for Compatibility phase")},
873+
&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())},
874+
metav1.ConditionFalse,
875+
metav1.ConditionFalse,
876+
dn.node,
877+
dn.mcfgClient,
878+
dn.featureGatesAccessor,
879+
)
880+
if Nerr != nil {
881+
klog.Errorf("Error making MCN for Preparing update failed: %v", Nerr)
882+
}
883+
}
870884
wrappedErr := fmt.Errorf("can't reconcile config %s with %s: %w", oldConfigName, newConfigName, reconcilableError)
871885
if dn.nodeWriter != nil {
872886
dn.nodeWriter.Eventf(corev1.EventTypeWarning, "FailedToReconcile", wrappedErr.Error())
873887
}
874888
return &unreconcilableErr{wrappedErr}
875889
}
876890

891+
// Set UpdatePrepared and UpdateCompatible to True since reconcilability check passed
892+
if dn.featureGatesAccessor != nil {
893+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
894+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: "Update is Compatible."},
895+
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateCompatible, Reason: fmt.Sprintf("%s%s", string(mcfgalphav1.MachineConfigNodeUpdatePrepared), string(mcfgalphav1.MachineConfigNodeUpdateCompatible)), Message: "Update Compatible with on-cluster build"},
896+
metav1.ConditionTrue,
897+
metav1.ConditionTrue,
898+
dn.node,
899+
dn.mcfgClient,
900+
dn.featureGatesAccessor,
901+
)
902+
if err != nil {
903+
klog.Errorf("Error making MCN for Update Compatible: %v", err)
904+
}
905+
}
906+
877907
if oldImage == newImage && newImage != "" {
878908
if oldImage == "" {
879909
logSystem("Starting transition to %q", newImage)
@@ -897,6 +927,30 @@ func (dn *Daemon) updateOnClusterBuild(oldConfig, newConfig *mcfgv1.MachineConfi
897927
klog.Infof("Image pullspecs equal, skipping rpm-ostree rebase")
898928
}
899929

930+
// Set UpdateFilesAndOS condition
931+
if dn.featureGatesAccessor != nil {
932+
updatesNeeded := []string{"not", "not"}
933+
if diff.passwd {
934+
updatesNeeded[1] = ""
935+
}
936+
if diff.osUpdate || diff.extensions || diff.kernelType {
937+
updatesNeeded[0] = ""
938+
}
939+
940+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
941+
&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")},
942+
&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])},
943+
metav1.ConditionUnknown,
944+
metav1.ConditionUnknown,
945+
dn.node,
946+
dn.mcfgClient,
947+
dn.featureGatesAccessor,
948+
)
949+
if err != nil {
950+
klog.Errorf("Error making MCN for Updating Files and OS: %v", err)
951+
}
952+
}
953+
900954
// update files on disk that need updating
901955
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, skipCertificateWrite); err != nil {
902956
return err
@@ -989,6 +1043,30 @@ func (dn *Daemon) updateOnClusterBuild(oldConfig, newConfig *mcfgv1.MachineConfi
9891043
}
9901044
}()
9911045

1046+
// Set UpdateExecuted and UpdateFilesAndOS to True since files and OS updates completed
1047+
if dn.featureGatesAccessor != nil {
1048+
updatesNeeded := []string{"not", "not"}
1049+
if diff.passwd {
1050+
updatesNeeded[1] = ""
1051+
}
1052+
if diff.osUpdate || diff.extensions || diff.kernelType {
1053+
updatesNeeded[0] = ""
1054+
}
1055+
1056+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1057+
&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")},
1058+
&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])},
1059+
metav1.ConditionTrue,
1060+
metav1.ConditionTrue,
1061+
dn.node,
1062+
dn.mcfgClient,
1063+
dn.featureGatesAccessor,
1064+
)
1065+
if err != nil {
1066+
klog.Errorf("Error making MCN for Updated Files and OS: %v", err)
1067+
}
1068+
}
1069+
9921070
return dn.reboot(fmt.Sprintf("Node will reboot into image %s / MachineConfig %s", newImage, newConfigName))
9931071
}
9941072

@@ -1042,8 +1120,8 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
10421120
Nerr := upgrademonitor.GenerateAndApplyMachineConfigNodes(
10431121
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: fmt.Sprintf("Update Failed during the Checking for Compatibility phase")},
10441122
&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())},
1045-
metav1.ConditionUnknown,
1046-
metav1.ConditionUnknown,
1123+
metav1.ConditionTrue,
1124+
metav1.ConditionFalse,
10471125
dn.node,
10481126
dn.mcfgClient,
10491127
dn.featureGatesAccessor,
@@ -1088,8 +1166,8 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
10881166
Nerr := upgrademonitor.GenerateAndApplyMachineConfigNodes(
10891167
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: "Update Failed during the Checking for Compatibility phase."},
10901168
&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 available for update. Error calculating post config change actions: %s", oldConfigName, newConfigName, err.Error())},
1091-
metav1.ConditionUnknown,
1092-
metav1.ConditionUnknown,
1169+
metav1.ConditionTrue,
1170+
metav1.ConditionFalse,
10931171
dn.node,
10941172
dn.mcfgClient,
10951173
dn.featureGatesAccessor,

0 commit comments

Comments
 (0)