Using include inside range in Go templates (helm)

4/18/2020

I have a template that get rendered several times with a range iteration and I can access variables external variables such as $.Release.Name without a problem. However, when I include templates I can't get it to work:

{{ range $key, $val := $.Values.resources }}
      ...
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/secrets.yaml") . | sha256sum }}
{{ end }}

And in secrets.yaml:

apiVersion: "v1"
kind: "Secret"
metadata:
  name: {{ $.Release.Name }}-secrets

I got this error:

Error: render error in "botfront-project/templates/deployment.yaml": template: [filename] :19:28: executing [filename] at <include (print $.Template.BasePath "/secrets.yaml") .>: error calling include: template: .../secrets.yaml:4:19: executing ".../secrets.yaml" at <$.Release.Name>: nil pointer evaluating interface {}.Name

How do I access variables inside an included template?

-- znat
go-templates
kubernetes-helm

0 Answers