From 5183b861eec87b4561a566bfc6e5febcb2f7d86c Mon Sep 17 00:00:00 2001 From: asamonik <49288593+asamonik@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:10:19 +0200 Subject: [PATCH] kubeconfig fallback Signed-off-by: asamonik <49288593+asamonik@users.noreply.github.com> --- keptn-gateway/internal/gateway/gateway.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/keptn-gateway/internal/gateway/gateway.go b/keptn-gateway/internal/gateway/gateway.go index 1a076fce56..d14c529209 100644 --- a/keptn-gateway/internal/gateway/gateway.go +++ b/keptn-gateway/internal/gateway/gateway.go @@ -13,6 +13,7 @@ import ( _ "github.com/joho/godotenv/autoload" "go.uber.org/zap" "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/util/homedir" ) @@ -31,19 +32,15 @@ func NewGateway() *Gateway { } // kubernetes clientset in cluster - /* - config, err := rest.InClusterConfig() + config, err := rest.InClusterConfig() + if err != nil { + // if error fallback to .kube/config + home := homedir.HomeDir() + kubeconfig := filepath.Join(home, ".kube", "config") + config, err = clientcmd.BuildConfigFromFlags("", kubeconfig) if err != nil { panic(err.Error()) } - */ - - // alternative not in cluster config - home := homedir.HomeDir() - kubeconfig := filepath.Join(home, ".kube", "config") - config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) - if err != nil { - return nil } client, err := kubernetes.NewForConfig(config)