Skip to content

Instantly share code, notes, and snippets.

@ofen
Last active May 12, 2023 08:40
Show Gist options
  • Save ofen/5f5d3e8a9ddee33455ab922f4df07fea to your computer and use it in GitHub Desktop.
Save ofen/5f5d3e8a9ddee33455ab922f4df07fea to your computer and use it in GitHub Desktop.
Helm helper to convert label map to comma-separated string
{{/*
Convert labels to string like: key1="value1", key2="value2", ...
*/}}
{{- define "chart.external_labels" -}}
{{- $list := list -}}
{{- range $k, $v := .Values.external_labels -}}
{{- $list = append $list (printf "%s=\"%s\"" $k $v) -}}
{{- end -}}
{{ join ", " $list }}
{{- end -}}
---
external_labels:
cluster-location: lab
cluster-name: test-cluster01
@sivanagireddyb
Copy link

How to convert below template.

{{- define "mongo.selectorLabels" -}}
app: {{ include "mongo.name" . }}
release: {{ .Release.Name }}
{{- end }}

{{- define "sring.lables" -}}
{{- $list := list -}}
{{- range $k, $v := ( include "mongo.selectorLabels" ) -}}
{{- $list = append $list (printf "%s=\"%s\"" $k $v) -}}
{{- end -}}
{{ join ", " $list }}
{{- end -}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment