diag: surface local-store read failures from the CRI check

handlerFor silently fell back to the class name when the store was
unreadable, so CheckCRI could report a wrong verdict (false pass, or a
missing-handler failure) with no indication that the store read failed.
The store error is now returned and the CRI check warns about it.
This commit is contained in:
lakshit verma 2026-08-08 00:58:08 +05:30
parent c2661f7c75
commit e0bc366525
No known key found for this signature in database
2 changed files with 21 additions and 5 deletions

View file

@ -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 {

View file

@ -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) {