Search code examples
kubernetes-helmgo-templates

helm template: how do i assign the result of a template to a variable


I'm trying to do something like:

{{- $cassandrafullname := template "cassandra.fullname" . -}}

but I'm getting this error on a dry run:

Error: UPGRADE FAILED: parse error in "cassandra/templates/service.yaml": template: cassandra/templates/service.yaml:1: unexpected <template> in command

The reason why I have this issue is because I am unable to use the template cassandra.fullname within a range, so I'm trying to put the value into a variable and use it in the range instead. So if there's a solution for that, it would also be accepted!


Solution

  • Helm defines an include function which is identical to the standard template, except that it returns the rendered output instead of outputting it. You should be able to write

    {{- $cassandrafullname := include "cassandra.fullname" . -}}