From 04dc3ed4313b332fd227af0b78ad85db22f644ce Mon Sep 17 00:00:00 2001 From: Sandip Bhattacharya Date: Fri, 27 May 2022 12:27:11 +0200 Subject: [PATCH] Use KUBECONFIG env variable if present --- pkg/kube/client.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index cc91a73a..98d8ae76 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -1,11 +1,12 @@ package kube import ( + "os" + "path/filepath" + "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "os" - "path/filepath" ) // GetKubernetesClient returns the client if its possible in cluster, otherwise tries to read HOME @@ -26,6 +27,9 @@ func GetKubernetesConfig() (*rest.Config, error) { return nil, err } - // TODO: Read KUBECONFIG env variable as fallback - return clientcmd.BuildConfigFromFlags("", filepath.Join(os.Getenv("HOME"), ".kube", "config")) + kubeConfigPath := os.Getenv("KUBECONFIG") + if kubeConfigPath == "" { + kubeConfigPath = filepath.Join(os.Getenv("HOME"), ".kube", "config") + } + return clientcmd.BuildConfigFromFlags("", kubeConfigPath) }