kubernetes: jsonpath: missing `left' in filter has confusing error message and fails unexpectedly

On current master, jsonpath will fail to evaluate a filter when the 'left' member does not exist:

if len(lefts) != 1 {
    return input, fmt.Errorf("can only compare one element at a time")
}

For instance, if I were to execute

kubectl get pods -o jsonpath='{.items[@.metadata.annotations.foo=="bar"].metadata.name}'

Where not all pods in that namespace had the foo annotation, this would fail with the error message:

error: error executing jsonpath "{.items[?(@.metadata.annotations.foo==\"bar\")].metadata.name}": can only compare one element at a time

This is confusing as it leads me to think more than one item was selected, so while it is not technically incorrect the error message is misleading.

I would furthermore expect jsonpath to more gracefully handle this case – a missing 'left' here means that the filter should fail, not error.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I think I have a fix. PR coming soon.