Support KUBECONFIG environment variable.

If KUBECONFIG environment variable is set, use it. Otherwise default to ~/.kube/config
This commit is contained in:
Sudhir Kasanavesi 2021-07-14 17:42:46 -07:00 committed by GitHub
parent 6e279bfca5
commit cef0e01cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,6 +10,7 @@ import (
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir" "k8s.io/client-go/util/homedir"
"path/filepath" "path/filepath"
"os"
) )
func NewFromInCluster(errOut chan error) (*Resolver, error) { func NewFromInCluster(errOut chan error) (*Resolver, error) {
@ -26,8 +27,13 @@ func NewFromInCluster(errOut chan error) (*Resolver, error) {
func NewFromOutOfCluster(kubeConfigPath string, errOut chan error) (*Resolver, error) { func NewFromOutOfCluster(kubeConfigPath string, errOut chan error) (*Resolver, error) {
if kubeConfigPath == "" { if kubeConfigPath == "" {
home := homedir.HomeDir() env := os.Getenv("KUBECONFIG")
kubeConfigPath = filepath.Join(home, ".kube", "config") if env != "" {
kubeConfigPath = env
} else {
home := homedir.HomeDir()
kubeConfigPath = filepath.Join(home, ".kube", "config")
}
} }
configPathList := filepath.SplitList(kubeConfigPath) configPathList := filepath.SplitList(kubeConfigPath)