Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot select annotation key using jsonpath #31984

Closed
erictune opened this issue Sep 2, 2016 · 2 comments
Closed

Cannot select annotation key using jsonpath #31984

erictune opened this issue Sep 2, 2016 · 2 comments
Labels
area/kubectl kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence.

Comments

@erictune
Copy link
Member

erictune commented Sep 2, 2016

I love using kubectl ... -o jsonpath but I cannot figure out how to print an annotation that contains a special character like - or / or ..

This does not work:
kubectl get pods tmp -o 'jsonpath={.metadata.annotations.kubernetes.io/created-by}{"\n"}'
nor this:
kubectl get pods tmp -o 'jsonpath={.metadata.annotations.kubernetes\.io\/created\-by}{"\n"}'
nor this:
kubectl get pods tmp -o 'jsonpath={.metadata.annotations}{["kubernetes.io/created-by"]}{"\n"}'
nor this:
kubectl get pods tmp-1986694738-dhpx0 -o jsonpath="{$['metadata']['annotations']['kubernetes.io/created-by']}"
(the last one should work according to what I can find about jsonPath, but doesn't, and anyhow is hard to get shell escaping right for.

Need a way to quote a

@erictune erictune changed the title How to select a map key with special characters in it using jsonpath Cannot select annotation key using jsonpath Sep 2, 2016
@erictune
Copy link
Member Author

erictune commented Sep 2, 2016

A use case for this is extracting "created-by" or "init-container" annotations. I've wanted to do both in the last month and fought jsonpath.

@janetkuo janetkuo added area/kubectl priority/backlog Higher priority than priority/awaiting-more-evidence. kind/bug Categorizes issue or PR as related to a bug. labels Sep 8, 2016
jmcarp added a commit to jmcarp/kubernetes that referenced this issue Oct 3, 2016
Example: `{.items[*].metadata.labels.kubernetes\.io/hostname}`

[Resolves kubernetes#31984]
@timstclair
Copy link

FYI, this is possible with go-template. We should still fix the jsonpath though.

kubectl get pods tmp -o go-template=$'{{index .metadata.annotations "kubernetes.io/created-by"}}\n'

Similar issue: #23386

k8s-github-robot pushed a commit that referenced this issue Oct 18, 2016
Automatic merge from submit-queue

Escape special characters in jsonpath field names.

There may be a better way to do this, but this seemed like the simplest possible version.

Example: `{.items[*].metadata.labels.kubernetes\.io/hostname}`

[Resolves #31984]
tallclair pushed a commit to tallclair/kubernetes that referenced this issue Aug 3, 2020
Example: `{.items[*].metadata.labels.kubernetes\.io/hostname}`

[Resolves kubernetes#31984]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl kind/bug Categorizes issue or PR as related to a bug. priority/backlog Higher priority than priority/awaiting-more-evidence.
Projects
None yet
Development

No branches or pull requests

3 participants