Skip to content

fix: support multiple paths in KUBECONFIG - #148

Merged
lucasMesquitaBorges merged 2 commits into
control-theory:mainfrom
kri5:k8s-multiple-kubeconfig-paths
Sep 4, 2026
Merged

lucasMesquitaBorges merged 2 commits into
control-theory:mainfrom
kri5:k8s-multiple-kubeconfig-paths

Conversation

@kri5

@kri5 kri5 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

KUBECONFIG may list several kubeconfig files to merge, but the whole value was used as a single path: clientcmd got it as ExplicitPath, and auto-detect ran os.Stat on the joined string, so Gonzo silently fell back to system logs.

Let client-go resolve the location instead of reimplementing it. BuildClientset now starts from NewDefaultClientConfigLoadingRules, which splits and merges KUBECONFIG and falls back to ~/.kube/config, and sets ExplicitPath only for --k8s-kubeconfig. As in kubectl, that flag stays a single file; merging is a KUBECONFIG feature. Auto-detect loads the merged config and checks that it holds at least one context.

Closes #147

KUBECONFIG may list several kubeconfig files to merge, but the whole value was
used as a single path: clientcmd got it as ExplicitPath, and auto-detect ran
os.Stat on the joined string, so Gonzo silently fell back to system logs.

Let client-go resolve the location instead of reimplementing it. BuildClientset
now starts from NewDefaultClientConfigLoadingRules, which splits and merges
KUBECONFIG and falls back to ~/.kube/config, and sets ExplicitPath only for
--k8s-kubeconfig. As in kubectl, that flag stays a single file; merging is a
KUBECONFIG feature. Auto-detect loads the merged config and checks that it
holds at least one context.

Closes control-theory#147
@rbg
rbg requested review from rbg and a lite review from Copilot September 4, 2026 15:16
@rbg rbg assigned kri5 Sep 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The core behavior change is correct and covered by a focused unit test, with only minor follow-up nits noted in review comments.

Pull request overview

Updates Gonzo’s Kubernetes kubeconfig handling to correctly support KUBECONFIG values containing multiple paths by delegating splitting/merging behavior to client-go’s standard loading rules, aligning behavior with kubectl.

Changes:

  • Switch kubeconfig resolution in BuildClientset to clientcmd.NewDefaultClientConfigLoadingRules() and only set ExplicitPath for --k8s-kubeconfig.
  • Update auto-detection to load the merged kubeconfig and require at least one context before enabling Kubernetes streaming.
  • Add unit tests for multi-path KUBECONFIG behavior and update docs/help text to describe the new default behavior.
File summaries
File Description
README.md Updates CLI flag documentation to reflect $KUBECONFIG-aware default kubeconfig behavior.
internal/k8s/config.go Uses client-go loading rules for kubeconfig detection and clientset construction (supports merged configs).
internal/k8s/config_test.go Adds coverage for DetectKubeconfig across single/multi-path and missing/empty config cases.
guides/KUBERNETES_USAGE.md Documents multi-path KUBECONFIG merging behavior and updates kubeconfig default text.
cmd/gonzo/app.go Updates log-source auto-detection to use merged kubeconfig detection instead of os.Stat on a single path string.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cmd/gonzo/app.go
Comment thread internal/k8s/config.go
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@rbg
rbg requested review from lucasMesquitaBorges and removed request for rbg September 4, 2026 17:43

@lucasMesquitaBorges lucasMesquitaBorges left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lucasMesquitaBorges
lucasMesquitaBorges merged commit d30c4db into control-theory:main Sep 4, 2026
4 checks passed
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.

Multiple paths in KUBECONFIG are not supported

4 participants