Merge pull request #5056 from carlossg/issue-4100
Improve handling KUBECONFIG environment variable with invalid entriespull/5082/head
commit
a1fa6bc7b4
|
@ -87,7 +87,14 @@ func PathFromEnv() 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
|
||||
}
|
||||
|
||||
// extractIP returns the IP address stored for minikube in the kubeconfig specified
|
||||
|
|
|
@ -555,11 +555,23 @@ 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",
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
want: "$HOME/.kube/config",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
os.Setenv(clientcmd.RecommendedConfigPathEnvVar, test.input)
|
||||
if result := PathFromEnv(); result != test.want {
|
||||
if result := PathFromEnv(); result != os.ExpandEnv(test.want) {
|
||||
t.Errorf("Expected first splitted chunk, got: %s", result)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue