diff --git a/cmd/util/util.go b/cmd/util/util.go index ca103bfca12e..26f9c4c186c1 100644 --- a/cmd/util/util.go +++ b/cmd/util/util.go @@ -100,5 +100,12 @@ func GetKubeConfigPath() string { if kubeConfigEnv == "" { return constants.KubeconfigPath } - return filepath.SplitList(kubeConfigEnv)[0] + kubeConfigFiles := filepath.SplitList(kubeConfigEnv) + for _, kubeConfigFile := range kubeConfigFiles { + if kubeConfigFile != "" { + return kubeConfigFile + } + glog.Infof("Ignoring empty entry in %s env var", constants.KubeconfigEnvVar) + } + return constants.KubeconfigPath } diff --git a/cmd/util/util_test.go b/cmd/util/util_test.go index 315762078b02..7e1765cb2b16 100644 --- a/cmd/util/util_test.go +++ b/cmd/util/util_test.go @@ -36,11 +36,19 @@ func TestGetKubeConfigPath(t *testing.T) { input: "/home/fake/.kube/.kubeconfig:/home/fake2/.kubeconfig", want: "/home/fake/.kube/.kubeconfig", }, + { + input: ":/home/fake/.kube/.kubeconfig:/home/fake2/.kubeconfig", + want: "/home/fake/.kube/.kubeconfig", + }, + { + input: ":", + want: "$HOME/.kube/config", + }, } for _, test := range tests { os.Setenv(clientcmd.RecommendedConfigPathEnvVar, test.input) - if result := GetKubeConfigPath(); result != test.want { + if result := GetKubeConfigPath(); result != os.ExpandEnv(test.want) { t.Errorf("Expected first splitted chunk, got: %s", result) } }