6

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.
m9m9m
  • 1,655
  • 3
  • 21
  • 41

3 Answers3

5

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.

Ángela
  • 1,405
  • 18
  • 24
  • Where shall I add this code? in _helpers.tpl or where i am calling this helper method. I have modified my question and added how I am calling the helper method. {{ template "windows.certificate" . }} – m9m9m Jun 21 '19 at 05:16
  • We need to see the code that is before you call the helper method. You need to check if there's any `{{range... }}` or `{{with...}}` that might have changed the context – Ángela Jun 21 '19 at 05:33
3

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).

Bob Claerhout
  • 781
  • 5
  • 24
2

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 }}
wolmi
  • 1,659
  • 12
  • 25