Skip to content

Commit 9d66fc7

Browse files
authored
Merge pull request #394 from makkes/prevent-npes
fix: prevent nil pointer dereference in health checks
2 parents 969bd4d + 08920d3 commit 9d66fc7

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)