Open wilsonehusin opened 3 years ago
This sounds interesting, how do you propose to implement it?
I think we will have some interesting portability concerns xref: https://github.com/kubernetes-sigs/kind/issues/2038 depending on how it is implemented
What I had in mind was using ValidArgsFunction
in cobra, where it executes docker image ls
or HTTP call to Docker server. However, in context of image-agnostic interface, it might be difficult unless user specifies the prefix with docker://
or podman://
.
I suppose if the scope is limited to Docker and Podman, we should be able to achieve this from executing the binary since Podman CLI aims to be backwards-compatible with Docker to a point of alias docker=podman
, right?
in the #2038 case we aim to support having both installed, because you may e.g. need to build kubernetes images with buildx
but prefer to use podman when you have the choice.
since Podman CLI aims to be backwards-compatible with Docker to a point of alias docker=podman, right?
I don't think they're making this claim as strongly anymore. Within kind we've found that this is ... not the case once you're doing interesting things. We have explicit codepaths for both and they're not identical.
I see, if the case is to support both, then I think this is something we can iterate on -- add support for one, then the other and append the results?
I have yet to try loading image from podman so maybe I'm rambling nonsense, but if I submit a PR for supporting autocompletion on docker images now while we explore the podman route, would that be acceptable? Or would you prefer to wait until we find a common ground / universal approach for both?
I guess it should be done on SHELL side, so create appropriate completion
in bash/zsh ?
I see, if the case is to support both, then I think this is something we can iterate on -- add support for one, then the other and append the results?
well we also have completion for other shells atm.
I have yet to try loading image from podman so maybe I'm rambling nonsense, but if I submit a PR for supporting autocompletion on docker images now while we explore the podman route, would that be acceptable? Or would you prefer to wait until we find a common ground / universal approach for both?
that seems reasonable, also it will probably be a different command.
https://github.com/kubernetes/kubernetes/pull/96087 might give an idea for this.
cobra just overhauled completion significantly and we will need to update our existing support to handle this, I think kubernetes will also have some issues upgrading but will probably just disable the support from cobra.
cobra just overhauled completion significantly and we will need to update our existing support to handle this, I think kubernetes will also have some issues upgrading but will probably just disable the support from cobra.
If I may chime in, Cobra's completion changes should be fully backwards-compatible, and I believe an upgrade should be transparent.
If you have your own completions written in bash, you would need to write them in Go for them to work with different shells, but I don't believe you do.
Are there specific issues you are referring to @BenTheElder ?
IIRC there was some custom work for ZSH but I have not had time to look at this. It would be great if someone wanted to 😅
IIRC there was some custom work for ZSH but I have not had time to look at this. It would be great if someone wanted to 😅
I've checked how completion was done for kind and you are all good. Specifically, kind uses Cobra's native zsh completion and does not use the bash-to-zsh conversion that kubectl was using up until kubernetes/kubernetes#96087, as can be seen here: https://github.com/kubernetes-sigs/kind/blob/c7f1d202a1408691d6ab1fb8e3112e11832ce500/pkg/cmd/kind/completion/zsh/zsh.go#L34
So, I am confident you can upgrade to Cobra 1.2.1 completely transparently.
Also, using ValidArgsFunction
as mentioned by @wilsonehusin to add custom completion logic would work nicely and would automatically work for all shells (bash, zsh, fish). As a side-note, be aware @wilsonehusin that when adding custom completions, you can also include descriptions for them if you are so inclined (https://github.com/spf13/cobra/blob/master/shell_completions.md#descriptions-for-completions).
Beyond adding custom completions, there are two other improvements you may be interested in making: 1- adding support for powershell completions, as provided by Cobra (https://github.com/spf13/cobra/blob/master/shell_completions.md#powershell-completions) 2- using Cobra's new bash completion V2 logic which supports descriptions like the other shells already support (https://github.com/spf13/cobra/blob/master/shell_completions.md#bash-completion-v2)
What would you like to be added:
Would be nice if I can get shell auto-completion from
kind load docker-image [TAB][TAB]
with the list of available images on my machine. Roughly the options can be retrieved by:or without the
<none>
images being included:Why is this needed:
As part of my development iteration, I need to repetitively load docker images. This would make my development iteration easier :smile:
Other notes:
Happy to contribute this if maintainers would not mind reviewing the code!