Last active
June 20, 2023 03:30
-
-
Save rmetzler/bc9401874553724afb4341d31ad2c427 to your computer and use it in GitHub Desktop.
flatten lists in helm and go templating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{- define "flatten_list" -}} | |
{{- $output := list -}} | |
{{- range . -}} | |
{{- if (kindIs "slice" . ) -}} | |
{{- $output = (concat $output ( get (fromYaml (include "flatten_list" . ) ) "list" ) ) -}} | |
{{- else -}} | |
{{- $output = (append $output . ) -}} | |
{{- end -}} | |
{{- end -}} | |
{{- toYaml (dict "list" $output) -}} | |
{{- end -}} | |
{{- define "flatten" -}} | |
{{- get ( fromYaml (include "flatten_list" . ) ) "list" | toYaml }} | |
{{- end -}} | |
{{- $nested := (list "a" "b" "c" (list 1 2 3)) -}} | |
flattend_list: | |
{{- include "flatten" $nested | nindent 4 }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think it also would be possible to create a
flatten
function with tail-recursion so we don't have to dofromYaml
andtoYaml
, but it would be preferable to have something like this in sprig