You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, I am grateful for kubectx, it makes things easier for us.
When I switch contexts using kubectx, the YAML file's indentation changes, extra spaces are added. This doesn't happen with the command kubectl config use-context k8sxxx1.
NOTE: I use the configuration with the KUBECONFIG variable in .zprofile file.
This is related to issue #499, which is still open. The root cause is in the Save() function in internal/kubeconfig/kubeconfig.go — it calls enc.SetIndent(0) on the YAML encoder [1]. An AI-generated analysis posted in that issue suggests that SetIndent(0) in the underlying go.yaml.in/yaml/v3 library falls back to a default of 4 spaces rather than preserving the original formatting, which produces the wider indentation you're seeing [2]. Note that the maintainer @ahmetb flagged that analysis as unverified and has not been able to reproduce the problem himself.
As of v0.11.0 and the current main branch, Save() still hardcodes enc.SetIndent(0)[3], so no fix has been merged yet. A proposed fix (SetIndent(2)) exists on an experimental branch but has not landed in any release [2].
For some users in #499, this same file-rewriting behavior had a more serious side effect: background tools watching ~/.kube/config (Docker Desktop, cloud CLI auth helpers, etc.) would detect the reformatted file and overwrite it, silently reverting the context/namespace switch [4]. If you're only seeing the indentation change and your context switches still work, you're not affected by that secondary problem — but it's worth being aware of if you use any kubeconfig-syncing tools.
As a workaround in the meantime, you can fall back to kubectl config use-context <name>, which preserves the original file formatting.
Activity
dosubot commentedon Aug 31, 2026
Hi @victorcisternas! I'm Dosu and I'm helping the ahmetb's Org team.
This is related to issue #499, which is still open. The root cause is in the
Save()function ininternal/kubeconfig/kubeconfig.go— it callsenc.SetIndent(0)on the YAML encoder [1]. An AI-generated analysis posted in that issue suggests thatSetIndent(0)in the underlyinggo.yaml.in/yaml/v3library falls back to a default of 4 spaces rather than preserving the original formatting, which produces the wider indentation you're seeing [2]. Note that the maintainer @ahmetb flagged that analysis as unverified and has not been able to reproduce the problem himself.As of v0.11.0 and the current
mainbranch,Save()still hardcodesenc.SetIndent(0)[3], so no fix has been merged yet. A proposed fix (SetIndent(2)) exists on an experimental branch but has not landed in any release [2].For some users in #499, this same file-rewriting behavior had a more serious side effect: background tools watching
~/.kube/config(Docker Desktop, cloud CLI auth helpers, etc.) would detect the reformatted file and overwrite it, silently reverting the context/namespace switch [4]. If you're only seeing the indentation change and your context switches still work, you're not affected by that secondary problem — but it's worth being aware of if you use any kubeconfig-syncing tools.As a workaround in the meantime, you can fall back to
kubectl config use-context <name>, which preserves the original file formatting.To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
an-tex commentedon Sep 16, 2026
yep same issue here