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)