This is values.yaml file. It contains the following and when I am trying to get it into _helper.tpl im getting Helm template failed. Error: render error in "windows/templates/ingresses/windows.yaml": template: windows/templates/_helpers.tpl:38:18: executing "windows.certificate" at <.Values.ingress.enab...>: can't evaluate field ingress in type interface {} : exit status 1
values.yaml
ingress:
enabled: true
tls: true
certificate: ''
issuer:
name: letsencrypt-staging
hosts:
windows:
- name: ''
path: /
_helpers.tpl
{{/*
Calculate certificate
*/}}
{{- define "windows.certificate" }}
{{- printf .Values.ingress.enabled }} // error line is this. line no 38
{{- end }}
in windows.yaml
- secretName: {{ template "windows.certificate" . }} // calling the helper method.
for those having the same problem.
In my case, I had to rename my file from Values.yaml to values.yaml (mind the lowercase filename).
It is possible that when you call the helper, the context is not the root as the definition expects.
Take for example, if you use it in a template like this:
{{- range .Values.deployments }}
{{ $certificate := include "windows.certificate" . }}
{{- end }}
The context when calling the helper would be .Values.deployments. So, .Values.ingress.certificate would point to .Values.deployments.Values.ingress.certificate, which of course, does not exist.
At the start of the variables section of the helm templating guide, you have an example of how with
blocks affect what .
means. Reading it might help you understand how to be aware of what you pass to your helper template.
The problem is the indentation try this
values.yaml
ingress:
enabled: true
tls: true
certificate: ''
issuer:
name: letsencrypt-staging
hosts:
windows:
- name: ''
path: /
Also some changes on the helpers to control the output of the define block
_helpers.tpl
{{/*
Calculate certificate
*/}}
{{- define "windows.certificate" }}
{{- if .Values.ingress.enabled }}
{{- printf .Values.ingress.certificate }}
{{- end }}
{{- end }}