Skip to content

Commit

Permalink
Honour Local path flag while saving kube configs (#416)
Browse files Browse the repository at this point in the history
* Honour Local path flag while saving kube configs

* modify defaultKubeConfigPath
  • Loading branch information
uzaxirr authored May 9, 2024
1 parent 5185798 commit 5df4eab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions cmd/kubernetes/kubernetes_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kubernetes
import (
"fmt"
"os"
"runtime"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
Expand All @@ -26,7 +27,7 @@ Notes:
`

var saveConfig, switchConfig, overwriteConfig bool
var localPathConfig string
var localPathConfig, defaultKubeConfigPath string

var kubernetesConfigCmd = &cobra.Command{
Use: "config",
Expand Down Expand Up @@ -65,8 +66,18 @@ If you wish to use a custom format, the available fields are:
os.Exit(1)
}

if os.Getenv("KUBECONFIG") != "" {
localPathConfig = os.Getenv("KUBECONFIG")
if runtime.GOOS == "windows" {
defaultKubeConfigPath = os.Getenv("USERPROFILE") + "\\.kube\\config"
} else {
defaultKubeConfigPath = os.Getenv("HOME") + "/.kube/config"
}

if localPathConfig == "" { // Check if -p or --local-path argument was not provided
if os.Getenv("KUBECONFIG") != "" {
localPathConfig = os.Getenv("KUBECONFIG")
} else {
localPathConfig = defaultKubeConfigPath
}
}

if saveConfig {
Expand Down
2 changes: 1 addition & 1 deletion utility/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func checkAppPlan(appList []civogo.KubernetesMarketplaceApplication, requested s
return requested, nil
}

// RequestedSplit is a function to split all app requested to be install
// RequestedSplit is a function to split all app requested to be installed
func RequestedSplit(appList []civogo.KubernetesMarketplaceApplication, requested string) string {
allsplit := strings.Split(requested, ",")
allApp := []string{}
Expand Down

0 comments on commit 5df4eab

Please sign in to comment.