Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 741
Mike Avatar asked Sep 20 '18 03:09

Mike


People also ask

How do you declare a variable in Helm template?

In Helm templates, a variable is a named reference to another object. It follows the form $name . Variables are assigned with a special assignment operator: := . We can rewrite the above to use a variable for Release.Name .

What is $_ in Helm?

The $_ is used to suppress undesired output as "set" returns the new dictionary. The above returns: - name: mongod-none. Any values added to the dictionary will live beyond the call. If you want to avoid polluting an existing dictionary you can force a deep copy with: {{- $d := merge (dict) . -}}

What does the Helm Template command do?

With Helm's helm template command, you can check the output of the chart in fully rendered Kubernetes resource templates. This is a very handy command to check the templates' outputs, especially when you are developing a new chart, making changes to the chart, debugging, and so on.


1 Answers

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" . -}}
like image 182
David Maze Avatar answered Sep 19 '22 19:09

David Maze