From 4bd5db14b45caef5a18959827da86187b0ca83ef Mon Sep 17 00:00:00 2001 From: Joshua Casey Date: Wed, 7 Aug 2024 12:23:11 -0500 Subject: [PATCH] Refactor branching logic when using an early return --- internal/controller/conditionsutil/conditions_util.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/controller/conditionsutil/conditions_util.go b/internal/controller/conditionsutil/conditions_util.go index 128b0ddac..7729c604b 100644 --- a/internal/controller/conditionsutil/conditions_util.go +++ b/internal/controller/conditionsutil/conditions_util.go @@ -67,11 +67,12 @@ func mergeCondition(existingConditionsToUpdate *[]metav1.Condition, newCondition // If there is no existing condition of this type, append this one and we're done. *existingConditionsToUpdate = append(*existingConditionsToUpdate, *newCondition) return true - } else { - existingCondition = &(*existingConditionsToUpdate)[index] } - // Set the LastTransitionTime depending on whether the status has changed. + // Get a pointer to the existing condition + existingCondition = &(*existingConditionsToUpdate)[index] + + // If the status has not changed, preserve the original lastTransitionTime if newCondition.Status == existingCondition.Status { newCondition.LastTransitionTime = existingCondition.LastTransitionTime }