Skip to content

Commit c162c49

Browse files
committed
Remove duplicated code
Defer function shouldn't be responsible to set the top-level ready condition because the same code has been moved to the main Reconcile loop. This patch represents a cleanup of a leftover from the previous PR. Signed-off-by: Francesco Pantano <[email protected]>
1 parent cc5c8f9 commit c162c49

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

controllers/glance_controller.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,14 @@ func (r *GlanceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
134134
// when a condition's state doesn't change.
135135
savedConditions := instance.Status.Conditions.DeepCopy()
136136

137-
// Always patch the instance status when exiting this function so we can persist any changes.
137+
// Always patch the instance status when exiting this function so we can
138+
// persist any changes.
138139
defer func() {
139-
// update the Ready condition based on the sub conditions
140-
if instance.Status.Conditions.AllSubConditionIsTrue() {
141-
instance.Status.Conditions.MarkTrue(
142-
condition.ReadyCondition, condition.ReadyMessage)
143-
} else {
144-
// something is not ready so reset the Ready condition
145-
instance.Status.Conditions.MarkUnknown(
146-
condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage)
147-
// and recalculate it based on the state of the rest of the conditions
148-
instance.Status.Conditions.Set(
149-
instance.Status.Conditions.Mirror(condition.ReadyCondition))
150-
}
151-
condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions)
140+
// Always mirror the condition status (useful in case of failures)
141+
instance.Status.Conditions.Set(
142+
instance.Status.Conditions.Mirror(condition.ReadyCondition))
143+
condition.RestoreLastTransitionTimes(
144+
&instance.Status.Conditions, savedConditions)
152145
err := helper.PatchInstance(ctx, instance)
153146
if err != nil {
154147
_err = err

0 commit comments

Comments
 (0)