@@ -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
@@ -1297,42 +1296,51 @@ func RequiresRebuild(oldMC, newMC *mcfgv1.MachineConfig) bool {
12971296 ! reflect .DeepEqual (oldMC .Spec .KernelArguments , newMC .Spec .KernelArguments )
12981297}
12991298
1300- // GetUpdatedMachines filters the provided nodes to return the nodes whose
1301- // current config matches its desired config and target config in the
1302- // associated MCP and has the "done" flag set.
1303- func GetUpdatedMachines (pool * mcfgv1.MachineConfigPool , nodes []* corev1.Node , mosc * mcfgv1.MachineOSConfig , mosb * mcfgv1.MachineOSBuild , layered bool ) []* corev1.Node {
1299+ type MachinesByStatus struct {
1300+ Updated []* corev1.Node
1301+ Degraded []* corev1.Node
1302+ Ready []* corev1.Node
1303+ Unavailable []* corev1.Node
1304+ }
1305+
1306+ // GetMachinesByState takes a list of nodes and returns lists of nodes filtered by state. The
1307+ // states and their requirements are:
1308+ // - Updated: A node's current config matches its desired config and the target config in the
1309+ // associated MCP and the node has the "done" flag set
1310+ // - Degraded: The node's `machineconfiguration.openshift.io/state` annotation has a value of
1311+ // "Degraded" or "Unreconcilable"
1312+ // - Ready: The node is "Updated" and marked ready
1313+ // - Unavailable: The node is either marked unscheduleable or has a MCD actively working. If the
1314+ // MCD is actively working (or hasn't started) then the node *may* go unschedulable in the
1315+ // future, so the node is considered "unavailable" so another node update does not exceed
1316+ // the desired maxUnavailable. (Somewhat the opposite of a "Ready" node)
1317+ func GetMachinesByState (pool * mcfgv1.MachineConfigPool , nodes []* corev1.Node , mosc * mcfgv1.MachineOSConfig , mosb * mcfgv1.MachineOSBuild , layered bool ) MachinesByStatus {
13041318 var updated []* corev1.Node
1319+ var degraded []* corev1.Node
1320+ var ready []* corev1.Node
1321+ var unavail []* corev1.Node
13051322 for _ , node := range nodes {
13061323 lns := NewLayeredNodeState (node )
13071324 if lns .IsDone (pool , layered , mosc , mosb ) {
13081325 updated = append (updated , node )
1326+ // A node must be updated to be considered "Ready"
1327+ if lns .IsNodeReady () {
1328+ ready = append (ready , node )
1329+ }
13091330 }
1310- }
1311- return updated
1312- }
1313-
1314- // GetDegradedMachines filters the provided nodes to return the nodes that
1315- // are considered in a degraded state.
1316- func GetDegradedMachines (nodes []* corev1.Node ) []* corev1.Node {
1317- var degraded []* corev1.Node
1318- for _ , node := range nodes {
1319- if node .Annotations == nil {
1320- continue
1321- }
1322- dconfig , ok := node .Annotations [daemonconsts .DesiredMachineConfigAnnotationKey ]
1323- if ! ok || dconfig == "" {
1324- continue
1325- }
1326- dstate , ok := node .Annotations [daemonconsts .MachineConfigDaemonStateAnnotationKey ]
1327- if ! ok || dstate == "" {
1328- continue
1329- }
1330-
1331- if dstate == daemonconsts .MachineConfigDaemonStateDegraded || dstate == daemonconsts .MachineConfigDaemonStateUnreconcilable {
1331+ if lns .IsNodeDegraded () || lns .IsNodeUnreconcilable () {
13321332 degraded = append (degraded , node )
13331333 }
1334+ if lns .IsUnavailableForUpdate () {
1335+ unavail = append (unavail , node )
1336+ }
1337+ }
1338+ return MachinesByStatus {
1339+ Updated : updated ,
1340+ Degraded : degraded ,
1341+ Ready : ready ,
1342+ Unavailable : unavail ,
13341343 }
1335- return degraded
13361344}
13371345
13381346// `IsMachineUpdatedMCN` checks if a machine (node) is "updated" by checking the associated MCN's
0 commit comments