diff --git a/.changesets/fix_garypen_helm_extra_labels.md b/.changesets/fix_garypen_helm_extra_labels.md new file mode 100644 index 0000000000..4082915ff1 --- /dev/null +++ b/.changesets/fix_garypen_helm_extra_labels.md @@ -0,0 +1,7 @@ +### Helm: If there are `extraLabels` add them to all resources ([PR #3622](https://github.com/apollographql/router/pull/3622)) + +This extends the functionality of `extraLabels` so that, if they are defined, they will be templated for all resources created by the chart. + +Previously, they were only templated onto the `Deployment` resource. + +By [@garypen](https://github.com/garypen) and [@bjoernw](https://github.com/bjoernw) in https://github.com/apollographql/router/pull/3622 diff --git a/helm/chart/router/templates/configmap.yaml b/helm/chart/router/templates/configmap.yaml index a51f1e6be3..e7caffecaf 100644 --- a/helm/chart/router/templates/configmap.yaml +++ b/helm/chart/router/templates/configmap.yaml @@ -9,6 +9,9 @@ metadata: name: {{ $routerFullName }} labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} data: configuration.yaml: | {{- toYaml $configuration | nindent 4 }} diff --git a/helm/chart/router/templates/deployment.yaml b/helm/chart/router/templates/deployment.yaml index dcda27697b..2fb6fa1c7a 100644 --- a/helm/chart/router/templates/deployment.yaml +++ b/helm/chart/router/templates/deployment.yaml @@ -5,7 +5,7 @@ metadata: labels: {{- include "router.labels" . | nindent 4 }} {{- if .Values.extraLabels }} - {{- include "common.templatizeExtraLabels" . | nindent 4 }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} {{- end }} {{/* There may not be much configuration so check that there is something */}} {{- if (((((.Values.router).configuration).telemetry).metrics).prometheus).enabled }} @@ -34,7 +34,7 @@ spec: labels: {{- include "router.selectorLabels" . | nindent 8 }} {{- if .Values.extraLabels }} - {{- include "common.templatizeExtraLabels" . | nindent 8 }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 8 }} {{- end }} spec: {{- with .Values.imagePullSecrets }} diff --git a/helm/chart/router/templates/hpa.yaml b/helm/chart/router/templates/hpa.yaml index 8a7891da03..b9e1eeb5a6 100644 --- a/helm/chart/router/templates/hpa.yaml +++ b/helm/chart/router/templates/hpa.yaml @@ -9,6 +9,9 @@ metadata: name: {{ include "router.fullname" . }} labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} spec: scaleTargetRef: apiVersion: apps/v1 diff --git a/helm/chart/router/templates/ingress.yaml b/helm/chart/router/templates/ingress.yaml index 355862b2d3..5f4bd976e1 100644 --- a/helm/chart/router/templates/ingress.yaml +++ b/helm/chart/router/templates/ingress.yaml @@ -7,6 +7,9 @@ metadata: name: {{ $fullName }} labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} {{- with .Values.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/helm/chart/router/templates/pdb.yaml b/helm/chart/router/templates/pdb.yaml index 518fa5aea5..359a13af4d 100644 --- a/helm/chart/router/templates/pdb.yaml +++ b/helm/chart/router/templates/pdb.yaml @@ -6,6 +6,9 @@ metadata: name: {{ include "router.fullname" . }} labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} spec: {{- if .Values.podDisruptionBudget.minAvailable }} minAvailable: {{ .Values.podDisruptionBudget.minAvailable }} diff --git a/helm/chart/router/templates/secret.yaml b/helm/chart/router/templates/secret.yaml index 3fbecd863e..9f5a4b124d 100644 --- a/helm/chart/router/templates/secret.yaml +++ b/helm/chart/router/templates/secret.yaml @@ -5,6 +5,9 @@ metadata: name: {{ template "router.managedFederation.apiSecretName" . }} labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} data: managedFederationApiKey: {{ default "MISSING" .Values.managedFederation.apiKey | b64enc | quote }} {{- end }} diff --git a/helm/chart/router/templates/service.yaml b/helm/chart/router/templates/service.yaml index 83990d91ef..57f59a2108 100644 --- a/helm/chart/router/templates/service.yaml +++ b/helm/chart/router/templates/service.yaml @@ -4,6 +4,9 @@ metadata: name: {{ include "router.fullname" . }} labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} {{- with .Values.service.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/helm/chart/router/templates/serviceaccount.yaml b/helm/chart/router/templates/serviceaccount.yaml index 203f012bb0..b15b8eaf96 100644 --- a/helm/chart/router/templates/serviceaccount.yaml +++ b/helm/chart/router/templates/serviceaccount.yaml @@ -5,6 +5,9 @@ metadata: name: {{ include "router.serviceAccountName" . }} labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/helm/chart/router/templates/serviceentry.yaml b/helm/chart/router/templates/serviceentry.yaml index 774eddeb31..ddc43407b4 100644 --- a/helm/chart/router/templates/serviceentry.yaml +++ b/helm/chart/router/templates/serviceentry.yaml @@ -12,6 +12,9 @@ metadata: labels: app.fullName: {{ $fullName }} {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} {{- with .Values.serviceentry.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/helm/chart/router/templates/servicemonitor.yaml b/helm/chart/router/templates/servicemonitor.yaml index a4654a1add..61f9c88368 100644 --- a/helm/chart/router/templates/servicemonitor.yaml +++ b/helm/chart/router/templates/servicemonitor.yaml @@ -3,6 +3,11 @@ apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ .Release.Name }} + labels: + {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} spec: endpoints: - path: {{ include "router.prometheusMetricsPath" . }} diff --git a/helm/chart/router/templates/supergraph-cm.yaml b/helm/chart/router/templates/supergraph-cm.yaml index 40ff9d073a..3a5f2a362a 100644 --- a/helm/chart/router/templates/supergraph-cm.yaml +++ b/helm/chart/router/templates/supergraph-cm.yaml @@ -6,6 +6,9 @@ metadata: name: {{ $routerFullName }}-supergraph labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} data: supergraph-schema.graphql: |- {{ .Values.supergraphFile | indent 4 }} diff --git a/helm/chart/router/templates/tests/test-connection.yaml b/helm/chart/router/templates/tests/test-connection.yaml index 0bf0612719..67b939bea0 100644 --- a/helm/chart/router/templates/tests/test-connection.yaml +++ b/helm/chart/router/templates/tests/test-connection.yaml @@ -4,6 +4,9 @@ metadata: name: "{{ include "router.fullname" . }}-test-connection" labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} annotations: "helm.sh/hook": test spec: diff --git a/helm/chart/router/templates/virtualservice.yaml b/helm/chart/router/templates/virtualservice.yaml index d8a77afede..fe3ef21db2 100644 --- a/helm/chart/router/templates/virtualservice.yaml +++ b/helm/chart/router/templates/virtualservice.yaml @@ -11,6 +11,9 @@ metadata: namespace: {{ .Values.virtualservice.namespace }} labels: {{- include "router.labels" . | nindent 4 }} + {{- if .Values.extraLabels }} + {{- include "common.templatizeExtraLabels" . | trim | nindent 4 }} + {{- end }} {{- with .Values.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/helm/chart/router/values.yaml b/helm/chart/router/values.yaml index f682a3f933..94120f7f00 100644 --- a/helm/chart/router/values.yaml +++ b/helm/chart/router/values.yaml @@ -94,7 +94,7 @@ extraContainers: [] # command: ["sh"] initContainers: [] -# -- A map of extra labels to apply to the router deploment and containers +# -- A map of extra labels to apply to the resources created by this chart # Example: # extraLabels: # label_one_name: "label_one_value"