From 80794876e021d23e75a7064ed87583b8e0e36607 Mon Sep 17 00:00:00 2001 From: Tarun Pothulapati Date: Wed, 28 Oct 2020 07:24:56 +0530 Subject: [PATCH] Restrict controlPlaneTracing field only to control plane components (#5117) * Restrict controlPlaneTracing field only to control plane components Previously, `global.controlPlaneTracing` was not available during injection and thus not affecting it. This commit creates a new method which checks if controlPlaneTracing is enabled and sets to the defaults if it is. This is done on the duplicates thus preventing it from not being propagated into `linkerd-config` Signed-off-by: Tarun Pothulapati --- charts/add-ons/grafana/templates/grafana.yaml | 1 + charts/add-ons/prometheus/templates/prometheus.yaml | 1 + charts/linkerd2/templates/controller.yaml | 1 + charts/linkerd2/templates/destination.yaml | 1 + charts/linkerd2/templates/identity.yaml | 1 + charts/linkerd2/templates/proxy-injector.yaml | 1 + charts/linkerd2/templates/sp-validator.yaml | 1 + charts/linkerd2/templates/tap.yaml | 1 + charts/linkerd2/templates/web.yaml | 1 + charts/partials/templates/_proxy.tpl | 13 ++++--------- charts/partials/templates/_trace.tpl | 7 +++++++ 11 files changed, 20 insertions(+), 9 deletions(-) diff --git a/charts/add-ons/grafana/templates/grafana.yaml b/charts/add-ons/grafana/templates/grafana.yaml index f7b7b773a..8034e7ee6 100644 --- a/charts/add-ons/grafana/templates/grafana.yaml +++ b/charts/add-ons/grafana/templates/grafana.yaml @@ -167,6 +167,7 @@ spec: {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/add-ons/prometheus/templates/prometheus.yaml b/charts/add-ons/prometheus/templates/prometheus.yaml index f3ea80245..44475f1f8 100644 --- a/charts/add-ons/prometheus/templates/prometheus.yaml +++ b/charts/add-ons/prometheus/templates/prometheus.yaml @@ -285,6 +285,7 @@ spec: {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/linkerd2/templates/controller.yaml b/charts/linkerd2/templates/controller.yaml index 83786b16d..d7a111a57 100644 --- a/charts/linkerd2/templates/controller.yaml +++ b/charts/linkerd2/templates/controller.yaml @@ -112,6 +112,7 @@ spec: {{- $r := merge .Values.publicAPIProxyResources .Values.global.proxy.resources }} {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/linkerd2/templates/destination.yaml b/charts/linkerd2/templates/destination.yaml index c478b3bf5..6b853f5ae 100644 --- a/charts/linkerd2/templates/destination.yaml +++ b/charts/linkerd2/templates/destination.yaml @@ -129,6 +129,7 @@ spec: {{- $r := merge .Values.destinationProxyResources .Values.global.proxy.resources }} {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/linkerd2/templates/identity.yaml b/charts/linkerd2/templates/identity.yaml index 99e325fc1..14450c806 100644 --- a/charts/linkerd2/templates/identity.yaml +++ b/charts/linkerd2/templates/identity.yaml @@ -152,6 +152,7 @@ spec: {{- $r := merge .Values.identityProxyResources .Values.global.proxy.resources }} {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/linkerd2/templates/proxy-injector.yaml b/charts/linkerd2/templates/proxy-injector.yaml index b17de25b1..7b2f68ef8 100644 --- a/charts/linkerd2/templates/proxy-injector.yaml +++ b/charts/linkerd2/templates/proxy-injector.yaml @@ -91,6 +91,7 @@ spec: {{- $r := merge .Values.proxyInjectorProxyResources .Values.global.proxy.resources }} {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/linkerd2/templates/sp-validator.yaml b/charts/linkerd2/templates/sp-validator.yaml index 8e65393a1..58e94b53a 100644 --- a/charts/linkerd2/templates/sp-validator.yaml +++ b/charts/linkerd2/templates/sp-validator.yaml @@ -108,6 +108,7 @@ spec: {{- $r := merge .Values.spValidatorProxyResources .Values.global.proxy.resources }} {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/linkerd2/templates/tap.yaml b/charts/linkerd2/templates/tap.yaml index 4f7fe8a69..a6754f18e 100644 --- a/charts/linkerd2/templates/tap.yaml +++ b/charts/linkerd2/templates/tap.yaml @@ -118,6 +118,7 @@ spec: {{- $r := merge .Values.tapProxyResources .Values.global.proxy.resources }} {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/linkerd2/templates/web.yaml b/charts/linkerd2/templates/web.yaml index 6c4c87bba..eb5be68af 100644 --- a/charts/linkerd2/templates/web.yaml +++ b/charts/linkerd2/templates/web.yaml @@ -115,6 +115,7 @@ spec: {{- $r := merge .Values.webProxyResources .Values.global.proxy.resources }} {{- $_ := set $tree.Values.global.proxy "resources" $r }} {{- end }} + {{- include "partials.setControlPlaneTracing.proxy" $tree }} - {{- include "partials.proxy" $tree | indent 8 | trimPrefix (repeat 7 " ") }} {{ if not .Values.global.cniEnabled -}} initContainers: diff --git a/charts/partials/templates/_proxy.tpl b/charts/partials/templates/_proxy.tpl index 3300b4c64..e67a3547f 100644 --- a/charts/partials/templates/_proxy.tpl +++ b/charts/partials/templates/_proxy.tpl @@ -43,7 +43,7 @@ env: value: 10000ms - name: LINKERD2_PROXY_OUTBOUND_CONNECT_KEEPALIVE value: 10000ms -{{ if or (.Values.global.proxy.trace.collectorSvcAddr) (.Values.global.controlPlaneTracing) -}} +{{ if .Values.global.proxy.trace.collectorSvcAddr -}} - name: LINKERD2_PROXY_TRACE_ATTRIBUTES_PATH value: /var/run/linkerd/podinfo/labels {{ end -}} @@ -98,12 +98,7 @@ env: - name: LINKERD2_PROXY_TAP_SVC_NAME value: linkerd-tap.$(_l5d_ns).serviceaccount.identity.$(_l5d_ns).$(_l5d_trustdomain) {{ end -}} -{{ if .Values.global.controlPlaneTracing -}} -- name: LINKERD2_PROXY_TRACE_COLLECTOR_SVC_ADDR - value: linkerd-collector.{{.Values.global.namespace}}.svc.{{.Values.global.clusterDomain}}:55678 -- name: LINKERD2_PROXY_TRACE_COLLECTOR_SVC_NAME - value: linkerd-collector.{{.Values.global.namespace}}.serviceaccount.identity.$(_l5d_ns).$(_l5d_trustdomain) -{{ else if .Values.global.proxy.trace.collectorSvcAddr -}} +{{ if .Values.global.proxy.trace.collectorSvcAddr -}} - name: LINKERD2_PROXY_TRACE_COLLECTOR_SVC_ADDR value: {{ .Values.global.proxy.trace.collectorSvcAddr }} - name: LINKERD2_PROXY_TRACE_COLLECTOR_SVC_NAME @@ -147,9 +142,9 @@ lifecycle: - -c - sleep {{.Values.global.proxy.waitBeforeExitSeconds}} {{- end }} -{{- if or (.Values.global.proxy.trace.collectorSvcAddr) (.Values.global.controlPlaneTracing) (not .Values.global.proxy.disableIdentity) (.Values.global.proxy.saMountPath) }} +{{- if or (.Values.global.proxy.trace.collectorSvcAddr) (not .Values.global.proxy.disableIdentity) (.Values.global.proxy.saMountPath) }} volumeMounts: -{{- if or (.Values.global.proxy.trace.collectorSvcAddr) (.Values.global.controlPlaneTracing) }} +{{- if .Values.global.proxy.trace.collectorSvcAddr }} - mountPath: var/run/linkerd/podinfo name: podinfo {{- end -}} diff --git a/charts/partials/templates/_trace.tpl b/charts/partials/templates/_trace.tpl index 8e60ff886..8bf6295d7 100644 --- a/charts/partials/templates/_trace.tpl +++ b/charts/partials/templates/_trace.tpl @@ -3,3 +3,10 @@ - -trace-collector=linkerd-collector.{{.Values.global.namespace}}.svc.{{.Values.global.clusterDomain}}:55678 {{ end -}} {{- end }} + +{{ define "partials.setControlPlaneTracing.proxy" -}} +{{ if .Values.global.controlPlaneTracing -}} +{{ $_ := set .Values.global.proxy.trace "collectorSvcAddr" (printf "linkerd-collector.%s.svc.%s:55678" .Values.global.namespace .Values.global.clusterDomain) -}} +{{ $_ := set .Values.global.proxy.trace "collectorSvcAccount" (printf "linkerd-collector.%s" .Values.global.namespace) -}} +{{ end -}} +{{- end }}