Skip to content

Commit 47e8a3c

Browse files
Merge pull request #493 from fmount/conditions
Remove duplicated code
2 parents 890f2ee + c162c49 commit 47e8a3c

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)