Helm Template Pipeline


Helm Template Pipeline

In this tutorial, we are going to discuss the helm template pipeline and default values. One of the powerful features of the template language is its concept of pipelines (|).

Helm Template Pipeline

Along with functions, the pipeline will be used more frequently to add more value to the calculations.

Say, for example, I may want to convert a particular string into an uppercase and then do further processing by adding double quotes, then I might do some other operation.

So this particular pipeline got derived from the Linux concepts. Let’s do some examples and get a better understanding.

Let me go into the values file and add the qualification key and its corresponding value.

message: Welcome to waytoeasylearn
website: www.waytoeasylearn.com
owner:
  name: Ashok Kumar
  place: Hyderabad
  qualification: mca

Now let me get into the templates file; within templates, I’m going to add a key qualification, and I’m going to have a derivative where it’s going to pick the value from qualification, and that will be piped to a function called upper.

After that, I added another key date, and here also, I’m also going to have a declarative, which will be piped to a function called quote.

ashok@waytoeasylearn:~/mychart$ cat templates/configmap.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Sample Config Map"
  message: {{ .Values.message }}
  website: {{ upper .Values.website }}
  ownerName: {{ quote .Values.owner.name }}
  ownerPlace: {{ quote .Values.owner.place }}
  qualification: {{ .Values.owner.qualification | upper | quote }}
  date: {{ now | date "2006-01-02" | quote }}
Explanation

So what will happen? The qualification will be read from the values file, and it will convert into uppercase. Then the output of it will be piped to another function called quote. So it’s going to quote the output and put that as the final calculated value.

The same way, I do have another derivative where I do have a function called now, that’s going to get the current timestamp, and it’s going to pipe it to another function called date, and that’s going to format the date in this particular order (YEAR-MONTH-DAY).

The way the Go template works for the date formatting is quite different. So you can verify the same page of sprig functions. Here are a lot more details provided as a part of the date functions.

So here, the current timestamp will format in this particular structure, and output will be enclosed within double quotes.

Let me go ahead and do a dry run.

ashok@waytoeasylearn:~$ helm install --dry-run --debug templatepipeline ./mychart/
install.go:173: [debug] Original chart version: ""
install.go:190: [debug] CHART PATH: /home/ashok/mychart
NAME: templatepipeline
LAST DEPLOYED: Thu May 20 10:15:02 2021
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
USER-SUPPLIED VALUES:
{}
COMPUTED VALUES:
message: Welcome to waytoeasylearn
owner:
  name: Ashok Kumar
  place: Hyderabad
  qualification: mca
website: www.waytoeasylearn.com
HOOKS:
MANIFEST:
Source: mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: templatepipeline-configmap
data:
  myvalue: "Sample Config Map"
  message: Welcome to waytoeasylearn
  website: WWW.WAYTOEASYLEARN.COM
  ownerName: "Ashok Kumar"
  ownerPlace: "Hyderabad"
  qualification: "MCA"
  date: "2021-05-20"

So it took the qualification from the values file and converted that into uppercase, then enclosed it within the double-quotes.

The next one took the current timestamp converted into the structure I had defined and enclosed within the double quotes.

So this is one of the very useful functions when we are moving on to the condition, verification’s or looping, lot more places this will be very useful.

Also, applying the logical operators will be very useful. Along with this, we need to have an understanding of the default value as well.

default value

Whenever we do some computation, we may not get the value, or that may not be available from where we are calculating the value.

So we need to provide some default value. So that it can replace and the value is getting calculated to offer it to the template.

Let me go ahead and add some additional details to the templates. Here I’m going to provide another line called email and where I’m going to have a derivative.

ashok@waytoeasylearn:~/mychart$ cat templates/configmap.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Sample Config Map"
  message: {{ .Values.message }}
  website: {{ upper .Values.website }}
  ownerName: {{ quote .Values.owner.name }}
  ownerPlace: {{ quote .Values.owner.place }}
  qualification: {{ .Values.owner.qualification | upper | quote }}
  date: {{ now | date "2006-01-02" | quote }}
  email: {{ .Values.email | default "contact@sh121.global.temp.domains" | quote }}

So it’s going to pick the values contact from the values file. But I have not added the email within the values file. Anyway, we can go ahead and verify.

ashok@waytoeasylearn:~$ helm install --dry-run --debug templatepipeline ./mychart/
install.go:173: [debug] Original chart version: ""
install.go:190: [debug] CHART PATH: /home/ashok/mychart
NAME: templatepipeline
LAST DEPLOYED: Thu May 20 10:15:02 2021
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
USER-SUPPLIED VALUES:
{}
COMPUTED VALUES:
message: Welcome to waytoeasylearn
owner:
  name: Ashok Kumar
  place: Hyderabad
  qualification: mca
website: www.waytoeasylearn.com
HOOKS:
MANIFEST:
Source: mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: templatepipeline-configmap
data:
  myvalue: "Sample Config Map"
  message: Welcome to waytoeasylearn
  website: WWW.WAYTOEASYLEARN.COM
  ownerName: "Ashok Kumar"
  ownerPlace: "Hyderabad"
  qualification: "MCA"
  date: "2021-05-20"
  email: "contact@sh121.global.temp.domains"

So in case, if the value is not calculated or it is not derived from the values file, it is going to use this value as the default one.

Let me go ahead and check the values YAML file as well.

ashok@waytoeasylearn:~$ cat mychart/values.yaml 
message: Welcome to waytoeasylearn
website: www.waytoeasylearn.com
owner:
  name: Ashok Kumar
  place: Hyderabad
  qualification:mca

Here I do not have value for email. So it replaced the default value that we had provided.

Now, I’m going to run the dry run on the same chart resources, but here I’m passing the contact value using the argument –set.

ashok@waytoeasylearn:~$ helm install --dry-run --debug templatepipeline ./mychart/ --set email="support@sh121.global.temp.domains"
install.go:173: [debug] Original chart version: ""
install.go:190: [debug] CHART PATH: /home/ashok/mychart
NAME: templatepipeline
LAST DEPLOYED: Thu May 20 10:15:02 2021
NAMESPACE: default
STATUS: pending-install
REVISION: 1
TEST SUITE: None
USER-SUPPLIED VALUES:
{}
COMPUTED VALUES:
message: Welcome to waytoeasylearn
owner:
  name: Ashok Kumar
  place: Hyderabad
  qualification: mca
website: www.waytoeasylearn.com
HOOKS:
MANIFEST:
Source: mychart/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: templatepipeline-configmap
data:
  myvalue: "Sample Config Map"
  message: Welcome to waytoeasylearn
  website: WWW.WAYTOEASYLEARN.COM
  ownerName: "Ashok Kumar"
  ownerPlace: "Hyderabad"
  qualification: "MCA"
  date: "2021-05-20"
  email: "support@sh121.global.temp.domains"

So within the calculated value, it will replace the value we provided as part of the command prompt using the argument –set.

So in a quick summary, we have discussed how to use the template pipeline and the default value within the templates.

Helm Template Pipeline
Scroll to top