kubectl
kubectl copied to clipboard
kubectl without arguments should print all aliases defined in kuberc file
What would you like to be added:
I'd like KUBECTL_KUBERC=true kubectl to print aliases similarly to how it prints the plugins, see below:
Subcommands provided by plugins:
convert The command convert is a plugin installed by the user
krew The command krew is a plugin installed by the user
Why is this needed: This will be a nice addition, and should help with debugging problems with kuberc file.
This was brought up in https://github.com/kubernetes/kubernetes/pull/125230/files#r1665566996
I think, that would be a nice feature. But as far as I understand, cobra does not support printing aliases of the commands.
For example, I define an alias to kubectl get in the code. After that if I run kubectl, I can see the get command in the list of commands but alias of the get won't be printed.
I think, we can't support this.
I believe we're controlling the output and the format of what you're getting when running just kubectl. It's defined in https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/util/templates/templater.go so we should be able to expand it to also include the alias section, most likely 😉
Thank you for the pointer. In order to not overload the kubectl in the cases where there are many aliases, kuberc only loads the alias that is passed as args and ignores the others. So that when user types kubectl, aliases will not be loaded and return https://github.com/kubernetes/kubernetes/blob/7cb2bd78b22c4ac8d9a401920fbcf7e2b240522d/staging/src/k8s.io/kubectl/pkg/kuberc/kuberc.go#L236-L240.
Maybe we can add an exception for this (i.e. kubectl -- without any commands) to load all aliases to print on the terminal. That would be a very nice to have in the long term.
/priority backlog
/triage accepted
Maybe we can add an exception for this (i.e.
kubectl-- without any commands) to load all aliases to print on the terminal. That would be a very nice to have in the long term.
I'm open to whatever will make the user's life easier 😅
Hi @ardaguclu @soltysh
I'd like to work on this issue. Based on the discussion, here's my understanding of the implementation:
-
Add an exception to the kuberc loading logic so that when
kubectlis run without any commands (i.e., justkubectlorKUBECTL_KUBERC=true kubectl), all aliases defined in the kuberc file will be loaded. -
Modify the output formatting in the
templater.goto display these aliases in a format similar to how plugins are displayed:
If there is nothing particularly problematic, I would like to proceed with the work. If there is anything I misunderstood, please give me feedback.
I'd like to work on this issue. Based on the discussion, here's my understanding of the implementation:
1. Add an exception to the kuberc loading logic so that when `kubectl` is run without any commands (i.e., just `kubectl` or `KUBECTL_KUBERC=true kubectl`), all aliases defined in the kuberc file will be loaded.
No need to check for KUBECTL_KUBERC=true that's being handled outside the code which adds the preferences. For now when we find that there are no arguments passed to kubectl we just skip adding the aliases, rather than just adding them normally.
2. Modify the output formatting in the `templater.go` to display these aliases in a format similar to how plugins are displayed:
Once you address no. 1, that'd be the next step.
If there is nothing particularly problematic, I would like to proceed with the work. If there is anything I misunderstood, please give me feedback.
Go for it, and feel free to ping me on slack once you have a PR for review.
@Antraxmin you still working on this?
If not I can take a crack at it!
Hi @soltysh @ardaguclu,
I'd like to work on this issue if it's still available.
Creating the PR for review. Thanks!
/assign