Skip to content

Commit 45c3cb5

Browse files
add nil check for get primary pool
1 parent 2d6dd88 commit 45c3cb5

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

pkg/daemon/update.go

+28-24
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,20 @@ func (dn *Daemon) performPostConfigChangeNodeDisruptionAction(postConfigChangeAc
275275
func (dn *Daemon) performPostConfigChangeAction(postConfigChangeActions []string, configName string) error {
276276
// TODO: Potentially consolidate down defining of `primaryPool` & `pool`
277277
// TODO: Update for cluster install
278-
// primaryPool, err := helpers.GetPrimaryPoolForNode(dn.mcpLister, dn.node)
279-
// if err != nil {
280-
// klog.Errorf("Error getting primary pool for node: %v", dn.node.Name)
281-
// return err
282-
// }
283-
// var pool string = primaryPool.Name
284-
var pool string = "testing-update-3"
278+
primaryPool, err := helpers.GetPrimaryPoolForNode(dn.mcpLister, dn.node)
279+
var pool string
280+
if err != nil {
281+
klog.Errorf("error getting primary pool for node: %v", dn.node.Name)
282+
// return err
283+
// pool = "unknown"
284+
} else if primaryPool == nil {
285+
// On first provisioning, the node may not have annoatations and, thus, will not be associated with a pool
286+
klog.Infof("No primary pool is associated with node: %v", dn.node.Name)
287+
pool = "unknown"
288+
} else {
289+
pool = primaryPool.Name
290+
}
291+
// var pool string = "testing-update-3"
285292

286293
if ctrlcommon.InSlice(postConfigChangeActionReboot, postConfigChangeActions) {
287294
err := upgrademonitor.GenerateAndApplyMachineConfigNodes(
@@ -1118,23 +1125,26 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
11181125

11191126
// TODO: Potentially consolidate down defining of `primaryPool` & `pool`
11201127
// TODO: Update for cluster install
1121-
// primaryPool, err := helpers.GetPrimaryPoolForNode(dn.mcpLister, dn.node)
1122-
// var pool string
1123-
// if err != nil {
1124-
// klog.Errorf("Error getting primary pool for node: %v", dn.node.Name)
1125-
// // return err
1126-
// pool = "testing-update-4"
1127-
// } else {
1128-
// pool = primaryPool.Name
1129-
// }
1130-
var pool string = "testing-update-4"
1128+
primaryPool, err := helpers.GetPrimaryPoolForNode(dn.mcpLister, dn.node)
1129+
var pool string
1130+
if err != nil {
1131+
klog.Errorf("error getting primary pool for node: %v", dn.node.Name)
1132+
// return err
1133+
// pool = "unknown"
1134+
} else if primaryPool == nil {
1135+
// On first provisioning, the node may not have annoatations and, thus, will not be associated with a pool
1136+
klog.Infof("No primary pool is associated with node: %v", dn.node.Name)
1137+
pool = "unknown"
1138+
} else {
1139+
pool = primaryPool.Name
1140+
}
1141+
// var pool string = "testing-update-4"
11311142

11321143
// checking for reconcilability
11331144
// make sure we can actually reconcile this state
11341145
diff, reconcilableError := reconcilable(oldConfig, newConfig)
11351146

11361147
if reconcilableError != nil {
1137-
pool = "test-update-1"
11381148
Nerr := upgrademonitor.GenerateAndApplyMachineConfigNodes(
11391149
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: fmt.Sprintf("Update Failed during the Checking for Compatibility phase")},
11401150
&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())},
@@ -1182,7 +1192,6 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
11821192
}
11831193

11841194
if err != nil {
1185-
pool = "test-update-2"
11861195
Nerr := upgrademonitor.GenerateAndApplyMachineConfigNodes(
11871196
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: "Update Failed during the Checking for Compatibility phase."},
11881197
&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())},
@@ -1218,7 +1227,6 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
12181227
return err
12191228
}
12201229
}
1221-
pool = "test-update-3"
12221230
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
12231231
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdatePrepared, Reason: string(mcfgalphav1.MachineConfigNodeUpdateCompatible), Message: "Update is Compatible."},
12241232
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateCompatible, Reason: fmt.Sprintf("%s%s", string(mcfgalphav1.MachineConfigNodeUpdatePrepared), string(mcfgalphav1.MachineConfigNodeUpdateCompatible)), Message: fmt.Sprintf("Update Compatible. Post Cfg Actions %v: Drain Required: %t", actions, drain)},
@@ -1243,7 +1251,6 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
12431251
// }
12441252
// }
12451253

1246-
pool = "test-update-5"
12471254
err = upgrademonitor.GenerateAndApplyMachineConfigNodeSpec(dn.featureGatesAccessor, pool, dn.node, dn.mcfgClient)
12481255
if err != nil {
12491256
klog.Errorf("Error making MCN spec for Update Compatible: %v", err)
@@ -1254,7 +1261,6 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
12541261
}
12551262
} else {
12561263
klog.Info("Changes do not require drain, skipping.")
1257-
pool = "test-update-6"
12581264
err := upgrademonitor.GenerateAndApplyMachineConfigNodes(
12591265
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateExecuted, Reason: string(mcfgalphav1.MachineConfigNodeUpdateDrained), Message: "Node Drain Not required for this update."},
12601266
&upgrademonitor.Condition{State: mcfgalphav1.MachineConfigNodeUpdateDrained, Reason: fmt.Sprintf("%s%s", string(mcfgalphav1.MachineConfigNodeUpdateExecuted), string(mcfgalphav1.MachineConfigNodeUpdateDrained)), Message: "Node Drain Not required for this update."},
@@ -1283,7 +1289,6 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
12831289
updatesNeeded[0] = ""
12841290
}
12851291

1286-
pool = "test-update-7"
12871292
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
12881293
&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")},
12891294
&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])},
@@ -1397,7 +1402,6 @@ func (dn *Daemon) update(oldConfig, newConfig *mcfgv1.MachineConfig, skipCertifi
13971402
}
13981403
}()
13991404

1400-
pool = "test-update-8"
14011405
err = upgrademonitor.GenerateAndApplyMachineConfigNodes(
14021406
&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")},
14031407
&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])},

0 commit comments

Comments
 (0)