Skip to content

Document how to negate a jsonpath conditional #7853

@rcorre

Description

@rcorre

This is a...

  • Feature Request
  • Bug Report

Problem:

kubectl get ns -ojsonpath='{range .items[?(@.metadata.labels.origin)]}{.metadata.name}{"\n"}'

lists namespaces that have the label "origin". How do I list namespaces that don't have the label "origin"?

The jsonpath docs provided by kubernetes.io are very sparse, and pretty much say "we support jsonpath plus a few extra features". There's no link to the official "jsonpath" docs, so I had to search and eventually found my way to http://goessner.net/articles/JsonPath/. That pretty much says "jsonpath is like xpath" without giving a full description of the syntax, so I then found my way to https://en.wikipedia.org/wiki/XPath.

That finally seemed to be comprehensive syntax documentation, yet doesn't seem compatible with k8s. For my above example, I would expect the boolean function not to work, yet

kubectl get ns -ojsonpath='{range .items[?(not(@.metadata.labels.origin))]}{.metadata.name}{"\n"}'

fails with error: error parsing jsonpath {range .items[?(not(@.metadata.labels.origin))]}{.metadata.name}{"\n"}, unclosed array expect ].

Proposed Solution:

Include full jsonpath syntax documentation, or link to a page that documents jsonpath in a way that is compatible with k8s. Alternately, if kubectl does not really support jsonpath, the line "And we add three functions in addition to the original JSONPath syntax" should be changed to reflect that.

Page to Update:
https://kubernetes.io/docs/reference/kubectl/jsonpath/

Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.5", GitCommit:"f01a2bf98249a4db383560443a59bed0c13575df", GitTreeState:"clean", BuildDate:"2018-03-19T15:50:45Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

Metadata

Metadata

Labels

lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.sig/docsCategorizes an issue or PR as relevant to SIG Docs.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions