Skip to content

Commit 08920d3

Browse files
author
Max Jonas Werner
committed
fix: prevent nil pointer dereference in health checks
When checking the health status of each declared resource, kstatus might return nil for certain resources (for whatever reason). In that case, this information is now conveyed in the health status event. #374 Signed-off-by: Max Jonas Werner <[email protected]>
1 parent 969bd4d commit 08920d3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

controllers/kustomization_healthcheck.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ func (hc *KustomizeHealthCheck) Assess(pollInterval time.Duration) error {
6464
func(statusCollector *collector.ResourceStatusCollector, e event.Event) {
6565
var rss []*event.ResourceStatus
6666
for _, rs := range statusCollector.ResourceStatuses {
67+
if rs == nil {
68+
continue
69+
}
6770
if rs.Error == nil {
6871
lastStatus[rs.Identifier] = rs
6972
}
@@ -86,11 +89,15 @@ func (hc *KustomizeHealthCheck) Assess(pollInterval time.Duration) error {
8689

8790
if ctx.Err() == context.DeadlineExceeded {
8891
errors := []string{}
89-
for _, rs := range coll.ResourceStatuses {
90-
if lastStatus[rs.Identifier].Status != status.CurrentStatus {
91-
id := hc.objMetadataToString(rs.Identifier)
92+
for id, rs := range coll.ResourceStatuses {
93+
if rs == nil {
94+
errors = append(errors, fmt.Sprintf("no status for %s available", id))
95+
continue
96+
}
97+
if lastStatus[id].Status != status.CurrentStatus {
98+
idString := hc.objMetadataToString(rs.Identifier)
9299
var bld strings.Builder
93-
bld.WriteString(fmt.Sprintf("%s (status '%s')", id, lastStatus[rs.Identifier].Status))
100+
bld.WriteString(fmt.Sprintf("%s (status '%s')", idString, lastStatus[id].Status))
94101
if rs.Error != nil {
95102
bld.WriteString(fmt.Sprintf(": %s", rs.Error))
96103
}

0 commit comments

Comments
 (0)