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
Implement kubectl custom command-line completions using go instead of bash #882
Comments
I was looking at this, and I think it will work fine. I'm going to make an attempt at this and submit a PR for review. /assign |
Yeah!
Actually, Cobra 1.0's support for zsh completion does not yet support dynamic completions in any form. It first needs spf13/cobra#1070 and then Cobra's native zsh completions will be ready. Until then, |
@marckhouzam thanks for the reminder... I think you mentioned this before in another issue but it slipped my mind for some reason, I’m not sure why. I think this issue is still probably something to be done, but timing wise, maybe It is best to hold off until spf13/cobra#1070 gets merged and we can upgrade to a version of cobra that supports dynamic completions for all... bash, zsh, and fish. I don’t want to halfway implement something or end up with multiple types of completion code for different shells. |
@brianpursley it's really up to you but to be clearer, if you switch to dynamic completion in Go, it will work for all three shells right away, even with the current zsh workaround (that is what helm has right now: using So, if you have the time, I think it would be worth starting to migrate to dynamic completions in Go gradually right away. That way, once spf13/cobra#1070 is available, |
/sig cli |
/kind feature |
@brianpursley Hi! now that spf13/cobra#1070 has been merged, are you still working on this issue? If not, I am willing to work on it. |
@knight42 I didn't realize it got merged. I am not working on it currently, so if you are willing, please go ahead. I'll be happy to help if you have any questions or review the PR when you are ready. |
@knight42 Here is a branch I was doing some work on originally, in case it helps or gives you some ideas. Feel free to use anything from it or not. It is a little old now, so some of it might not even be valid anymore |
@brianpursley wow that is helpful! really appreciate it! |
@knight42 you're welcome. Like I said, take it or leave it. Don't feel obligated to use it, but if it helps as a reference then great! 😄 |
/assign |
@knight42 This issue came up in today's SIG-CLI bug scrub meeting. @pwittrock mentioned that kustomize uses posener complete to do its completions and that it might be worth considering using it for kubectl. @eddiezane added it as a future topic for the next SIG-CLI meeting (next Wednesday). |
@brianpursley posener complete seems to be a good alternative, thanks for letting me know!
I am afraid I am unable to attend the meeting as the meeting time is at midnight in my TZ, but I will check the recording next day. |
I haven't looked in detail at https://github.com/posener/complete but out of curiosity, if you are to rewrite the (Disclaimer: I have a bias since I developed the Cobra solution and have moved the Helm project to use it) |
@marckhouzam Hi! I am rewriting |
@knight42 I think you are taking the best approach by changing things gradually. You can start by adding For example, you could add Now that I hope this helps. |
@knight42 I have an update for you. We discussed this topic in today's SIG-CLI meeting and agreed it makes sense to proceed with using Cobra 1.0.0 because we already have a dependency on cobra, other projects (like helm) are using it, and people already have completions set up this way in their .bashrc, .zshrc, etc. If you find that Cobra's completion is not able to let us eliminate all the hard-coded bash we have in kubectl and eliminate the zsh-specific workaround, then we can look at posener completion as an alternative option. |
@marckhouzam Really appreciate your detailed guidance, it is really helpful! @brianpursley Thanks for letting me know, I would file a PR with experimental changes ASAP so that we could discuss on it. |
So I see spf13/cobra#1070 got merged, but it doesn't look like it has been released yet. Because zsh completions have issues without spf13/cobra#1070, I think we are technically blocked on this until the next cobra release. |
@brianpursley As @maciaszczykm said in kubernetes/kubernetes#93714 (comment):
looks like we don't have to wait for the new release of cobra. |
I don't know about everyone else, but I would not be satisfied if we still had to have to have custom scripts to make zsh work. When I created this issue, I had hopes that this would simplify completions (by eliminate custom scripts) and make everything consistent while at the same time enabling fish and powershell completions. But it is clear now that it is not that simple. If cobra 1.0.0 can't fully support zsh, then I see two options:
|
I feel your pain. 😞 That being said, before using native zsh completion, we need to get rid of all existing custom bash scripts. Sadly until that is done, a new release of Cobra will not help (switching to native zsh completion before having moved all custom scripts to Go would cause a loss of functionality for kubectl zsh completion). I believe the first PR on that path is ready: kubernetes/kubernetes#93714 For helm, I've gotten rid of all custom bash scripts. That alone makes it easier to improve the completion logic and add extra features (for example, checking flags becomes really easy, so I was able to make some completions smarter). And it is a heck of a lot easier to maintain. But I am also anxiously waiting for the next Cobra release, as Helm is ready to switch to native zsh completion. Also, with the current Cobra 1.0.0 you can start using Fish completion right away. It won't have the custom completions, but it will have all other completions of commands and flags. Also, Cobra is about to get full PowerShell completion support, which will also get custom completions that have been migrated to Go. See spf13/cobra#1208.
Whichever solution is selected, the custom bash scripts must be replaced, so there is no getting away from doing that work. So I think continuing forward to get rid of all the custom scripts is a valuable step. What do you think? |
The Cobra maintainers have agreed that a release is needed. A few PRs will be included in the next few days (at least that is my understanding) and then the release will be made. |
Cobra 1.1.0 has just been released 😄 But we should not move to Cobra's zsh completion until we have removed all custom completion bash scripts from kubectl. |
@marckhouzam thanks for pushing that through with the cobra maintainers! I've opened a PR to update our dependency. |
PR kubernetes/kubernetes#96087 moves all bash custom completions to Go. As planned by @brianpursley, it will allow to move to native zsh completion and get rid of all the zsh script code. However, we need to move to Cobra 1.1.1 for that, which is done by kubernetes/kubernetes#95571 |
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. |
/remove-lifecycle stale |
/lifecycle active |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
/remove-lifecycle stale |
What would you like to be added:
Why is this needed:
The Cobra reference was recently upgraded to version 1.0.0 for the Kubernetes 1.19 release. This version of Cobra has a new, recommended way to specify dynamic completions using Go.
By implementing completions in Go (instead of bash), we can get rid of the custom bash code to handle completions which doesn't have tests, and we can also get rid of the zsh workaround code because Cobra 1.0.0 supports zsh completions now.
Making this change will also enable kubectl to support fish completion, which has been requested, as Cobra 1.0.0 supports fish completions.
Writing completions in go could also make it easier to optimize completions to handle large resource lists which have been found to be slow in some cases because we will have more control over how the requests are being performed internally.
The text was updated successfully, but these errors were encountered: