Skip to content

Commit

Permalink
Fix nullptr issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Kieweg committed Feb 21, 2024
1 parent 92b2d5f commit b0e5e85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions controller/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
oldTimestamp := getOldTimestamp(statuses, 0)
appHealth := appv1.HealthStatus{Status: health.HealthStatusHealthy}
for i, res := range resources {
timestamp := metav1.Now()
if res.Target != nil && hookutil.Skip(res.Target) {
continue
}
Expand Down Expand Up @@ -72,7 +73,6 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource
}

if persistResourceHealth {
timestamp := metav1.Now()

// If the status didn't change, we don't want to update the timestamp
if healthStatus.Status == statuses[i].Health.Status {
Expand All @@ -97,7 +97,11 @@ func setApplicationHealth(resources []managedResource, statuses []appv1.Resource

if health.IsWorse(appHealth.Status, healthStatus.Status) {
appHealth.Status = healthStatus.Status
appHealth.Timestamp = statuses[i].Health.Timestamp
if persistResourceHealth {
appHealth.Timestamp = statuses[i].Health.Timestamp
} else {
appHealth.Timestamp = timestamp
}
} else if healthStatus.Status == health.HealthStatusHealthy {
appHealth.Timestamp = oldTimestamp
}
Expand Down
2 changes: 1 addition & 1 deletion controller/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestSetApplicationHealth(t *testing.T) {
healthStatus, err = setApplicationHealth(resources, resourceStatuses, nil, app, true)
assert.NoError(t, err)
assert.Equal(t, health.HealthStatusHealthy, healthStatus.Status)
assert.Equal(t, firstHealthStatusTimestamp, healthStatus.Timestamp)
assert.Equal(t, testTimestamp, healthStatus.Timestamp)
}

func TestSetApplicationHealth_ResourceHealthNotPersisted(t *testing.T) {
Expand Down

0 comments on commit b0e5e85

Please sign in to comment.