kubie icon indicating copy to clipboard operation
kubie copied to clipboard

Use XDG base dir spec for config file

Open triarius opened this issue 1 year ago • 2 comments

The XDG base directory specification is a popular way to store config files that doesn't clutter a user's home directory with dotfiles.

This tool stores its configuration in ~/.kube/kubie.yaml, however, I think it should follow the spec and store it in a location that is not shared by other tools.

Fortunately, the dirs crate has native support for the XDG base directory spec, so we can use it to handle resolving the environment variables and falling back to the defaults in the spec.

What this means is that the new default location for this tool's settings from this PR onwards is ~/.config/kubie/config.yaml. If the old config file exists, it will prefer that. Otherwise, it will create the parent directories for the XDG based config file.

triarius avatar Jul 30 '23 00:07 triarius

I knew about the XDG spec when I made the decision to put the config file there. I put it there to match what kubectl does. If recent versions of kubectl have started supporting the XDG spec, then maybe this change makes sense. But has kubectl changed where it stores the config?

A lot of tools like gcloud and k3d write the clusters' config files in ~/.kube/config by default too.

sbstp avatar Aug 06 '23 01:08 sbstp

I guess there are two opinions I have:

  1. Tools should follow the XDG Spec
  2. Tools should store their config in their own directories

Let's ignore 1. for the present.

A lot of tools like gcloud and k3d write the clusters' config files in ~/.kube/config by default too.

That's fine. These tools are generating config for kubectl to use. Kubie's job is to choose between these configs, but Kubie has its own config, the ~/.kube/kubie.yaml.

Apart from this file, the config files in ~/.kube are not config for Kubie, but data that Kubie operates on. So I think it makes sense to separate them. I don't think Kubie should mix its own config with the cluster config used by kubectl. I would store it in a different directory, as the file, ~/.kubie/config.yaml.

Now if you add 1. to this position, you get:

Kubie should store its config in the directory $XDG_CONFIG_HOME/kubie/, which is what this PR does.

I don't think it follows from the fact that other tools in the Kubernetes ecosystem don't follow the XDG spec for their config, can Kubie must not either. I currently use AWS EKS, and through the setting of some environment variables for aws and kubectl, I've manage to eliminate the .kube directory from my homedir entirely, except for when I use Kubie. With the patch in this PR, however, Kubie plays nice with this setup too.

LMK what you think, I would like to get Kubie to work with this setup, open to hearing other ideas on how to do so too.

triarius avatar Aug 06 '23 02:08 triarius