mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-10 03:19:44 +00:00
jsonpath filter: allow intermediate missing keys
In jsonpath, when filtering a list, if allowMissingKeys is true, skip over any items that are missing an intermediate key in the filter, instead of returning a confusing error. For example, if the filter is {.items[?(@.metadata.annotations.foo=="bar")].metadata.name} we should return all items where metadata.annotations.foo == bar, but if an item in the list does not have metadata, metadata.annotations, or metadata.annotations.foo, skip it instead of erroring. Kubernetes-commit: e6f97d514d83fc2614d1ad4e18de0b318cc81653
This commit is contained in:
committed by
Kubernetes Publisher
parent
812b4cbd4b
commit
75943a8927
@@ -455,7 +455,10 @@ func (j *JSONPath) evalFilter(input []reflect.Value, node *FilterNode) ([]reflec
|
||||
}
|
||||
|
||||
var left, right interface{}
|
||||
if len(lefts) != 1 {
|
||||
switch {
|
||||
case len(lefts) == 0:
|
||||
continue
|
||||
case len(lefts) > 1:
|
||||
return input, fmt.Errorf("can only compare one element at a time")
|
||||
}
|
||||
left = lefts[0].Interface()
|
||||
@@ -464,7 +467,10 @@ func (j *JSONPath) evalFilter(input []reflect.Value, node *FilterNode) ([]reflec
|
||||
if err != nil {
|
||||
return input, err
|
||||
}
|
||||
if len(rights) != 1 {
|
||||
switch {
|
||||
case len(rights) == 0:
|
||||
continue
|
||||
case len(rights) > 1:
|
||||
return input, fmt.Errorf("can only compare one element at a time")
|
||||
}
|
||||
right = rights[0].Interface()
|
||||
|
Reference in New Issue
Block a user