Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions pkg/customresourcestate/registry_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ func (c *compiledStateSet) values(v interface{}) (result []eachValue, errs []err
comparable := c.ValueFrom.Get(v)
value, ok := comparable.(string)
if !ok {
// If the path doesn't exist (nil), return empty results instead of an error.
// This is consistent with how Gauge handles nil values and is expected for
// status fields that don't exist at resource creation time.
if comparable == nil {
return []eachValue{}, nil
}
return []eachValue{}, []error{fmt.Errorf("%s: expected value for path to be string, got %T", c.path, comparable)}
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/customresourcestate/registry_factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,22 @@ func Test_values(t *testing.T) {
newEachValue(t, 0, "phase", "bar"),
newEachValue(t, 1, "phase", "foo"),
}},
{name: "stateset nil path", each: &compiledStateSet{
compiledCommon: compiledCommon{
path: mustCompilePath(t, "does", "not", "exist"),
},
LabelName: "phase",
List: []string{"foo", "bar"},
}, wantResult: []eachValue{}, wantErrors: nil},
{name: "stateset non-string value", each: &compiledStateSet{
compiledCommon: compiledCommon{
path: mustCompilePath(t, "spec", "replicas"),
},
LabelName: "phase",
List: []string{"1", "2"},
}, wantResult: []eachValue{}, wantErrors: []error{
errors.New("[spec,replicas]: expected value for path to be string, got float64"),
}},
Comment on lines +336 to +351
{name: "status_conditions", each: &compiledGauge{
compiledCommon: compiledCommon{
path: mustCompilePath(t, "status", "conditions", "[type=Ready]", "status"),
Expand Down
Loading