Skip to content

fix(cyctl): add explicit completion command to prevent kubeconfig panic#892

Open
cschanhniem wants to merge 1 commit into
cyclops-ui:mainfrom
cschanhniem:fix/cyctl-completion-panic
Open

fix(cyctl): add explicit completion command to prevent kubeconfig panic#892
cschanhniem wants to merge 1 commit into
cyclops-ui:mainfrom
cschanhniem:fix/cyctl-completion-panic

Conversation

@cschanhniem

Copy link
Copy Markdown

Description

cyctl completion bash (and zsh/fish/powershell) currently panics because the root command's PersistentPreRun hook calls kubeconfig.GetKubeConfig() for every subcommand. When no Kubernetes cluster is available or no kubeconfig is set, the clientcmd.BuildConfigFromFlags call panics.

Fix

Added an explicit completion command — modeled after standard Cobra convention — that overrides the root's PersistentPreRun with an empty no-op function. This prevents kubeconfig loading during completion generation.

The command is registered in an init() function via RootCmd.AddCommand(completionCmd), which shadows Cobra's built-in completion.

Testing

  • cyctl completion bash now outputs the bash completion script without errors
  • cyctl completion zsh / fish / powershell also work
  • All other commands retain their existing PersistentPreRun behavior

Fixes #880

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
@cschanhniem cschanhniem requested a review from a team as a code owner June 19, 2026 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cyctl completion fails

1 participant