Skip to content

Commit

Permalink
adding the ability to define extraLabels for the kubernetes Service o…
Browse files Browse the repository at this point in the history
…bject
  • Loading branch information
bjoernw committed Aug 17, 2023
1 parent 9116fa6 commit edae0f7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions helm/chart/router/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ extraLabels:
```
*/}}
{{- define "common.templatizeExtraLabels" -}}
{{- range $key, $value := .Values.extraLabels }}
{{ printf "%s: %s" $key (include "common.tplvalues.render" ( dict "value" $value "context" $))}}
{{- $extraLabels := .extraLabels -}}
{{- $ctx := .context -}}
{{- range $key, $value := $extraLabels }}
{{ printf "%s: %s" $key (include "common.tplvalues.render" (dict "value" $value "context" $ctx)) }}
{{- end -}}
{{- end -}}
4 changes: 2 additions & 2 deletions helm/chart/router/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
{{- include "router.labels" . | nindent 4 }}
{{- if .Values.extraLabels }}
{{- include "common.templatizeExtraLabels" . | nindent 4 }}
{{ include "common.templatizeExtraLabels" (dict "extraLabels" .Values.extraLabels "context" $) | nindent 4 }}
{{- end }}
{{/* There may not be much configuration so check that there is something */}}
{{- if (((((.Values.router).configuration).telemetry).metrics).prometheus).enabled }}
Expand Down Expand Up @@ -35,7 +35,7 @@ spec:
labels:
{{- include "router.selectorLabels" . | nindent 8 }}
{{- if .Values.extraLabels }}
{{- include "common.templatizeExtraLabels" . | nindent 8 }}
{{ include "common.templatizeExtraLabels" (dict "extraLabels" .Values.extraLabels "context" $) | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
Expand Down
3 changes: 3 additions & 0 deletions helm/chart/router/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ metadata:
name: {{ include "router.fullname" . }}
labels:
{{- include "router.labels" . | nindent 4 }}
{{- if .Values.service.extraLabels }}
{{ include "common.templatizeExtraLabels" (dict "extraLabels" .Values.service.extraLabels "context" $) | indent 4 }}
{{- end }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
6 changes: 5 additions & 1 deletion helm/chart/router/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ initContainers: []
# extraLabels:
# label_one_name: "label_one_value"
# label_two_name: "label_two_value"
extraLabels: {}
extraLabels:
somethingExtra: "{{ .Release.Name }}"

lifecycle: {}
# preStop:
Expand Down Expand Up @@ -139,6 +140,9 @@ service:
type: ClusterIP
port: 80
annotations: {}
extraLabels:
testing: hello
testing2: hello

serviceMonitor:
enabled: false
Expand Down

0 comments on commit edae0f7

Please sign in to comment.