Skip to content

Commit

Permalink
✨ (kubernetes): Check KUBECONFIG env when setting up Kubernetes client
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Feb 3, 2023
1 parent a486b39 commit 244946c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/config/flags/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 244946c

Please sign in to comment.