default key value when reading values from values file in helm chart

7/8/2019

I want to pass the default key value while reading values file.

{{- range $key, $val := .Values.nodeLabel | default map[string]string{"a":"b"}}}

Values.yaml nodeLabel - a: b

But i am trying to pass default value too.

{{- range $key, $val := .Values.nodeLabel | default "b:c"

error- range cannot iterate over b:c

-- Inder Singh
go
kubernetes
kubernetes-helm

1 Answer

7/9/2019

Please try this:

 {{- if .Values.nodeLabel -}}
    {{- range $key, $val := .Values.nodeLabel  }}
    {{ $key }}: {{ $val }}
  #  {{- end }}
  {{ else }}
     {{ default "b: c" }}
  {{- end -}}

Additional resources: The Chart Best Practices Guide

Hope this help

-- Hanx
Source: StackOverflow