kubernetes: JsonPath nested condition and multiple conditions are not working
I want to get the list of all pods that are ready to take requests. In order to do that I run the following queries:
kubectl get pods -l app=my-app -o jsonpath='{.items[?(@.status.conditions[?(@.type == "Ready")].status == "True")].status.phase}'
OR
kubectl get pods -l app=my-app -o jsonpath='{.items[?(@.status.conditions[*].type == "Ready" && @.status.conditions[*].status == "True")].status.phase}'
Neither of them works. Jsonpath doesn’t support nested filters or multiple filters.
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Reactions: 42
- Comments: 35 (18 by maintainers)
Commits related to this issue
- Use awk to filter the ready nodes As due to the https://github.com/kubernetes/kubernetes/issues/20352 The previous fix was not working — committed to kisieland/test-infra by kisieland 3 years ago
So now that RFC9535: JSONPath: Query Expressions for JSON is a proposed standard by the IETF, perhaps it’s time to reopen this and expand the implementation?
Such functionality is super-useful for print columns,
kubectland potentially other areas in Kubernetes.Is there current ongoing work to apply this new standard somewhere? If so, would be happy if someone can provide a pointer to the relevant KEP or similar document, thanks!
P.S. It might be worth considering using CEL instead of JSONPath; but in general, any solution providing more advanced querying capabilities would be useful to the community in my opinion.
👋 Is this being worked on anywhere? If not I could take a look.
/reopen Issue still there
Seems a new draft was release three days ago: https://datatracker.ietf.org/wg/jsonpath/documents/
Working to get the first part of the implementation merged over at #79227
Looks like there’s one in the process of being drafted: https://tools.ietf.org/html/draft-goessner-dispatch-jsonpath-00