From 19f42c05601c8dbc7800540f5c938d5098e648f1 Mon Sep 17 00:00:00 2001 From: Sergey Monakhov Date: Thu, 18 Feb 2021 08:19:39 +0300 Subject: [PATCH] added worksInKubernetesCluster flag --- cmd/kg/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/kg/main.go b/cmd/kg/main.go index e7d827c..c2ad934 100644 --- a/cmd/kg/main.go +++ b/cmd/kg/main.go @@ -32,6 +32,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" apiextensions "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" "github.com/squat/kilo/pkg/encapsulation" @@ -86,6 +87,7 @@ func Main() error { compatibility := flag.String("compatibility", "", fmt.Sprintf("Should Kilo run in compatibility mode? Possible values: %s", availableCompatibilities)) encapsulate := flag.String("encapsulate", string(encapsulation.Always), fmt.Sprintf("When should Kilo encapsulate packets within a location? Possible values: %s", availableEncapsulations)) granularity := flag.String("mesh-granularity", string(mesh.LogicalGranularity), fmt.Sprintf("The granularity of the network mesh to create. Possible values: %s", availableGranularities)) + worksInKubernetesCluster := flag.Bool("worksInKubernetesCluster", false, "use InClusterConfig metod to configure the Kubernetes API client.") kubeconfig := flag.String("kubeconfig", "", "Path to kubeconfig.") hostname := flag.String("hostname", "", "Hostname of the node on which this process is running.") iface := flag.String("interface", mesh.DefaultKiloInterface, "Name of the Kilo interface to use; if it does not exist, it will be created.") @@ -166,7 +168,13 @@ func Main() error { var b mesh.Backend switch *backend { case k8s.Backend: - config, err := clientcmd.BuildConfigFromFlags(*master, *kubeconfig) + var config *rest.Config + var err error + if *worksInKubernetesCluster { + config, err = rest.InClusterConfig() + } else { + config, err = clientcmd.BuildConfigFromFlags(*master, *kubeconfig) + } if err != nil { return fmt.Errorf("failed to create Kubernetes config: %v", err) }