Skip to content

kubectx change indent of yaml file (osx arm) #511

Open

Description

@victorcisternas

Hi,

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.

Simple example:

Original ident of file:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: xxxxxxx
    server: https://xxx.xxx.xxx.xxx:6443
  name: k8sxxx1
- cluster:
    certificate-authority-data: xxxxxxx
    server: https://xxx.xxx.xxx.xxx:6443
  name: k8sxxx2
....

Command: kubectx k8sxxx1

apiVersion: v1
clusters:
  - cluster:
        certificate-authority-data: xxxxxxx
        server: https://xxx.xxx.xxx.xxx:6443
    name: k8sxxx1
  - cluster:
        certificate-authority-data: xxxxxxx
        server: https://xxx.xxx.xxx.xxx:6443
    name: k8sxxx2
....

OSX

ProductName:		macOS
ProductVersion:		26.5.2
BuildVersion:		25F84
Darwin 172-16-49-17.lan.uchile.cl 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun  9 22:28:24 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6020 arm64

kubectx installed with brew:

kubectx ✔ 0.11.0 (15 files, 50.7MB) [Linked]

I used with the console: iTerm2 or Terminal

Activity

  1. dosubot commented on Aug 31, 2026

    @dosubot

    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 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.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about kubectx with Dosu Add Dosu to your team

  2. an-tex commented on Sep 16, 2026

    @an-tex

    yep same issue here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions