kubernetes: Regular expressions not working in json-path

This is a duplicate of #61406, which was closed because it was stale (I couldn’t reopen it)

What happened: Trying to use the following json-path expression: kubectl get secrets -o jsonpath='{.items[?(@.metadata.name=~/^test$/)].metadata.name}' resulted in the following error: error: error parsing jsonpath {.items[?(@.metadata.name=~/^test$/)].metadata.name}, unrecognized character in action: U+007E '~'

What you expected to happen: Getting the list of secret names that match the regular expression. How to reproduce it (as minimally and precisely as possible): kubectl get secrets -o jsonpath='{.items[?(@.metadata.name=~/^default-/)]}' Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version): 1.10.2
  • Cloud provider or hardware configuration: Dell PC
  • OS (e.g. from /etc/os-release): Ubuntu 18.04.1 LTS
  • Kernel (e.g. uname -a): Linux pwt-test-cluster-master 4.15.0-34-generic #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Install tools:
  • Others:

/kind feature

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 27
  • Comments: 40 (16 by maintainers)

Most upvoted comments

This is still a problem - please fix this

For what it’s worth, JSONPath is being standardised at the moment. The work can be tracked here: https://datatracker.ietf.org/doc/draft-ietf-jsonpath-base/

Don’t get me wrong, that sounds like a super frustrating situation to be in, I’m sorry you have to live with that. (This is a horrible hack and probably not approved by corporate overlords, but, if you’re allowed to run things in a cluster, you could run grep or jq in a container via kubectl exec and/or attach!)

My own concern is ecosystem fragmentation, I don’t want to run a variation of JSONPath that ends up not being standard. E.g., if we go with go regexps and then some other flavor is standardized… then we would have a major problem: no course of action would make both existing and new users happy.

That said, this is only kubectl we’re talking about, not the API. So, it’s actually SIG CLI members that should be the gatekeeper here, not me.

Ran into the same issue. At least there should be a WARNING on document saying that jsonpath features are not fully implemented. Apparently I got nothing from doc and it wasted me 20 minutes checking jsonpath doc to see if I am wrong with syntax.

Same here. Just been banging my head against this for hours. It really should at least say on the json path kubectl docs that it isn’t fully supported.

i would like work on it @liggitt maybe as a GSOC project too.