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
Avoid conflicts with other cobra auto completions #70470
Conversation
/ok-to-test |
I don't think I can reproduce this bug
|
Here's my result without this fix.
|
/assign @deads2k |
@deads2k Could you review this PR? |
cc @kubernetes/sig-cli-pr-reviews |
pkg/kubectl/cmd/cmd.go
Outdated
@@ -84,7 +84,11 @@ __kubectl_override_flags() | |||
local ${__kubectl_override_flag_list[*]##*-} two_word_of of var | |||
for w in "${words[@]}"; do | |||
if [ -n "${two_word_of}" ]; then | |||
eval "${two_word_of##*-}=\"${two_word_of}=\${w}\"" | |||
if [[ "${two_word_of}" == --* ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If that is a bug, I don't think this pr will actually fix it.
The changes here is only used for bash completion, which will do nothing for parsing arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug is in the autocompletion… the suggestions on [tab][tab] do not honor the specified namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bug is in the autocompletion… the suggestions on [tab][tab] do not honor the specified namespace
Yes, that is what I wanted to fix, but it seems I was looking into a wrong place. I'm trying to update reproducible steps and fix the issue.
2bc41bd
to
8bcd82b
Compare
I added debug logs for auto completion commands and found which patterns don't work correctly. ✅ I enabled debug logs and got the following. the completion log
For the failed case of I found the completion script has the following related lines. ...
# skip the argument to a two word flag
if __kubectl_contains_word "${words[c]}" "${two_word_flags[@]}"; then
c=$((c+1))
# if we are looking for a flags value, don't show commands
if [[ $c -eq $cword ]]; then
commands=()
fi
fi
... This code skips next argument of two-word flags but it seems only ...
flags+=("--namespace=")
flags_with_completion+=("--namespace")
flags_completion+=("__kubectl_get_resource_namespace")
two_word_flags+=("-n")
flags_with_completion+=("-n")
flags_completion+=("__kubectl_get_resource_namespace")
... And I dug into the upstream code and found that part of the script is generated by cobra. So I fixed it and sent a PR to cobra. We can fix this issue by using a cobra version with this fix. I actually have sent a PR to update the Cobra version which addresses another issue but doesn't include this fix. I will fix either of the PRs depending on when new Cobra version will be released. |
ceab413
to
e360424
Compare
/test pull-kubernetes-godeps |
e360424
to
5e8eec7
Compare
90ac109
to
8c8e31f
Compare
8c8e31f
to
97d08a7
Compare
|
@liggitt So do you mean I can ignore the result of |
for the golang.org/x/... dependencies, yes. Opened #79944 to omit those from the output by default to avoid confusing people. It looks like cobra tagged a release containing the fix we want, which is great. You can replace all the dependency bump commits with a single commit that just bumps cobra:
|
Thank you for the information! It looks the fix for two-word flags is included in cobra v0.0.4 and it has been updated in #78187 already although it doesn't mention the fix. |
97d08a7
to
93d3a52
Compare
93d3a52
to
4200d6c
Compare
@liggitt As the fix for two-word flags has been included in cobra v0.0.4 which has been updated in Kubernetes, I renamed the title of this PR and committed only the change of custom func name and debug mode autocompletion. Could you review it? |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dtaniwaki, liggitt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
It looks like this PR breaks kubectl completion if override flags (e.g., --kubeconfig) are supplied. |
What type of PR is this?
/kind bug
What this PR does / why we need it:
kubectl get -n foo pod [TAB][TAB]
ignores the namespace whilekubectl get --namespace foo pod [TAB][TAB]
andkubectl get --namespace=foo pod [TAB][TAB]
don't.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):N/A
Special notes for your reviewer:
N/A
Does this PR introduce a user-facing change?: