Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling KUBECONFIG environment variable with invalid entries #5056

Merged
merged 1 commit into from
Aug 14, 2019
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
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