diff --git a/pkg/customresourcestate/registry_factory.go b/pkg/customresourcestate/registry_factory.go index 66158782eb..8cfe716c76 100644 --- a/pkg/customresourcestate/registry_factory.go +++ b/pkg/customresourcestate/registry_factory.go @@ -269,6 +269,9 @@ func (c *compiledInfo) Values(v interface{}) (result []eachValue, errs []error) } func (c *compiledInfo) values(v interface{}) (result []eachValue, err []error) { + if v == nil { + return + } value := eachValue{Value: 1, Labels: map[string]string{}} addPathLabels(v, c.labelFromPath, value.Labels) result = append(result, value) diff --git a/pkg/customresourcestate/registry_factory_test.go b/pkg/customresourcestate/registry_factory_test.go index 09676d8001..b553fa4be5 100644 --- a/pkg/customresourcestate/registry_factory_test.go +++ b/pkg/customresourcestate/registry_factory_test.go @@ -209,6 +209,11 @@ func Test_values(t *testing.T) { }, wantResult: []eachValue{ newEachValue(t, 1, "version", "v0.0.0"), }}, + {name: "info nil path", each: &compiledInfo{ + compiledCommon{ + path: mustCompilePath(t, "does", "not", "exist"), + }, + }, wantResult: nil}, {name: "stateset", each: &compiledStateSet{ compiledCommon: compiledCommon{ path: mustCompilePath(t, "status", "phase"),