Skip to content

Commit a8ce677

Browse files
fix(controller): always set health.status.lastTransitionTime (argoproj#22665) (cherry-pick argoproj#22666) (argoproj#22667)
Signed-off-by: Michael Crenshaw <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]>
1 parent 5d131c5 commit a8ce677

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

controller/health.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
8080
appHealth.Status = healthStatus.Status
8181
}
8282
}
83+
// if the status didn't change, don't update the timestamp
84+
if app.Status.Health.Status == appHealth.Status && app.Status.Health.LastTransitionTime != nil {
85+
appHealth.LastTransitionTime = app.Status.Health.LastTransitionTime
86+
} else {
87+
now := metav1.Now()
88+
appHealth.LastTransitionTime = &now
89+
}
8390
if persistResourceHealth {
8491
app.Status.ResourceHealthSource = appv1.ResourceHealthLocationInline
85-
// if the status didn't change, don't update the timestamp
86-
if app.Status.Health.Status == appHealth.Status && app.Status.Health.LastTransitionTime != nil {
87-
appHealth.LastTransitionTime = app.Status.Health.LastTransitionTime
88-
} else {
89-
now := metav1.Now()
90-
appHealth.LastTransitionTime = &now
91-
}
9292
} else {
9393
app.Status.ResourceHealthSource = appv1.ResourceHealthLocationAppTree
9494
}

controller/health_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func TestSetApplicationHealth_ResourceHealthNotPersisted(t *testing.T) {
109109
healthStatus, err := setApplicationHealth(resources, resourceStatuses, lua.ResourceHealthOverrides{}, app, false)
110110
require.NoError(t, err)
111111
assert.Equal(t, health.HealthStatusDegraded, healthStatus.Status)
112+
assert.NotNil(t, healthStatus.LastTransitionTime)
112113

113114
assert.Nil(t, resourceStatuses[0].Health)
114115
}

docs/operator-manual/upgrading/2.14-3.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Example of a status field in the Application CR persisting health:
319319
status:
320320
health:
321321
status: Healthy
322+
lastTransitionTime: "2025-01-01T00:00:00Z"
322323
resources:
323324
- group: apps
324325
health:
@@ -338,6 +339,7 @@ Example of a status field in the Application CR _not_ persisting health:
338339
status:
339340
health:
340341
status: Healthy
342+
lastTransitionTime: "2025-01-01T00:00:00Z"
341343
resourceHealthSource: appTree
342344
resources:
343345
- group: apps

0 commit comments

Comments
 (0)