kubernetes / kubectl

Issue tracker and mirror of kubectl code
Apache License 2.0
2.83k stars 915 forks source link

kubectl not handling certain JSONPath queries #1535

Open EricBuist opened 9 months ago

EricBuist commented 9 months ago

What happened:

I have a config map containing a field with a dot in the name. The field is a YAML file encoded as a string. I wanted to extract the field using a JSONPath so it shows up as a YAML file instead of a single line with \n all over the place.

What you expected to happen:

I expected to get the information associated with field "application-config.yaml" from the config map config-map, without me having to think in advance not to put dots in field names.

How to reproduce it (as minimally and precisely as possible):

I verified that the issue happens with kubectl 1.29.0. Any config map with a field containing a dot, forcing use of [] in the JSONPath expression, will cause the problem.

  1. Create a config map containing a field named application-config.yaml.
  2. Try command kubectl get configmap config-map -o jsonpath="{.data['application-config.yaml']}". The command returns no output while it should return the contents or an error.

Anything else we need to know?:

Only workaround is to output the full JSON and use a tool such as jq to extract the information. JSONPath becomes in practice less and less useful, requiring a lot of trial and error to come up with an expression to then figure out it won't work and I'd have to use an external tool.

Environment:

k8s-ci-robot commented 9 months ago

This issue is currently awaiting triage.

SIG CLI takes a lead on issue triage for this repo, but any Kubernetes member can accept issues by applying the triage/accepted label.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
eddiezane commented 9 months ago

Does it work if you escape the . in the field name?

kubectl get configmap config-map -o jsonpath="{.data['application-config\.yaml']}"

k8s-triage-robot commented 6 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 5 months ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten