Skip to content

Commit 63d2138

Browse files
rexagodmrueg
authored andcommitted
Don't crash on non-existent path values
Don't crash on non-existent path values in CRS. Signed-off-by: Pranshu Srivastava <[email protected]>
1 parent b06d352 commit 63d2138

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/customresourcestate/registry_factory.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,10 @@ func (c compiledGauge) value(it interface{}) (*eachValue, error) {
430430
Value: 0,
431431
}, nil
432432
}
433+
// no it means no iterables were passed down, meaning that the path resolution never happened
434+
if it == nil {
435+
return nil, fmt.Errorf("got nil while resolving path")
436+
}
433437
// Don't error if there was not a type-casting issue (`toFloat64`), but rather a failed lookup.
434438
return nil, nil
435439
}

pkg/customresourcestate/registry_factory_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package customresourcestate
1818

1919
import (
2020
"encoding/json"
21+
"errors"
2122
"reflect"
2223
"testing"
2324

@@ -194,6 +195,17 @@ func Test_values(t *testing.T) {
194195
}, wantResult: []eachValue{
195196
newEachValue(t, 1.6563744e+09),
196197
}},
198+
{name: "non-existent path", each: &compiledGauge{
199+
compiledCommon: compiledCommon{
200+
path: mustCompilePath(t, "foo"),
201+
labelFromPath: map[string]valuePath{
202+
"name": mustCompilePath(t, "name"),
203+
},
204+
},
205+
ValueFrom: mustCompilePath(t, "creationTimestamp"),
206+
}, wantResult: nil, wantErrors: []error{
207+
errors.New("[foo]: got nil while resolving path"),
208+
}},
197209
{name: "array", each: &compiledGauge{
198210
compiledCommon: compiledCommon{
199211
path: mustCompilePath(t, "status", "condition_values"),

0 commit comments

Comments
 (0)