-
Notifications
You must be signed in to change notification settings - Fork 921
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
kubectl plugins do not work when options placed before plugin name #884
Comments
What is the output of this?
|
Typical permissions:
|
Hmm. If you do |
Yes it does. And it's worth noting again that it works properly and runs the plugin if I run |
I was able to reproduce your problem when I made an alias for kubectl, like this:
By any chance, have you defined an alias for kubectl? |
Indeed!
Removing the alias makes it work. Is this a bug in kubectl, or an odd side-effect of how aliases work? |
Not sure if there is some way to fix or prevent this, but here is what I think is happening: Kubectl expects the plugin name needs to be the first thing after So when you have an alias of this:
And then try to use the
the code actually sees this (I think, haven't confirmed):
It seems like it should be made to work somehow though, because if I do I would also like to point out this is a problem with aliases in general, not just if you define a kubectl alias. So this would also not be able to call the foo plugin:
|
Agreed, this is what I'm seeing as well. The alias itself isn't the issue -- it occurs any time an argument appears before the plugin name.
|
this problem is a bit interesting and I think I have found out the reason. tl;dr for detailed reason, we can take a look at these lines: let's say we run |
Agreed -- it looks like that code block needs to be updated so that it enumerates through the whole list of |
@skaven81 and @knight42 I think your ideas are on the right track, but it gets a little tricky to figure out what to do when you consider this:
First one is simple to parse because it has no space, but the second one is harder because you need to know something about the context of the flag to know whether Take a look at Cobra's Traverse method that can separate out the command and args: Maybe that can somehow be used, but I think it only works if the command you are looking for is a subcommand, and plugins are not. But maybe a temporary dummy subcommand could be created for the plugin so that this method could be used to parse out the args without having to re-invent that logic. Just a thought. Also check out stripFlags from the same file: |
I am not sure whether it is a good idea to call the plugin with options before it, since users may assume plugin accepts the global flags as kubectl subcommand, but that is not always true. |
also I think we'd better change the title of this issue to something like |
I edited the title and description to make it more obvious to newcomers that this has nothing to do with strace. |
IMHO I think a better choice might be warn users about the options before the plugin name and call the plugin with remaining args after the plugin name. |
@knight42 That sounds like a good approach to me. I think there is still the situation of how do you identify what is supposed to be the plugin name vs some flag value. For example, if you have this alias:
If you try to run the foo plugin like this:
I think the code would consider the args to be
BUT... I think as long as the warning that you proposed is there, you could just accept that having flags without |
/assign |
@brianpursley @skaven81 I have filed a PR kubernetes/kubernetes#92343. EDIT:
|
/area kubectl |
/sig cli |
/priority P2 |
this was discussed in kubernetes/kubernetes#77666 and during the initial plugin impl review at juanvallejo/kubernetes#9 (comment) and juanvallejo/kubernetes#9 (comment) I don't think we have sufficient information to know how to relocate flags/args that appear ahead of plugin names |
For me, the main use case is to specify |
Since I've approved most of the 100 plugins in Krew, I can say that majority of the plugins out there don't even support As long as users can still tell what's the error, it's fine. |
@ahmetb Thanks for that data point. It seems fair that we shouldn't worry about supporting this use case. I do agree that the error output could be improved. It seems like plugins tend to rely on the alias ka='kubectl --kubeconfig="$ADMIN_KUBECONFIG"' to alias ka='KUBECONFIG="$ADMIN_KUBECONFIG" kubectl' And now I can run commands like |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@ahmetb this may just be me but this definitely violates the "principle of least surprise" for me. I have long found it quite frustrating (and a little un-unixy) that
There is no mention that users will likely encounter issues if they use one of these in particular. I know |
Without going into the way When considering aliases you should look into functions instead, which can handle parameters. # Create an alias
$ alias kd="kubectl -n devops"
# Getting an error
$ kd view-secret deployer-token-8d28z
Error: flags cannot be placed before plugin name: -n
# Removing the alias and adding a function instead
$ unalias kd
$ function kd(){ kubectl "$@" -n devops; }
# Using the function
$ kd view-secret deployer-token-8d28z
Multiple sub keys found. Specify another argument, one of:
-> ca.crt
-> namespace
-> service-ca.crt
-> token |
Edit:
The root cause of this issue has nothing to do with strace; it is because calling a kubectl plugin with options before the plugin name causes kubectl to not know how to find the plugin.
What happened:
kubectl plugin list
shows that I have some plugins installed:But calling them does not work:
However, calling them under strace works somehow:
What you expected to happen: Plugins listed in
kubectl plugin list
should be called without having to wrap the command withstrace
.How to reproduce it (as minimally and precisely as possible):
$PATH
kubectl plugin list
shows the pluginkubectl <plugin>
and it returns an errorstrace <args> kubectl <plugin>
and it worksAnything else we need to know?:
Environment:
kubectl version
):cat /etc/os-release
):The text was updated successfully, but these errors were encountered: