diff --git a/pkg/diag/diag.go b/pkg/diag/diag.go index c1f3a0a..df4b83d 100644 --- a/pkg/diag/diag.go +++ b/pkg/diag/diag.go @@ -179,7 +179,10 @@ func (d *Diag) CheckCRI(scope []string) CheckResult { missing := []string{} configured := []string{} for _, name := range scope { - handler := d.handlerFor(name) + handler, err := d.handlerFor(name) + if err != nil { + return CheckResult{ID: "cri", Status: StatusWarn, Detail: fmt.Sprintf("cannot read the local store: %v", err)} + } if cc.HasHandler(handler) { configured = append(configured, handler) } else { @@ -210,17 +213,20 @@ func (d *Diag) CheckEvents() CheckResult { return CheckResult{ID: "events", Status: StatusWarn, Detail: "reportEvent is false: pod failures may not surface as events. Enable edgeCore.reportEvent"} } -func (d *Diag) handlerFor(name string) string { +// handlerFor maps a class name to its handler from the local store. Classes +// absent from the store fall back to the class name (the common naming +// convention); a store read failure is returned instead of guessed at. +func (d *Diag) handlerFor(name string) (string, error) { classes, err := d.Store.ListRuntimeClasses() if err != nil { - return name + return "", err } for _, c := range classes { if c.Name == name && c.Handler != "" { - return c.Handler + return c.Handler, nil } } - return name + return name, nil } func lookupOutcome(handler string, err error) string { diff --git a/pkg/diag/diag_test.go b/pkg/diag/diag_test.go index 19ca4d2..2702f31 100644 --- a/pkg/diag/diag_test.go +++ b/pkg/diag/diag_test.go @@ -199,6 +199,16 @@ func TestCheckCRI(t *testing.T) { t.Fatalf("expected warn, got %+v", res) } }) + t.Run("warn when store unreadable", func(t *testing.T) { + d := withPaths(t, &Diag{Store: &fakeStore{err: errBoom}}) + res := d.CheckCRI([]string{"kata"}) + if res.Status != StatusWarn { + t.Fatalf("expected warn, got %+v", res) + } + if !strings.Contains(res.Detail, "local store") { + t.Fatalf("expected store error in detail, got %q", res.Detail) + } + }) } func TestCheckEvents(t *testing.T) {