Suppose I have a values.yaml that contains the following arbitrary-length list of maps:
values.yaml
-----------
people:
- name: "alice"
age: 56
- name: "bob"
age: 42
One of the containers in my stack will need access to a list of just the names. (NAMES="alice,bob")
So far, I have come up with the following solution:
templates/_helpers.tpl
----------------------
{{- define "list.listNames" -}}
{{ $listStarted := false }}
{{- range .Values.people }}
{{- if $listStarted }},{{- end }}{{ $listStarted = true }}{{ .name }}
{{- end }}
{{- end }}
templates/configmap.yaml
------------------------
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
NAMES: '{{- include "list.listNames" . }}'
This solution works, but it feels inelegant. Looking through the Helm documentation, it seems like this would be the perfect use case for pluck in combination with join, but I haven't found a way to use .Values.people as an argument to that function.
Is there a cleaner way to do this?