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" }}

getValues

Introduced in v0.36.0

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

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

example