Skip to content

📄 Templating

Helmwave using go templates for templating.

Helmwave supports all built-in functions / sprig / gomplate and several custom functions. We recommend using gomplate.

flag
--templater value   Select template engine: sprig or gomplate (default: "sprig") [$HELMWAVE_TEMPLATER, $HELMWAVE_TEMPLATE_ENGINE]`

Explain context helm vs helmwave

There is a different context between helm and helmwave. You can't pass variables from helmwave to your helm chart templates. You should use helmwave to render values of your chart.

Overriding templater

You can override used templater using renderer option in values

Sprig

If you've ever written helm charts, then you're already familiar with it.

Gomplate

Gomplate is a template renderer which supports a growing list of datasources, such as JSON (including EJSON - encrypted JSON), YAML, AWS EC2 metadata, BoltDB, Hashicorp Consul and Hashicorp Vault secrets.

Custom

Custom functions will work with any template engine.

toYaml

The toYaml function allows you to convert a value to YAML string. When has failed, the template rendering will fail with an error message.

{{ $yaml :=  $value | toYaml }}

fromYaml

The fromYaml function allows you to convert a YAML string to a value. When has failed, the template rendering will fail with an error message.

{{ $value :=  $yamlString | fromYaml }}

exec

The exec function allows you to run a command, returning the stdout of the command. When the command fails, the template rendering will fail with an error message.

{{ $cmdOutpot := exec "./mycmd" (list "arg1" "arg2" "--flag1") }}

setValueAtPath

The setValueAtPath function allows you to set a value at a path. When has failed, the template rendering will fail with an error message.

{{ $value | setValueAtPath "path.key" $newValue }}

requiredEnv

The requiredEnv function allows you to declare a particular environment variable as required for template rendering. If the environment variable is unset or empty, the template rendering will fail with an error message.

{{ $envValue := requiredEnv "envName" }}

If the environment variable value starts with '/' (forward slash) and Git for Windows is used, you must set MSYS_NO_PATHCONV=1 to preserve values as-is, or the environment variable value will be prefixed with the C:\Program Files\Git. Reference

required

The required function returns the second argument as-is only if it is not empty. If empty, the template rendering will fail with an error message containing the first argument.

{{ $requiredValue :=  $value | required "value not set" }}

readFile

The readFile function allows you to read a file and return its content as the function output. On failure, the template rendering will fail with an error message.

{{ $fileContent := readFile "./myfile" }}

get

The get function allows you to get a value at a path. When defaultValue not set it will return nil. On failure, the template rendering will fail with an error message.

{{ $Getvalue := $value | get "path.key" "defaultValue" }}

hasKey

The hasKey function allows you to check if key exists in the value. Dot-separated key will recurse. On failure, the template rendering will fail with an error message.

{{ $exists := $value | hasKey "path.key" }}

getPlan

Introduced in v0.43.0

The getPlan function returns the entire plan configuration as a map. This allows values to access any release's store field or other configuration.

{{ $plan := getPlan }}
{{ $redis := index $plan.releases 0 }}
{{ $redis.store.someKey }}

example

getValues

Introduced in v0.36.0

Enhanced in v0.43.0

The getValues function returns the contents of a values file parsed as YAML. On failure, the template rendering will fail with an error message.

Single argument - get values from another values file of the current release:

{{ $common := getValues "common.yaml" }}

Two arguments - get rendered values from a depending release (v0.43.0+). The release must be declared in depends_on.

{{ $redisValues := getValues "redis@my-namespace" "values.yaml" }}

example

getTags

Introduced in v0.43.0

The getTags function returns the tags of the current build as a list: the tags passed via --tags, or every tag in the plan when none were passed.

Useful to render values differently depending on what is being deployed:

{{- if getTags | len | eq 1 | and (getTags | first | eq "crd") }}
prometheusOperator:
  enabled: false
{{- end }}

getManifests

Introduced in v0.43.0

The getManifests function returns rendered manifests of a depending release as an array of objects. The release must be declared in depends_on.

{{ $manifests := getManifests "redis@my-namespace" }}
{{- range $manifests }}
{{- if eq .kind "Secret" }}
redis_password: {{ index .data "redis-password" }}
{{- end }}
{{- end }}

example