Skip to content

Commit

Permalink
Factor out LastTransitionTime for CloudInit conds
Browse files Browse the repository at this point in the history
This way when a subsequent patch improves LastTransitionTime generation
for the other conditions, it can take advantage of not accidentally
updating the last transition time when it is unnecessary.

Signed-off-by: Connor Kuehl <[email protected]>
  • Loading branch information
Connor Kuehl authored and connorkuehl committed Apr 18, 2024
1 parent 99bfcbe commit f90a398
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/controller/cloudinit/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ func (c *controller) updateStatus(node *corev1.Node, cloudInitObj *cloudinitv1.C
cond := &conds[i]
prev := oldConds[cond.Type]

// Only retain the LastTransitionTime when it is not the first time
// processing this metav1.Cond.
var zero metav1.Condition
if prev != zero &&
cond.Status == prev.Status &&
cond.Reason == prev.Reason &&
cond.Message == prev.Message {
cond.LastTransitionTime = prev.LastTransitionTime
continue
}

switch cond.Type {
case string(cloudinitv1.CloudInitFilePresent):
if createdAt.After(cond.LastTransitionTime.Time) {
Expand All @@ -190,10 +201,6 @@ func (c *controller) updateStatus(node *corev1.Node, cloudInitObj *cloudinitv1.C
cond.LastTransitionTime = metav1.NewTime(modifiedAt)
}
case string(cloudinitv1.CloudInitApplicable):
if prev.Status == cond.Status && prev.Message == cond.Message && prev.Reason == cond.Reason {
cond.LastTransitionTime = prev.LastTransitionTime
break
}
cond.LastTransitionTime = metav1.NewTime(now)
}
}
Expand Down

0 comments on commit f90a398

Please sign in to comment.