Skip to content

Switch context with every file listed in $KUBECONFIG - #6

Merged
pierreneter merged 1 commit into
p10node:mainfrom
junior:kubeconfig-list
Oct 7, 2026
Merged

pierreneter merged 1 commit into
p10node:mainfrom
junior:kubeconfig-list

Conversation

@junior

@junior junior commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

With KUBECONFIG listing several files, which kubectl merges (one file per cluster is a common layout), k10s connects to the current context, but switching to another one with :ctx fails:

load kubeconfig: stat /home/me/.kube/a.yaml:/home/me/.kube/b.yaml: no such file or directory

The first connection goes through NewStore("", ctx), so client-go applies its own loading rules and merges the list. Store.SwitchContext rebuilt the store from Client.ConfigPath instead. That field holds the whole KUBECONFIG value on purpose, for plugins (TestLoadedKubeconfigPathPreservesMergedKubeconfigList), and client-go took it as the one explicit file to load.

The client now remembers the path it was asked to load ("" for kubectl's rules), and SwitchContext loads the same way. ConfigPath is unchanged, so plugins still get the full list.

TestSwitchContextWithKubeconfigList writes two kubeconfig files with one context each, connects through the merged list and switches to the context that lives in the second file. On main it fails with the error above.

Checked with gofmt, go vet ./... and go test ./... on Go 1.26.8, and a build for each release platform.

With $KUBECONFIG listing several files, k10s connected to the current
context, but switching to another one failed with

  load kubeconfig: stat a.yaml:b.yaml: no such file or directory

The first connection passes no path, so client-go applies kubectl's
loading rules and merges the list. SwitchContext rebuilt the store
from Client.ConfigPath instead, which holds the whole list for
plugins, and client-go took it as the one explicit file to load.

The client now remembers the path it was asked to load ("" for
kubectl's rules), and a context switch loads the same way. ConfigPath
is unchanged, so plugins still get the full list in $KUBECONFIG.
@pierreneter

Copy link
Copy Markdown
Member

Reviewed, approving.

Verified locally on Go 1.27.1: gofmt, go vet ./... and go test ./... pass, and the binary builds for all five release targets. I also ran TestSwitchContextWithKubeconfigList against main's client.go/store.go to confirm it reproduces the stat a.yaml:b.yaml error before the fix.

The diagnosis is right: New("", ctx) lets client-go merge the $KUBECONFIG list, while SwitchContext fed ConfigPath back in as ExplicitPath, which client-go treats as one file. Keeping the original load path on the client and leaving ConfigPath as the plugin-facing list is the correct split, and dropping Store.kubeconfigPath removes the one place the two got confused.

Merging. Thanks for the regression test.

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.

2 participants