fix(cyctl): add explicit completion command to prevent kubeconfig panic#892
Open
cschanhniem wants to merge 1 commit into
Open
fix(cyctl): add explicit completion command to prevent kubeconfig panic#892cschanhniem wants to merge 1 commit into
cschanhniem wants to merge 1 commit into
Conversation
The root command's PersistentPreRun loads kubeconfig for every subcommand, causing 'cyctl completion bash' (and other shells) to panic when no kubeconfig is available or when the cluster is unreachable. Adding an explicit completion command with an empty PersistentPreRun overrides the root's hook so that completion generation runs without attempting any Kubernetes connection. Fixes cyclops-ui#880
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
cyctl completion bash(and zsh/fish/powershell) currently panics because the root command'sPersistentPreRunhook callskubeconfig.GetKubeConfig()for every subcommand. When no Kubernetes cluster is available or no kubeconfig is set, theclientcmd.BuildConfigFromFlagscall panics.Fix
Added an explicit
completioncommand — modeled after standard Cobra convention — that overrides the root'sPersistentPreRunwith an empty no-op function. This prevents kubeconfig loading during completion generation.The command is registered in an
init()function viaRootCmd.AddCommand(completionCmd), which shadows Cobra's built-in completion.Testing
cyctl completion bashnow outputs the bash completion script without errorscyctl completion zsh/fish/powershellalso workFixes #880