kubernetes / kubernetes

Production-Grade Container Scheduling and Management
https://kubernetes.io
Apache License 2.0
108.33k stars 38.87k forks source link

Jsonpath impl does not support left match regex #124157

Open rotty3000 opened 3 months ago

rotty3000 commented 3 months ago

What would you like to be added?

I would like to have support for =~ in jsonpath filter expressions.

e.g.

Matches a Golang regular expression. For example, k get pods -o jsonpath='{.items[?(@.metadata.name =~ /^node.*/i)].metadata.name}' matches items whose description starts with node (case-insensitive).

Why is this needed?

When many resources exist in the system being able to match by regex can greatly simplify locating the desired resources.

Note: I am willing to contribute an implementation.

neolit123 commented 3 months ago

/sig api-machinery

alexzielenski commented 2 months ago

/sig cli /cc @jpbetz /triage accepted

jpbetz commented 2 months ago

I'll defer to sig-cli for the kubectl functionality, which I think is front and center here.

But just to clarify the server side aspects-- on the apiserver we only use a very limited subset of json path, typically we only allow a dot separated list of field names like supported by CRD additionalPrinterColumns and similar. I don't anticipate that being expanded. We're trending toward use of CEL server side to perform more involved operations, including plans to use it for field extraction, and so I don't think we'll be investing in json path in the apiserver.