I did not figured out how to proper render nested template array of objects
values.yaml
persistence:
volumes:
- name: api-manutencao-env2
configMap:
name: api-manutencao-env2
- name: api-manutencao-env2
configMap:
name: api-manutencao-env2
deployment.yaml (template)
{{- if .Values.persistence }}
volumes:
{{- range .Values.persistence.volumes }}
{{ . | toYaml | nindent 8 }}
{{- end }}
{{- end }}
Result:
volumes:
configMap:
name: api-manutencao-env2
name: api-manutencao-env2
configMap:
name: api-manutencao-env2
name: api-manutencao-env2
---
I render its content reversed and break in the array structure not being add the - and the correct ident.
I've tried https://kb.novaordis.com/index.php/Helm_Template_range and it did not work either.
Thanks
The easiest way to do this is to call
toYaml
on the entire list, rather than iterating through it on your own.If you iterate through the list with
range
, and you want the YAML list markers, you need to emit them yourself.indent
puts spaces in front of every line including the first one, so in this construct you need totrim
leading and trailing whitespace, causing the first line of the rendered output to appear immediately after the hyphen.The order of items in a YAML mapping isn't important, and at the underlying Go
map[string]interface{}
layer it isn't preserved. In the Gotext/template
languagerange
is documented as iterating over maps in sorted key order. Helm'stoYaml
extension isn't especially well-documented;toJson
at least appears in the documentation but it doesn't say anything about key order. It doesn't matter whethername:
orconfigMap:
comes first and Helm won't remember the ordering fromvalues.yaml
; there's nothing you can do to control this.