diff --git a/charts/flagger/templates/deployment.yaml b/charts/flagger/templates/deployment.yaml index 5941d8fe1..ed3e992d9 100644 --- a/charts/flagger/templates/deployment.yaml +++ b/charts/flagger/templates/deployment.yaml @@ -42,11 +42,22 @@ spec: imagePullSecrets: - name: {{ .Values.image.pullSecret }} {{- end }} + volumes: + {{- if .Values.kubeconfigHost }} + - name: kubeconfig + secret: + secretName: "{{ .Values.kubeconfigHost }}" + {{- end }} containers: - name: flagger securityContext: readOnlyRootFilesystem: true runAsUser: 10001 + volumeMounts: + {{- if .Values.kubeconfigHost }} + - name: kubeconfig + mountPath: "/tmp/istio-host" + {{- end }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: @@ -90,6 +101,9 @@ spec: {{- if .Values.eventWebhook }} - -event-webhook={{ .Values.eventWebhook }} {{- end }} + {{- if .Values.kubeconfigHost }} + - -kubeconfig-host=/tmp/istio-host/kubeconfig + {{- end }} livenessProbe: exec: command: diff --git a/charts/flagger/values.yaml b/charts/flagger/values.yaml index a0c8f27bd..927fe54f9 100644 --- a/charts/flagger/values.yaml +++ b/charts/flagger/values.yaml @@ -102,3 +102,5 @@ tolerations: [] prometheus: # to be used with ingress controllers install: false + +kubeconfigHost: "" diff --git a/cmd/flagger/main.go b/cmd/flagger/main.go index 5ab5c80f9..a9f271d01 100644 --- a/cmd/flagger/main.go +++ b/cmd/flagger/main.go @@ -58,6 +58,7 @@ var ( leaderElectionNamespace string enableConfigTracking bool ver bool + kubeconfigHost string ) func init() { @@ -83,6 +84,7 @@ func init() { flag.StringVar(&leaderElectionNamespace, "leader-election-namespace", "kube-system", "Namespace used to create the leader election config map.") flag.BoolVar(&enableConfigTracking, "enable-config-tracking", true, "Enable secrets and configmaps tracking.") flag.BoolVar(&ver, "version", false, "Print version") + flag.StringVar(&kubeconfigHost, "kubeconfig-host", "", "Path to a kubeconfig for host cluster. Only required if cluster has a host cluster.") } func main() { @@ -117,14 +119,20 @@ func main() { logger.Fatalf("Error building kubernetes clientset: %v", err) } - meshClient, err := clientset.NewForConfig(cfg) + flaggerClient, err := clientset.NewForConfig(cfg) if err != nil { - logger.Fatalf("Error building mesh clientset: %v", err) + logger.Fatalf("Error building flagger clientset: %s", err.Error()) } - flaggerClient, err := clientset.NewForConfig(cfg) + //if host kube config is there than this should be spawned with host kubeconfig + cfgHost, err := clientcmd.BuildConfigFromFlags(masterURL, kubeconfigHost) if err != nil { - logger.Fatalf("Error building flagger clientset: %s", err.Error()) + logger.Fatalf("Error building host kubeconfig: %v", err) + } + + meshClient, err := clientset.NewForConfig(cfgHost) + if err != nil { + logger.Fatalf("Error building mesh clientset: %v", err) } verifyCRDs(flaggerClient, logger)