Skip to content

Commit 2867a27

Browse files
daemon: update 'SetDegrade' flow to include updating the degrade condition in the MCN
1 parent 201cc31 commit 2867a27

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

pkg/apihelpers/apihelpers.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,34 @@ func GetManagedBootImagesWithUpdateDisabled() opv1.ManagedBootImages {
501501
func GetManagedBootImagesWithNoConfiguration() opv1.ManagedBootImages {
502502
return opv1.ManagedBootImages{}
503503
}
504+
505+
// // GetMachineConfigNodeCondition returns the condition with the provided type.
506+
// func GetMachineConfigNodeCondition(status mcfgv1.MachineConfigPoolStatus, condType mcfgv1.MachineConfigPoolConditionType) *mcfgv1.MachineConfigPoolCondition {
507+
// // in case of sync errors, return the last condition that matches, not the first
508+
// // this exists for redundancy and potential race conditions.
509+
// var LatestState *mcfgv1.MachineConfigPoolCondition
510+
// for i := range status.Conditions {
511+
// c := status.Conditions[i]
512+
// if c.Type == condType {
513+
// LatestState = &c
514+
// }
515+
// }
516+
// return LatestState
517+
// }
518+
519+
// // SetMachineConfigNodeCondition updates the MachineConfigNode to include the provided condition. If the condition that
520+
// // we are about to add already exists and has the same status and reason, then we are not going to update.
521+
// func SetMachineConfigNodeCondition(status *mcfgv1.MachineConfigPoolStatus, condition mcfgv1.MachineConfigPoolCondition) {
522+
// currentCond := GetMachineConfigPoolCondition(*status, condition.Type)
523+
// if currentCond != nil && currentCond.Status == condition.Status && currentCond.Reason == condition.Reason && currentCond.Message == condition.Message {
524+
// return
525+
// }
526+
// // Do not update lastTransitionTime if the status of the condition doesn't change.
527+
// if currentCond != nil && currentCond.Status == condition.Status {
528+
// condition.LastTransitionTime = currentCond.LastTransitionTime
529+
// }
530+
// newConditions := filterOutMachineConfigPoolCondition(status.Conditions, condition.Type)
531+
// newConditions = append(newConditions, condition)
532+
// status.Conditions = newConditions
533+
534+
// }

pkg/daemon/daemon.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,15 +649,33 @@ type unreconcilableErr struct {
649649
error
650650
}
651651

652+
// updateErrorState calls `SetUnreconcilable` to set the node's state annotation value to
653+
// "Unreconcilable" and the associated reason annotation if the provided error is an unreconcilable
654+
// error. Otherwise it calls `updateDegradedState` to set the node's state annotation value to
655+
// "Degraded," populate the associated reason annotation, and set the degrade condition in the MCN.
652656
func (dn *Daemon) updateErrorState(err error) error {
653657
var uErr *unreconcilableErr
654658
if errors.As(err, &uErr) {
655-
dn.nodeWriter.SetUnreconcilable(err)
659+
return dn.nodeWriter.SetUnreconcilable(err)
656660
} else {
657-
if err := dn.nodeWriter.SetDegraded(err); err != nil {
658-
return err
659-
}
661+
return dn.updateDegradedState(err)
662+
}
663+
}
664+
665+
// `updateDegradedState` calls `SetDegraded` to set the node's state annotation value to "Degraded"
666+
// and populate the associated reason annotation. It then sets the degrade condition in the MCN.
667+
func (dn *Daemon) updateDegradedState(err error) error {
668+
// Set node state annotation to "Degraded"
669+
if setErr := dn.nodeWriter.SetDegraded(err); setErr != nil {
670+
return setErr
671+
}
672+
// Get MCP associated with node
673+
pool, poolErr := helpers.GetPrimaryPoolNameForMCN(dn.mcpLister, dn.node)
674+
if poolErr != nil {
675+
return poolErr
660676
}
677+
// Set the node's MCN condition to "Degraded"
678+
dn.reportMachineNodeDegradeStatus(err, pool)
661679
return nil
662680
}
663681

@@ -2419,7 +2437,7 @@ func (dn *Daemon) runOnceFromMachineConfig(machineConfig mcfgv1.MachineConfig, c
24192437
// NOTE: This case expects a cluster to exists already.
24202438
ufc, err := dn.prepUpdateFromCluster()
24212439
if err != nil {
2422-
if err := dn.nodeWriter.SetDegraded(err); err != nil {
2440+
if err := dn.updateDegradedState(err); err != nil {
24232441
return err
24242442
}
24252443
return err
@@ -2429,7 +2447,7 @@ func (dn *Daemon) runOnceFromMachineConfig(machineConfig mcfgv1.MachineConfig, c
24292447
}
24302448
// At this point we have verified we need to update
24312449
if err = dn.triggerUpdateWithMachineConfig(ufc.currentConfig, &machineConfig, false); err != nil {
2432-
dn.nodeWriter.SetDegraded(err)
2450+
dn.updateDegradedState(err)
24332451
return err
24342452
}
24352453
return nil

0 commit comments

Comments
 (0)