From 4defea4cc3431796d139faed8e4f510e79ad4ab5 Mon Sep 17 00:00:00 2001 From: Jonsy13 Date: Wed, 18 Sep 2024 18:19:22 +0530 Subject: [PATCH] Added litmusctl changes Signed-off-by: Jonsy13 --- custom/litmus-helm-agent/pkg/k8s/client.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/custom/litmus-helm-agent/pkg/k8s/client.go b/custom/litmus-helm-agent/pkg/k8s/client.go index 6044108d..ef49a967 100644 --- a/custom/litmus-helm-agent/pkg/k8s/client.go +++ b/custom/litmus-helm-agent/pkg/k8s/client.go @@ -5,7 +5,6 @@ import ( "flag" "fmt" "os" - "path/filepath" corev1r "k8s.io/api/core/v1" @@ -13,7 +12,6 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "k8s.io/client-go/util/homedir" ) func ConnectKubeApi() *kubernetes.Clientset { @@ -74,13 +72,12 @@ func CreateSecret(secretName string, secretData map[string][]byte, NAMESPACE str } func getKubeConfig() (*rest.Config, error) { - var kubeconfig *string - if home := homedir.HomeDir(); home != "" { - kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file") - } else { - kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file") - } + kubeconfig := flag.String("kubeconfig", "", "absolute path to the kubeconfig file") flag.Parse() + // Use in-cluster config if kubeconfig path is not specified + if *kubeconfig == "" { + return rest.InClusterConfig() + } // use the current context in kubeconfig return clientcmd.BuildConfigFromFlags("", *kubeconfig)