Merge pull request #114 from ksudhir007/fix-kubeconfig

Support KUBECONFIG environment variable.
This commit is contained in:
Igor Gov 2021-07-15 18:09:40 +03:00 committed by GitHub
commit 765feafbcc
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)