Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make it easier to reason about health check failures #374

Merged
merged 1 commit into from
Jul 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions controllers/kustomization_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ func (hc *KustomizeHealthCheck) Assess(pollInterval time.Duration) error {
opts := polling.Options{PollInterval: pollInterval, UseCache: true}
eventsChan := hc.statusPoller.Poll(ctx, objMetadata, opts)
coll := collector.NewResourceStatusCollector(objMetadata)
lastStatus := make(map[object.ObjMetadata]*event.ResourceStatus)
done := coll.ListenWithObserver(eventsChan, collector.ObserverFunc(
func(statusCollector *collector.ResourceStatusCollector, e event.Event) {
var rss []*event.ResourceStatus
for _, rs := range statusCollector.ResourceStatuses {
if rs.Error == nil {
lastStatus[rs.Identifier] = rs
}
rss = append(rss, rs)
}
desired := status.CurrentStatus
Expand All @@ -81,14 +85,19 @@ func (hc *KustomizeHealthCheck) Assess(pollInterval time.Duration) error {
}

if ctx.Err() == context.DeadlineExceeded {
ids := []string{}
errors := []string{}
for _, rs := range coll.ResourceStatuses {
if rs.Status != status.CurrentStatus {
if lastStatus[rs.Identifier].Status != status.CurrentStatus {
id := hc.objMetadataToString(rs.Identifier)
ids = append(ids, id)
var bld strings.Builder
bld.WriteString(fmt.Sprintf("%s (status '%s')", id, lastStatus[rs.Identifier].Status))
if rs.Error != nil {
bld.WriteString(fmt.Sprintf(": %s", rs.Error))
}
errors = append(errors, bld.String())
}
}
return fmt.Errorf("Health check timed out for [%v]", strings.Join(ids, ", "))
return fmt.Errorf("Health check failed for [%s]", strings.Join(errors, ", "))
}

return nil
Expand Down