From 244946c27b33852c60954986b9faeff83c5d5a0d Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Fri, 3 Feb 2023 12:37:18 -0600 Subject: [PATCH] :sparkles: (kubernetes): Check KUBECONFIG env when setting up Kubernetes client --- internal/config/flags/kubernetes.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/config/flags/kubernetes.go b/internal/config/flags/kubernetes.go index a3bda16b..af48efda 100644 --- a/internal/config/flags/kubernetes.go +++ b/internal/config/flags/kubernetes.go @@ -6,11 +6,19 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "os" "path/filepath" ) +const KubeconfigEnv = "KUBECONFIG" + func Kubeconfig(cmd *cobra.Command) { - cmd.PersistentFlags().String("kubeconfig", filepath.Join("$HOME", ".kube", "config"), "absolute path to the kubeconfig file") + kubeconfigEnv := os.Getenv(KubeconfigEnv) + if kubeconfigEnv == "" { + kubeconfigEnv = filepath.Join("$HOME", ".kube", "config") + } + + cmd.PersistentFlags().String("kubeconfig", kubeconfigEnv, "absolute path to the kubeconfig file") if err := viper.BindPFlag("kubernetes.kubeconfig", cmd.PersistentFlags().Lookup("kubeconfig")); err != nil { panic(err) }