Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Documentation for kubeconfig write doesn't match actual behaviour #1467

Open
Cavaler opened this issue Jul 10, 2024 · 2 comments
Open
Labels
bug Something isn't working docs Documentation
Milestone

Comments

@Cavaler
Copy link

Cavaler commented Jul 10, 2024

Documentation for kubeconfig write says: this will create (or update) the file $HOME/.k3d/kubeconfig-mycluster.yaml

This is actually not true. Judging by the code it is created either in the directory returned by GetConfigDirOrCreate() which uses $XDG_CONFIG_HOME or defaults to ~/.config/k3d.

There are also some other (obsolete?) mentions of ~/.k3d in the code comments as well.

What did you do

k3d kubeconfig merge edge-local

What did you expect to happen

/home/pavel/.k3d/kubeconfig-edge-local.yaml

Screenshots or terminal output

/home/pavel/.config/kubeconfig-edge-local.yaml

Which OS & Architecture

Ubuntu 20.04 amd64

Which version of k3d

v5.6.3

@Cavaler Cavaler added the bug Something isn't working label Jul 10, 2024
@iwilltry42 iwilltry42 added the docs Documentation label Jul 10, 2024
@iwilltry42 iwilltry42 added this to the v5.8.0 milestone Jul 10, 2024
@totallyGreg
Copy link

More importantly, if XDG_CONFIG_HOME is set it uses that directory without appending a k3d

☸ k3d-uds in ~/.config/zsh
 [17:01] ❯ k3d kubeconfig write uds
/Users/totally/.config/kubeconfig-uds.yaml

☸ k3d-uds in ~/.config/zsh
 [17:01] ❯ echo $XDG_CONFIG_HOME
/Users/totally/.config

☸ k3d-uds in ~/.config/zsh
 [17:02] ❯ unset XDG_CONFIG_HOME

☸ k3d-uds in ~/.config/zsh
 [17:05] ❯ k3d kubeconfig write uds
/Users/totally/.config/k3d/kubeconfig-uds.yaml

@totallyGreg
Copy link

In the function GetConfigDirOrCreate

k3d/pkg/util/files.go

Lines 39 to 58 in 4709d6a

// GetConfigDirOrCreate will return the base path of the k3d config directory or create it if it doesn't exist yet
// k3d's config directory will be $XDG_CONFIG_HOME (Unix)
func GetConfigDirOrCreate() (string, error) {
configDir := os.Getenv("XDG_CONFIG_HOME")
if len(configDir) == 0 {
// build the path
homeDir, err := homedir.Dir()
if err != nil {
return "", fmt.Errorf("failed to get user's home directory: %w", err)
}
configDir = path.Join(homeDir, types.DefaultConfigDirName)
}
// create directories if necessary
if err := createDirIfNotExists(configDir); err != nil {
return "", fmt.Errorf("failed to create config directory '%s': %w", configDir, err)
}
return configDir, nil
}

  • configDir returns $XDG_CONFIG_HOME if it exists (for me that is ~/.config)
  • and returns ~/.config/k3d if it doesn't since it appends DefaultConfigDirName to the home directory
  • DefaultConfigDirName is misdefined (IMHO it should just be k3d) as a partial path instead of a directory name here:
    // DefaultConfigDirName defines the name of the config directory (where we'll e.g. put the kubeconfigs)
    const DefaultConfigDirName = ".config/k3d" // should end up in $XDG_CONFIG_HOME
    (.config/k3d)

The end result is that if $XDG_CONFIG_HOME is defined, k3d will use the entire directory as it's dumping ground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docs Documentation
Projects
None yet
Development

No branches or pull requests

3 participants