Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/scripts/addons-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ main() {
}

export HELMVM_METRICS_BASEURL="https://staging.replicated.app"
export KUBECONFIG=/root/.helmvm/etc/kubeconfig
export PATH="$PATH:/root/.helmvm/bin"
export KUBECONFIG=/root/.config/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.config/.helmvm/bin
main
4 changes: 2 additions & 2 deletions e2e/scripts/embed-and-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ main() {
}

export HELMVM_METRICS_BASEURL="https://staging.replicated.app"
export KUBECONFIG=/root/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.helmvm/bin
export KUBECONFIG=/root/.config/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.config/.helmvm/bin
main
4 changes: 2 additions & 2 deletions e2e/scripts/embedded-preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ main() {
}

export HELMVM_METRICS_BASEURL="https://staging.replicated.app"
export KUBECONFIG=/root/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.helmvm/bin
export KUBECONFIG=/root/.config/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.config/.helmvm/bin
main
4 changes: 2 additions & 2 deletions e2e/scripts/install-with-disabled-addons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ main() {
}

export HELMVM_METRICS_BASEURL="https://staging.replicated.app"
export KUBECONFIG=/root/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.helmvm/bin
export KUBECONFIG=/root/.config/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.config/.helmvm/bin
main
4 changes: 2 additions & 2 deletions e2e/scripts/multi-node-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ main() {
}

export HELMVM_METRICS_BASEURL="https://staging.replicated.app"
export KUBECONFIG=/root/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.helmvm/bin
export KUBECONFIG=/root/.config/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.config/.helmvm/bin
main
4 changes: 2 additions & 2 deletions e2e/scripts/single-node-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ main() {
}

export HELMVM_METRICS_BASEURL="https://staging.replicated.app"
export KUBECONFIG=/root/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.helmvm/bin
export KUBECONFIG=/root/.config/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.config/.helmvm/bin
main
4 changes: 2 additions & 2 deletions e2e/scripts/wait-for-ready-nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ main() {
}

export HELMVM_METRICS_BASEURL="https://staging.replicated.app"
export KUBECONFIG=/root/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.helmvm/bin
export KUBECONFIG=/root/.config/.helmvm/etc/kubeconfig
export PATH=$PATH:/root/.config/.helmvm/bin
main "$@"
47 changes: 44 additions & 3 deletions pkg/defaults/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,46 @@ func (d *DefaultsProvider) home() string {
return home
}

// config returns the user's config dir.
func (d *DefaultsProvider) config() string {
home, err := os.UserHomeDir()
if err != nil {
logrus.Fatalf("unable to get user home dir: %s", err)
}

// use the XDG_CONFIG_HOME environment variable if set
if xdgConfigHome := os.Getenv("XDG_CONFIG_HOME"); xdgConfigHome != "" {
return xdgConfigHome
}

// otherwise, default to $HOME/.config on linux
if runtime.GOOS == "linux" {
return filepath.Join(home, ".config")
}

return home
}

// state returns the user's state dir.
func (d *DefaultsProvider) state() string {
home, err := os.UserHomeDir()
if err != nil {
logrus.Fatalf("unable to get user home dir: %s", err)
}

// use the XDG_STATE_HOME environment variable if set
if xdgStateHome := os.Getenv("XDG_STATE_HOME"); xdgStateHome != "" {
return xdgStateHome
}

// otherwise, default to $HOME/.local/state on linux
if runtime.GOOS == "linux" {
return filepath.Join(home, ".local", "state")
}

return home
}

// BinaryName returns the binary name, this is useful for places where we
// need to present the name of the binary to the user (the name may vary if
// the binary is renamed). We make sure the name does not contain invalid
Expand All @@ -77,7 +117,7 @@ func (d *DefaultsProvider) BinaryName() string {
// stored. This is a subdirectory of the user's home directory.
func (d *DefaultsProvider) HelmVMLogsSubDir() string {
hidden := fmt.Sprintf(".%s", d.BinaryName())
return filepath.Join(d.Base, d.home(), hidden, "logs")
return filepath.Join(d.Base, d.state(), hidden, "logs")
}

// PathToLog returns the full path to a log file. This function does not check
Expand All @@ -100,7 +140,7 @@ func (d *DefaultsProvider) K0sctlBinsSubDir() string {
// are stored. This is a subdirectory of the user's home directory.
func (d *DefaultsProvider) HelmVMBinsSubDir() string {
hidden := fmt.Sprintf(".%s", d.BinaryName())
return filepath.Join(d.Base, d.home(), hidden, "bin")
return filepath.Join(d.Base, d.config(), hidden, "bin")
}

// K0sctlApplyLogPath returns the path to the k0sctl apply log file.
Expand All @@ -126,9 +166,10 @@ func (d *DefaultsProvider) SSHConfigSubDir() string {

// ConfigSubDir returns the path to the directory where k0sctl configuration
// files are stored. This is a subdirectory of the user's home directory.
// TODO update
func (d *DefaultsProvider) ConfigSubDir() string {
hidden := fmt.Sprintf(".%s", d.BinaryName())
return filepath.Join(d.Base, d.home(), hidden, "etc")
return filepath.Join(d.Base, d.config(), hidden, "etc")
}

// K0sBinaryPath returns the path to the k0s binary.
Expand Down