3

I've got these values in a YAML file:

configuration:
  files:
  - from: "foo.yml"
    to: "bar.yml"

I would like to check whether configuration and files exists like this:

{{- if and .Values.configuration .Values.configuration.files -}}
volumeMounts:
  {{- range .Values.configuration.files -}}
  - name: "config"
    mountPath: {{ .to }}
  {{- end -}}
{{- end -}}

It works beautifully when configuration and files exist but when both are omitted I get this error when rendering the Helm template:

Error: render error in "chart/templates/deployment.yaml": template: chart/templates/deployment.yaml:62:48: executing "chart/templates/deployment.yaml" at <.Values.configuration.files>: nil pointer evaluating interface {}.files

How can I check whether both exist without nesting two ifclauses?

Hedge
  • 16,142
  • 42
  • 141
  • 246

0 Answers0