Skip to content

Commit

Permalink
daemon/pinnedimageset: ensure pool is degraded if out of space
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Batschelet <[email protected]>
  • Loading branch information
hexfusion committed Apr 25, 2024
1 parent 926f71b commit b9280a6
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 105 deletions.
39 changes: 27 additions & 12 deletions pkg/controller/node/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ func calculateStatus(fg featuregates.FeatureGate, mcs []*mcfgalphav1.MachineConf
}
}
machineCount := int32(len(nodes))
updatingPinnedImageSetMachines := int32(0)

var degradedMachines, readyMachines, updatedMachines, unavailableMachines, updatingMachines []*corev1.Node
var updatingPinnedImageSetMachines int32
degradedReasons := []string{}

// if we represent updating properly here, we will also represent updating properly in the CO
// so this solves the cordoning RFE and the upgradeable RFE
// updating == updatePrepared, updateExecuted, updatedComplete, postAction, cordoning, draining
Expand All @@ -114,18 +116,23 @@ func calculateStatus(fg featuregates.FeatureGate, mcs []*mcfgalphav1.MachineConf
// not ready yet
break
}
pinnedImageSetsUpdating := false
if fg.Enabled(configv1.FeatureGatePinnedImages) {
if isPinnedImageSetNodeUpdating(state) {
updatingPinnedImageSetMachines++
}
}
for _, cond := range state.Status.Conditions {
if strings.Contains(cond.Message, "Error:") {
degradedMachines = append(degradedMachines, ourNode)
continue
}
if fg.Enabled(configv1.FeatureGatePinnedImages) && cond.Status == metav1.ConditionTrue {
if mcfgalphav1.StateProgress(cond.Type) == mcfgalphav1.MachineConfigNodePinnedImageSetsProgressing ||
mcfgalphav1.StateProgress(cond.Type) == mcfgalphav1.MachineConfigNodePinnedImageSetsDegraded {
pinnedImageSetsUpdating = true
// populate the degradedReasons from the MachineConfigNodePinnedImageSetsDegraded condition
if fg.Enabled(configv1.FeatureGatePinnedImages) {
if mcfgalphav1.StateProgress(cond.Type) == mcfgalphav1.MachineConfigNodePinnedImageSetsDegraded && cond.Status == metav1.ConditionTrue {
degradedReasons = append(degradedReasons, fmt.Sprintf("Node %s is reporting: %q", ourNode.Name, cond.Message))
}
}
continue
}

if cond.Status == metav1.ConditionUnknown {
switch mcfgalphav1.StateProgress(cond.Type) {
case mcfgalphav1.MachineConfigNodeUpdatePrepared:
Expand Down Expand Up @@ -153,9 +160,6 @@ func calculateStatus(fg featuregates.FeatureGate, mcs []*mcfgalphav1.MachineConf
}
}
}
if pinnedImageSetsUpdating {
updatingPinnedImageSetMachines++
}
}
degradedMachineCount := int32(len(degradedMachines))
updatedMachineCount := int32(len(updatedMachines))
Expand All @@ -178,7 +182,6 @@ func calculateStatus(fg featuregates.FeatureGate, mcs []*mcfgalphav1.MachineConf
degradedMachineCount = int32(len(degradedMachines))
}

degradedReasons := []string{}
for _, n := range degradedMachines {
reason, ok := n.Annotations[daemonconsts.MachineConfigDaemonReasonAnnotationKey]
if ok && reason != "" {
Expand All @@ -198,13 +201,15 @@ func calculateStatus(fg featuregates.FeatureGate, mcs []*mcfgalphav1.MachineConf

// update synchronizer status for pinned image sets
if fg.Enabled(configv1.FeatureGatePinnedImages) {
// TODO: update counts to be more granular
status.PoolSynchronizersStatus = []mcfgv1.PoolSynchronizerStatus{
{
PoolSynchronizerType: mcfgv1.PinnedImageSets,
MachineCount: int64(machineCount),
UpdatedMachineCount: int64(machineCount - updatingPinnedImageSetMachines),
ReadyMachineCount: int64(readyMachineCount),
UnavailableMachineCount: int64(unavailableMachineCount),
AvailableMachineCount: int64(machineCount - unavailableMachineCount),
},
}
}
Expand Down Expand Up @@ -279,6 +284,16 @@ func calculateStatus(fg featuregates.FeatureGate, mcs []*mcfgalphav1.MachineConf
return status
}

func isPinnedImageSetNodeUpdating(mcs *mcfgalphav1.MachineConfigNode) bool {
var updating int32
for _, set := range mcs.Status.PinnedImageSets {
if set.CurrentGeneration != set.DesiredGeneration {
updating++
}
}
return updating > 0
}

func getPoolUpdateLine(pool *mcfgv1.MachineConfigPool) string {
targetConfig := pool.Spec.Configuration.Name
mcLine := fmt.Sprintf("MachineConfig %s", targetConfig)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/pinnedimageset/pinned_image_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func triggerPinnedImageSetChange(old, new *mcfgv1alpha1.PinnedImageSet) bool {
if old.DeletionTimestamp != new.DeletionTimestamp {
return true
}
if !reflect.DeepEqual(old.Spec, new.Spec) {
if !reflect.DeepEqual(old, new) {
return true
}
return false
Expand Down
Loading

0 comments on commit b9280a6

Please sign in to comment.