Helm charts
Helm get:
- helm get values <release name>
- - It will get all the values user passed using --set option when using helm install command
- helm get values <release name> -a
- - It will give all computed values.
indent
The indent function indents every line in a given string to the specified indent width. This is useful when aligning multi-line strings:
indent 4 $lots_of_text
The above will indent every line of text by 4 space characters.
nindent
The nindent function is the same as the indent function, but prepends a new line to the beginning of the string.
nindent 4 $lots_of_text
The above will indent every line of text by 4 space characters and add a new line to the beginning.
'-' (dash symbol) in curly braces:- You can define named templated using define(within define block as shown below) in tpl file
- The extension could be any thing .tpl is widely used as a best coding practice.We should prepend name with '_ ' else helm rendering engine treats it as normal yaml manifest file
- We can call about defined block of code, using 2 ways
As you can see, we piped result to indent by 4 spaces.If we move the include block and place it at any indent level,It doesn't mater.It will take iondendation from define block which is at level 0 indent and we specified required indent while calling using include
default "foo" .Bar
In the above, if .Bar evaluates to a non-empty value, it will be used. But if it is empty, foo will be returned instead.
The definition of "empty" depends on type:
Numeric: 0
String: ""
Lists: []
Dicts: {}
Boolean: false
And always nil (aka null)
For structs, there is no definition of empty, so a struct will never return the default.
These functions wrap a string in double quotes (quote) or single quotes (squote).
Here is the first named template in _helpers.tpl :
{{- define "myhelm1.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}On the first line we give the template snippet a name. We then refer to this name to include it.
The second line gives "myhelm1.name" a default value: .Chart.Name
If the default value does not exist "myhelm1.name" gets the value of .Values.nameOverride
trunc 63 truncates it to 63 characters in length.
trimSuffix "-" removes ONE trailing - if one exists.
but
trimSuffix "--" removes only two trailing -- if it exists.
( It does not work as in some programming languages where trim will remove all trailing characters )
app.kubernetes.io/name: {{ include "myhelm1.name" . }}
render as
app.kubernetes.io/name: myhelm1
Next: the template code
helm.sh/chart: {{ include "myhelm1.chart" . }}
renders as
helm.sh/chart: myhelm1-0.1.0
This is the template function :
{{- define "myhelm1.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}printf "%s-%s" .Chart.Name .Chart.Version concatenates .Chart.Name and .Chart.Version - plus it places a hyphen between the two.
replace "+" "_" replaces plus characters with underscores.
Now that you can understand those two one-liner functions you should be able to understand the 10-liner define "myhelm1.fullname" with ease.
Comments
Post a Comment