Skip to content

Commit 5cfcb8f

Browse files
committed
Fix error when KUBECONFIG has empty entries
Fixes #4100 Signed-off-by: Carlos Sanchez <[email protected]>
1 parent 1842311 commit 5cfcb8f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

cmd/util/util.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,12 @@ func GetKubeConfigPath() string {
100100
if kubeConfigEnv == "" {
101101
return constants.KubeconfigPath
102102
}
103-
return filepath.SplitList(kubeConfigEnv)[0]
103+
kubeConfigFiles := filepath.SplitList(kubeConfigEnv)
104+
for _, kubeConfigFile := range kubeConfigFiles {
105+
if kubeConfigFile != "" {
106+
return kubeConfigFile
107+
}
108+
glog.Infof("Ignoring empty entry in %s env var", constants.KubeconfigEnvVar)
109+
}
110+
return constants.KubeconfigPath
104111
}

cmd/util/util_test.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,19 @@ func TestGetKubeConfigPath(t *testing.T) {
3636
input: "/home/fake/.kube/.kubeconfig:/home/fake2/.kubeconfig",
3737
want: "/home/fake/.kube/.kubeconfig",
3838
},
39+
{
40+
input: ":/home/fake/.kube/.kubeconfig:/home/fake2/.kubeconfig",
41+
want: "/home/fake/.kube/.kubeconfig",
42+
},
43+
{
44+
input: ":",
45+
want: "$HOME/.kube/config",
46+
},
3947
}
4048

4149
for _, test := range tests {
4250
os.Setenv(clientcmd.RecommendedConfigPathEnvVar, test.input)
43-
if result := GetKubeConfigPath(); result != test.want {
51+
if result := GetKubeConfigPath(); result != os.ExpandEnv(test.want) {
4452
t.Errorf("Expected first splitted chunk, got: %s", result)
4553
}
4654
}

0 commit comments

Comments
 (0)