kubernetes / kubectl

Issue tracker and mirror of kubectl code
Apache License 2.0
2.86k stars 921 forks source link

`wait` command produces error on quoted conditions #1646

Closed tvandinther closed 1 month ago

tvandinther commented 2 months ago

What happened: The parsing of this command seems to be affected by quoting the argument.

$ kubectl wait --for "jsonpath='{.status.readyReplicas}'" deployment/coredns -n kube-system
error: unexpected path string, expected a 'name1.name2' or '.name1.name2' or '{name1.name2}' or '{.name1.name2}'

What you expected to happen:

$ kubectl wait --for "jsonpath='{.status.readyReplicas}'" deployment/coredns -n kube-system
deployment.apps/coredns condition met

just as the following unquoted example:

$ kubectl wait --for jsonpath='{.status.readyReplicas}' deployment/coredns -n kube-system
deployment.apps/coredns condition met

From my understanding, this should not affect things.

$ echo hello | wc -c
6
$ echo "hello" | wc -c
6

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

kubectl wait --for "jsonpath='{.status.readyReplicas}'" deployment/coredns -n kube-system

Anything else we need to know?: Some tools that manage subprocess always execute arguments as these quoted variants which makes the kubectl wait command fail with the error shown above.

Environment:

k8s-ci-robot commented 2 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-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
tvandinther commented 1 month ago

It turns out the single quotes aren't necessary and when removed the quoted command words. Although the help message specifies that these are required in the syntax. I am unsure why the differences.

ardaguclu commented 1 month ago

Isn't this issue trying to achieve similar behavior with https://github.com/kubernetes/kubernetes/issues/127073?.

tvandinther commented 1 month ago

I think the difficulty may have been averted with a different error message. There seems to be something wrong with it:

error: unexpected path string, expected a 'name1.name2' or '.name1.name2' or '{name1.name2}' or '{.name1.name2}'

It has duplicate options for:

What it should probably cover (and perhaps, what it is trying to say) is:

The duplicate of each syntax format has single quotes but should not have them.

ardaguclu commented 1 month ago

I think it tries to enumerate;

tvandinther commented 1 month ago

I see, I did not spot those leading dots. The help examples for wait have a variation of usage of the single quotes, but not one for if the whole argument is quoted. This is okay, but if you quote the argument, single-quoting like in the example will be parsed differently.

OK: kubectl wait --for=jsonpath='{.status.phase}'=Running pod/busybox1 Not OK: kubectl wait "--for=jsonpath='{.status.phase}'=Running" pod/busybox1 OK: kubectl wait "--for=jsonpath={.status.phase}=Running" pod/busybox1

Hopefully this distinction will help anyone else that gets this error and finds this issue.