Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a variable in helm include (or template) for the name

I made a design for my helm chart which uses templates to set certain parts of my kubernetes deployment. The templates are per cloud provider:

A template for GCE, a template for AWS, etc.

The template is then included into the deployment part of the chart in Helm.

Now there is a pretty way of doing this which is: Name every template according to the cloud provider it is intended for, and use a variable in the values.yaml to direct this.

And there is a less pretty way with a bunch of if statements.

I want to use the pretty way since it requires a lot less maintenance and code downstream, but can not get the following to work:

{{- include {{.Values.resources.cloudProvider}} .}}

In this statement the {{.Values.resources.cloudProvider}} contains my cloud provider name (aws, gce, etc)

The error I get is:

Error: parse error in "testModel/templates/deployment.yaml": 
template: testModel/templates/deployment.yaml:28: 
unexpected "{" in operand

The other method I tested is:

{{- include (.Values.resources.cloudProvider) .}}

Which gives:

Error: render error in "testModel/templates/deployment.yaml": template:
testModel/templates/deployment.yaml:29:23: 
executing "testModel/templates/deployment.yaml" 
at <.Values.resources.c...>: invalid value; expected string

Is there a way to use a variable for a template name when including the template?

like image 356
Norbert van Nobelen Avatar asked May 10 '17 22:05

Norbert van Nobelen


1 Answers

I am using helm 2.4.2. This work by changing the line

{{- include {{.Values.resources.cloudProvider}} .}}

to:

{{- include .Values.resources.cloudProvider .}}

You can also use a variable:

{{- $provider := .Values.resources.cloudProvider -}}
{{ - include $provider . }}

like image 166
kscoder Avatar answered Nov 15 '22 09:11

kscoder