Skip to content

Commit d77cc70

Browse files
daemon & upgrade_monitor: split 'MachineConfigNodeUpdateFilesAndOS' condition to 'MachineConfigNodeUpdateOS' and 'MachineConfigNodeUpdateFiles' when 'ImageModeStatusReporting' is enabled
1 parent 3ca2fc0 commit d77cc70

File tree

2 files changed

+191
-41
lines changed

2 files changed

+191
-41
lines changed

pkg/daemon/update.go

Lines changed: 149 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,30 +1095,87 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
10951095
files += f.Path + " "
10961096
}
10971097

1098+
// TODO (MCO-1775): Once ImageModeStatusReporting is GA, clean up the below logic. Updates to
1099+
// the `MachineConfigNodeUpdateFilesAndOS` condition will no longer be necessary and should be
1100+
// fully replaced by updates to the individual `MachineConfigNodeUpdateFiles` and
1101+
// `MachineConfigNodeUpdateOS` conditions.
1102+
imageModeStatusReportingEnabled := dn.fgHandler != nil && dn.fgHandler.Enabled(features.FeatureGateImageModeStatusReporting)
10981103
updatesNeeded := []string{"not", "not"}
1099-
if diff.passwd {
1104+
fileUpdate := false
1105+
osUpdate := false
1106+
// Handle file updates case
1107+
if diff.passwd || diff.files {
11001108
updatesNeeded[1] = ""
1109+
fileUpdate = true
1110+
// When ImageModeStatusReporting is enabled, use the specific `MachineConfigNodeUpdateFiles` condition for file updates
1111+
if imageModeStatusReportingEnabled {
1112+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1113+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateFiles), Message: fmt.Sprintf("Updating the Files on disk as a part of the in progress phase")},
1114+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateFiles, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.MachineConfigNodeUpdateFiles)), Message: fmt.Sprintf("Applying files to node.")},
1115+
metav1.ConditionUnknown,
1116+
metav1.ConditionUnknown,
1117+
dn.node,
1118+
dn.mcfgClient,
1119+
dn.fgHandler,
1120+
pool,
1121+
)
1122+
}
1123+
if err != nil {
1124+
klog.Errorf("Error making MCN for Updating Files: %v", err)
1125+
}
11011126
}
1127+
// Handle OS updates case
11021128
if diff.osUpdate || diff.extensions || diff.kernelType {
1129+
osUpdate = true
11031130
updatesNeeded[0] = ""
1131+
// When ImageModeStatusReporting is enabled, use the specific `MachineConfigNodeUpdateOS` condition for OS updates
1132+
if imageModeStatusReportingEnabled {
1133+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1134+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateOS), Message: fmt.Sprintf("Updating the OS on disk as a part of the in progress phase")},
1135+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateOS, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.MachineConfigNodeUpdateOS)), Message: fmt.Sprintf("Applying new OS config to node.")},
1136+
metav1.ConditionUnknown,
1137+
metav1.ConditionUnknown,
1138+
dn.node,
1139+
dn.mcfgClient,
1140+
dn.fgHandler,
1141+
pool,
1142+
)
1143+
}
1144+
if err != nil {
1145+
klog.Errorf("Error making MCN for Updating Files: %v", err)
1146+
}
11041147
}
1105-
1106-
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1107-
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateFilesAndOS), Message: fmt.Sprintf("Updating the Files and OS on disk as a part of the in progress phase")},
1108-
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateFilesAndOS, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.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])},
1109-
metav1.ConditionUnknown,
1110-
metav1.ConditionUnknown,
1111-
dn.node,
1112-
dn.mcfgClient,
1113-
dn.fgHandler,
1114-
pool,
1115-
)
1116-
if err != nil {
1117-
klog.Errorf("Error making MCN for Updating Files and OS: %v", err)
1148+
if !imageModeStatusReportingEnabled {
1149+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1150+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateFilesAndOS), Message: fmt.Sprintf("Updating the Files and OS on disk as a part of the in progress phase")},
1151+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateFilesAndOS, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.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])},
1152+
metav1.ConditionUnknown,
1153+
metav1.ConditionUnknown,
1154+
dn.node,
1155+
dn.mcfgClient,
1156+
dn.fgHandler,
1157+
pool,
1158+
)
1159+
if err != nil {
1160+
klog.Errorf("Error making MCN for Updating OS: %v", err)
1161+
}
11181162
}
11191163

11201164
// update files on disk that need updating
11211165
if err := dn.updateFiles(oldIgnConfig, newIgnConfig, skipCertificateWrite); err != nil {
1166+
// When ImageModeStatusReporting is enabled, update the `MachineConfigNodeUpdateFiles` condition to report the experienced error
1167+
if imageModeStatusReportingEnabled {
1168+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1169+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateFiles), Message: fmt.Sprintf("Error updating the Files on disk as a part of the in progress phase")},
1170+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateFiles, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.MachineConfigNodeUpdateFiles)), Message: fmt.Sprintf("Update failed applying files to node: %s", err.Error())},
1171+
metav1.ConditionUnknown,
1172+
metav1.ConditionUnknown,
1173+
dn.node,
1174+
dn.mcfgClient,
1175+
dn.fgHandler,
1176+
pool,
1177+
)
1178+
}
11221179
return err
11231180
}
11241181

@@ -1140,8 +1197,20 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
11401197
// only update passwd if it has changed (do not nullify)
11411198
// we do not need to include SetPasswordHash in this, since only updateSSHKeys has issues on firstboot.
11421199
if diff.passwd {
1143-
klog.Info("setting passwd")
11441200
if err := dn.updateSSHKeys(newIgnConfig.Passwd.Users, oldIgnConfig.Passwd.Users); err != nil {
1201+
// When ImageModeStatusReporting is enabled, update the `MachineConfigNodeUpdateFiles` condition to report the experienced error
1202+
if imageModeStatusReportingEnabled {
1203+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1204+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateFiles), Message: fmt.Sprintf("Error updating the Files on disk as a part of the in progress phase")},
1205+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateFiles, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.MachineConfigNodeUpdateFiles)), Message: fmt.Sprintf("Update failed applying files to node: %s", err.Error())},
1206+
metav1.ConditionUnknown,
1207+
metav1.ConditionUnknown,
1208+
dn.node,
1209+
dn.mcfgClient,
1210+
dn.fgHandler,
1211+
pool,
1212+
)
1213+
}
11451214
return err
11461215
}
11471216

@@ -1179,6 +1248,19 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
11791248
}
11801249

11811250
if err := coreOSDaemon.applyOSChanges(*diff, oldConfig, newConfig); err != nil {
1251+
// When ImageModeStatusReporting is enabled, update the `MachineConfigNodeUpdateOS` condition to report the experienced error
1252+
if imageModeStatusReportingEnabled {
1253+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1254+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateOS), Message: fmt.Sprintf("Error the OS on disk as a part of the in progress phase")},
1255+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateOS, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.MachineConfigNodeUpdateOS)), Message: fmt.Sprintf("Update failed applying new OS config to node: %s", err.Error())},
1256+
metav1.ConditionUnknown,
1257+
metav1.ConditionUnknown,
1258+
dn.node,
1259+
dn.mcfgClient,
1260+
dn.fgHandler,
1261+
pool,
1262+
)
1263+
}
11821264
return err
11831265
}
11841266

@@ -1225,19 +1307,59 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
12251307
}
12261308
}()
12271309

1228-
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1229-
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateFilesAndOS), Message: fmt.Sprintf("Updated the Files and OS on disk as a part of the in progress phase")},
1230-
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateFilesAndOS, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.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])},
1231-
metav1.ConditionTrue,
1232-
metav1.ConditionTrue,
1233-
dn.node,
1234-
dn.mcfgClient,
1235-
dn.fgHandler,
1236-
pool,
1237-
)
1238-
if err != nil {
1239-
klog.Errorf("Error making MCN for Updated Files and OS: %v", err)
1310+
// TODO (MCO-1775): Once ImageModeStatusReporting is GA, clean up the below logic. Updates to
1311+
// the `MachineConfigNodeUpdateFilesAndOS` condition will no longer be necessary and should be
1312+
// fully replaced by updates to the individual `MachineConfigNodeUpdateFiles` and
1313+
// `MachineConfigNodeUpdateOS` conditions.
1314+
if imageModeStatusReportingEnabled {
1315+
// Update MCN for successful file update
1316+
if fileUpdate {
1317+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1318+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateFiles), Message: fmt.Sprintf("Updated the Files on disk as a part of the in progress phase")},
1319+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateFiles, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.MachineConfigNodeUpdateFiles)), Message: fmt.Sprintf("Applied files. SSH Keys did need an update")},
1320+
metav1.ConditionTrue,
1321+
metav1.ConditionTrue,
1322+
dn.node,
1323+
dn.mcfgClient,
1324+
dn.fgHandler,
1325+
pool,
1326+
)
1327+
if err != nil {
1328+
klog.Errorf("Error making MCN for Updated Files: %v", err)
1329+
}
1330+
}
1331+
// Update MCN for successful OS update
1332+
if osUpdate {
1333+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1334+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateOS), Message: fmt.Sprintf("Updated the OS on disk as a part of the in progress phase")},
1335+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateOS, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.MachineConfigNodeUpdateOS)), Message: fmt.Sprintf("Applied new OS config to node.")},
1336+
metav1.ConditionTrue,
1337+
metav1.ConditionTrue,
1338+
dn.node,
1339+
dn.mcfgClient,
1340+
dn.fgHandler,
1341+
pool,
1342+
)
1343+
if err != nil {
1344+
klog.Errorf("Error making MCN for Updated OS: %v", err)
1345+
}
1346+
}
1347+
} else {
1348+
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
1349+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgv1.MachineConfigNodeUpdateFilesAndOS), Message: fmt.Sprintf("Updated the Files and OS on disk as a part of the in progress phase")},
1350+
&upgrademonitor.Condition{State: mcfgv1.MachineConfigNodeUpdateFilesAndOS, Reason: fmt.Sprintf("%s%s", string(mcfgv1.MachineConfigNodeUpdateExecuted), string(mcfgv1.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])},
1351+
metav1.ConditionTrue,
1352+
metav1.ConditionTrue,
1353+
dn.node,
1354+
dn.mcfgClient,
1355+
dn.fgHandler,
1356+
pool,
1357+
)
1358+
if err != nil {
1359+
klog.Errorf("Error making MCN for Updated Files and OS: %v", err)
1360+
}
12401361
}
1362+
12411363
// Node Disruption Policies cannot be used during firstboot as API is not accessible.
12421364
if !firstBoot {
12431365
return dn.performPostConfigChangeNodeDisruptionAction(nodeDisruptionActions, newConfig.GetName())

pkg/upgrademonitor/upgrade_monitor.go

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,48 @@ func generateAndApplyMachineConfigNodes(
135135

136136
// we use this array to see if the MCN has all of its conditions set
137137
// if not we set a sane default
138-
allConditionTypes := []mcfgv1.StateProgress{
139-
mcfgv1.MachineConfigNodeUpdatePrepared,
140-
mcfgv1.MachineConfigNodeUpdateExecuted,
141-
mcfgv1.MachineConfigNodeUpdatePostActionComplete,
142-
mcfgv1.MachineConfigNodeUpdateComplete,
143-
mcfgv1.MachineConfigNodeResumed,
144-
mcfgv1.MachineConfigNodeUpdateDrained,
145-
mcfgv1.MachineConfigNodeUpdateFilesAndOS,
146-
mcfgv1.MachineConfigNodeImagePulledFromRegistry,
147-
mcfgv1.MachineConfigNodeUpdateCordoned,
148-
mcfgv1.MachineConfigNodeUpdateRebooted,
149-
mcfgv1.MachineConfigNodeUpdated,
150-
mcfgv1.MachineConfigNodeUpdateUncordoned,
151-
mcfgv1.MachineConfigNodeNodeDegraded,
138+
// TODO (MCO-1775): Once ImageModeStatusReporting is GA, clean up the below logic. The `if`
139+
// conditional will no longer be needed.
140+
var allConditionTypes []mcfgv1.StateProgress
141+
imageModeStatusReportingEnabled := fgHandler.Enabled(features.FeatureGateImageModeStatusReporting)
142+
// If `ImageModeStatusReporting` is not enabled, use the default conditions
143+
if !imageModeStatusReportingEnabled {
144+
allConditionTypes = append(
145+
allConditionTypes,
146+
mcfgv1.MachineConfigNodeUpdatePrepared,
147+
mcfgv1.MachineConfigNodeUpdateExecuted,
148+
mcfgv1.MachineConfigNodeUpdatePostActionComplete,
149+
mcfgv1.MachineConfigNodeUpdateComplete,
150+
mcfgv1.MachineConfigNodeResumed,
151+
mcfgv1.MachineConfigNodeUpdateDrained,
152+
mcfgv1.MachineConfigNodeUpdateFilesAndOS,
153+
mcfgv1.MachineConfigNodeUpdateCordoned,
154+
mcfgv1.MachineConfigNodeUpdateRebooted,
155+
mcfgv1.MachineConfigNodeUpdated,
156+
mcfgv1.MachineConfigNodeUpdateUncordoned,
157+
mcfgv1.MachineConfigNodeNodeDegraded,
158+
)
159+
} else { // If `ImageModeStatusReporting` is enabled, include the new condition states
160+
allConditionTypes = append(
161+
allConditionTypes,
162+
mcfgv1.MachineConfigNodeUpdatePrepared,
163+
mcfgv1.MachineConfigNodeUpdateExecuted,
164+
mcfgv1.MachineConfigNodeUpdatePostActionComplete,
165+
mcfgv1.MachineConfigNodeUpdateComplete,
166+
mcfgv1.MachineConfigNodeResumed,
167+
mcfgv1.MachineConfigNodeUpdateDrained,
168+
// Note that the following two conditions replace the previous, singular
169+
// `MachineConfigNodeUpdateFilesAndOS` condition
170+
mcfgv1.MachineConfigNodeUpdateFiles,
171+
mcfgv1.MachineConfigNodeUpdateOS,
172+
mcfgv1.MachineConfigNodeUpdateCordoned,
173+
mcfgv1.MachineConfigNodeUpdateRebooted,
174+
mcfgv1.MachineConfigNodeUpdated,
175+
mcfgv1.MachineConfigNodeUpdateUncordoned,
176+
// Note that the following condition is new
177+
mcfgv1.MachineConfigNodeImagePulledFromRegistry,
178+
mcfgv1.MachineConfigNodeNodeDegraded,
179+
)
152180
}
153181
allConditionTypes = append(allConditionTypes, singletonConditionTypes...)
154182

0 commit comments

Comments
 (0)