Helm include map define in _helpers

3/8/2019

I try to include a map which is defined in the _helper.tpl file but I can't. I get the error "at : range can't iterate over"(nothing more).

values.yaml

services:
  - serviceX
  - serviceY

_helpers.tpl

{{/*
Define the mapping values
*/}}
{{- define "associated.resources" }}
{{- $resourceMapping := dict "serviceX" "config1" "serviceY" "config2" "serviceZ" "config5" -}}
{{- end }}

configmap.yaml

...
{{- $resourcesMap := include "associated.resources" . }}
{{- range $k, $v := $resourcesMap }}
{{- if (has $k $.Values.services) }}
   - $v
{{- end }}
{{- end }}

I don't really know how to set a map and include it then in my configmap file. Does the include method support map type? It seems that it returns only string.

Thanks

-- Matt
kubernetes-helm

1 Answer

3/22/2019

Moving all logic to __helpers.tpl can solve the issue.

__helpers.tmp

{{/*
Define the mapping values
*/}}
{{- define "associated.resources" }}
{{- $resourceMapping := dict "serviceX" "config1" "serviceY" "config2" "serviceZ" "config5" -}}
{{- range $k, $v := $resourceMapping }}
{{- if (has $k $.Values.services) }}
  - {{ $v }}
{{- end }}
{{- end }}
{{- end }}

configmap.yaml

{{-  include "associated.resources" . | indent 6 }}
-- edbighead
Source: StackOverflow