Skip to content

Commit

Permalink
Fix error when KUBECONFIG has empty entries (#4100)
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Sanchez <[email protected]>
  • Loading branch information
carlossg committed Aug 14, 2019
1 parent 25e057c commit 58de23f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/minikube/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion pkg/minikube/kubeconfig/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 58de23f

Please sign in to comment.