Refactor to make it obvious that newCondition is a copy

This commit is contained in:
Joshua Casey
2024-08-07 10:56:07 -05:00
parent 8b97414f3d
commit 4a9136040c

View File

@@ -37,15 +37,15 @@ func MergeConditions(
log plog.MinLogger,
) bool {
for i := range newConditions {
cond := newConditions[i].DeepCopy()
cond.LastTransitionTime = lastTransitionTime
cond.ObservedGeneration = observedGeneration
if mergeCondition(existingConditionsToUpdate, cond) {
newCondition := newConditions[i].DeepCopy()
newCondition.LastTransitionTime = lastTransitionTime
newCondition.ObservedGeneration = observedGeneration
if mergeCondition(existingConditionsToUpdate, newCondition) {
log.Info("updated condition",
"type", cond.Type,
"status", cond.Status,
"reason", cond.Reason,
"message", cond.Message)
"type", newCondition.Type,
"status", newCondition.Status,
"reason", newCondition.Reason,
"message", newCondition.Message)
}
}
sort.SliceStable(*existingConditionsToUpdate, func(i, j int) bool {
@@ -72,8 +72,7 @@ func mergeCondition(existingConditionsToUpdate *[]metav1.Condition, newCondition
}
// Set the LastTransitionTime depending on whether the status has changed.
newCondition = newCondition.DeepCopy()
if existingCondition.Status == newCondition.Status {
if newCondition.Status == existingCondition.Status {
newCondition.LastTransitionTime = existingCondition.LastTransitionTime
}