Skip to content

Commit d8626e7

Browse files
committed
feat: handle path list for KUBECONFIG env var
1 parent 966bcb3 commit d8626e7

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

klient/conf/config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"os/user"
2525
"path"
26+
"path/filepath"
2627

2728
"k8s.io/client-go/rest"
2829
"k8s.io/client-go/tools/clientcmd"
@@ -97,7 +98,15 @@ func ResolveKubeConfigFile() string {
9798
// if KUBECONFIG env is defined then use that
9899
kubeConfigPath = os.Getenv(clientcmd.RecommendedConfigPathEnvVar)
99100
if kubeConfigPath != "" {
100-
return kubeConfigPath
101+
// handle the variable as a path list, similar to client-go.
102+
filePaths := filepath.SplitList(kubeConfigPath)
103+
for _, filename := range filePaths {
104+
if _, err := os.Stat(filename); err == nil {
105+
return filename
106+
}
107+
}
108+
// return the first path if none the paths existed.
109+
return filePaths[0]
101110
}
102111

103112
var (

0 commit comments

Comments
 (0)