Skip to content

Commit c6271f4

Browse files
controller: refactor helpers to get machines by state
1 parent 36dcbbc commit c6271f4

7 files changed

Lines changed: 251 additions & 565 deletions

File tree

pkg/controller/common/helpers.go

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import (
5151
"github.com/openshift/client-go/machineconfiguration/clientset/versioned/scheme"
5252
"github.com/openshift/library-go/pkg/crypto"
5353
buildconstants "github.com/openshift/machine-config-operator/pkg/controller/build/constants"
54-
daemonconsts "github.com/openshift/machine-config-operator/pkg/daemon/constants"
5554
)
5655

5756
// strToPtr converts the input string to a pointer to itself
@@ -1286,42 +1285,51 @@ func RequiresRebuild(oldMC, newMC *mcfgv1.MachineConfig) bool {
12861285
!reflect.DeepEqual(oldMC.Spec.KernelArguments, newMC.Spec.KernelArguments)
12871286
}
12881287

1289-
// GetUpdatedMachines filters the provided nodes to return the nodes whose
1290-
// current config matches its desired config and target config in the
1291-
// associated MCP and has the "done" flag set.
1292-
func GetUpdatedMachines(pool *mcfgv1.MachineConfigPool, nodes []*corev1.Node, mosc *mcfgv1.MachineOSConfig, mosb *mcfgv1.MachineOSBuild, layered bool) []*corev1.Node {
1288+
type MachinesByStatus struct {
1289+
Updated []*corev1.Node
1290+
Degraded []*corev1.Node
1291+
Ready []*corev1.Node
1292+
Unavailable []*corev1.Node
1293+
}
1294+
1295+
// GetMachinesByState takes a list of nodes and returns lists of nodes filtered by state. The
1296+
// states and their requirements are:
1297+
// - Updated: A node's current config matches its desired config and the target config in the
1298+
// associated MCP and the node has the "done" flag set
1299+
// - Degraded: The node's `machineconfiguration.openshift.io/state` annotation has a value of
1300+
// "Degraded" or "Unreconcilable"
1301+
// - Ready: The node is "Updated" and marked ready
1302+
// - Unavailable: The node is either marked unscheduleable or has a MCD actively working. If the
1303+
// MCD is actively working (or hasn't started) then the node *may* go unschedulable in the
1304+
// future, so the node is considered "unavailable" so another node update does not exceed
1305+
// the desired maxUnavailable. (Somewhat the opposite of a "Ready" node)
1306+
func GetMachinesByState(pool *mcfgv1.MachineConfigPool, nodes []*corev1.Node, mosc *mcfgv1.MachineOSConfig, mosb *mcfgv1.MachineOSBuild, layered bool) MachinesByStatus {
12931307
var updated []*corev1.Node
1308+
var degraded []*corev1.Node
1309+
var ready []*corev1.Node
1310+
var unavail []*corev1.Node
12941311
for _, node := range nodes {
12951312
lns := NewLayeredNodeState(node)
12961313
if lns.IsDone(pool, layered, mosc, mosb) {
12971314
updated = append(updated, node)
1315+
// A node must be updated to be considered "Ready"
1316+
if lns.IsNodeReady() {
1317+
ready = append(ready, node)
1318+
}
12981319
}
1299-
}
1300-
return updated
1301-
}
1302-
1303-
// GetDegradedMachines filters the provided nodes to return the nodes that
1304-
// are considered in a degraded state.
1305-
func GetDegradedMachines(nodes []*corev1.Node) []*corev1.Node {
1306-
var degraded []*corev1.Node
1307-
for _, node := range nodes {
1308-
if node.Annotations == nil {
1309-
continue
1310-
}
1311-
dconfig, ok := node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey]
1312-
if !ok || dconfig == "" {
1313-
continue
1314-
}
1315-
dstate, ok := node.Annotations[daemonconsts.MachineConfigDaemonStateAnnotationKey]
1316-
if !ok || dstate == "" {
1317-
continue
1318-
}
1319-
1320-
if dstate == daemonconsts.MachineConfigDaemonStateDegraded || dstate == daemonconsts.MachineConfigDaemonStateUnreconcilable {
1320+
if lns.IsNodeDegraded() || lns.IsNodeUnreconcilable() {
13211321
degraded = append(degraded, node)
13221322
}
1323+
if lns.IsUnavailableForUpdate() {
1324+
unavail = append(unavail, node)
1325+
}
1326+
}
1327+
return MachinesByStatus{
1328+
Updated: updated,
1329+
Degraded: degraded,
1330+
Ready: ready,
1331+
Unavailable: unavail,
13231332
}
1324-
return degraded
13251333
}
13261334

13271335
// `IsMachineUpdatedMCN` checks if a machine (node) is "updated" by checking the associated MCN's

0 commit comments

Comments
 (0)