Skip to main content
Version: 0.37.0

Supported Templating Languages Enterprise

The following templating languages are supported:

  • envsubst (default)
  • templating

Declare the templating language to be used to render the template by setting spec.renderType.

Envsubst

envsubst, which is short for 'environment substitution', uses envsubst for rendering. This templating format is used by clusterctl.

Variables can be set for rendering into the template in the ${VAR_NAME} syntax.

Supported Functions

ExpressionMeaning
${var}Value of $var
${#var}String length of $var
${var^}Uppercase first character of $var
${var^^}Uppercase all characters in $var
${var,}Lowercase first character of $var
${var,,}Lowercase all characters in $var
${var:n}Offset $var n characters from start
${var:n:len}Offset $var n characters with max length of len
${var#pattern}Strip shortest pattern match from start
${var##pattern}Strip longest pattern match from start
${var%pattern}Strip shortest pattern match from end
${var%%pattern}Strip longest pattern match from end
${var-default}If $var is not set, evaluate expression as $default
${var:-default}If $var is not set or is empty, evaluate expression as $default
${var=default}If $var is not set, evaluate expression as $default
${var:=default}If $var is not set or is empty, evaluate expression as $default
${var/pattern/replacement}Replace as few pattern matches as possible with replacement
${var//pattern/replacement}Replace as many pattern matches as possible with replacement
${var/#pattern/replacement}Replace pattern match with replacement from $var start
${var/%pattern/replacement}Replace pattern match with replacement from $var end

Templating

Templating uses text/templating for rendering, using go-templating style syntax {{ .params.CLUSTER_NAME }} where params are provided by the .params variable. Template functions can also be used with the syntax {{ .params.CLUSTER_NAME | FUNCTION }}.

Supported Functions

As taken (from the Sprig library)

Function TypeFunctions
String Functionstrim, wrap, randAlpha, plural
String List FunctionssplitList, sortAlpha
Integer Math Functionsadd, max, mul
Integer Slice Functionsuntil, untilStep
Float Math Functionsaddf, maxf, mulf
Date Functionsnow, date
Defaults Functionsdefault, empty, coalesce, fromJson, toJson, toPrettyJson, toRawJson, ternary
Encoding Functionsb64enc, b64dec
Lists and List Functionslist, first, uniq
Dictionaries and Dict Functionsget, set, dict, hasKey, pluck, dig, deepCopy
Type Conversion Functionsatoi, int64, toString
Flow Control Functionsfail
UUID Functionsuuidv4
Version Comparison Functionssemver, semverCompare
ReflectiontypeOf, kindIs, typeIsLike

Custom Delimiters

The default delimiters for renderType: templating are {{ and }}. These can be changed by setting the templates.weave.works/delimiters annotation on the template. For example:

  • templates.weave.works/delimiters: "{{,}}" - default
  • templates.weave.works/delimiters: "${{,}}"
    • Use ${{ and }}, for example "${{ .params.CLUSTER_NAME }}"
    • Useful as {{ in yaml is invalid syntax and needs to be quoted. If you need to provide a un-quoted number value like replicas: 3 you should use these delimiters.
      • replicas: {{ .params.REPLICAS }} Invalid yaml
      • replicas: "{{ .params.REPLICAS }}" Valid yaml, incorrect type. The type is a string not a number and will fail validation.
      • replicas: ${{ .params.REPLICAS }} Valid yaml and correct number type.
  • templates.weave.works/delimiters: "<<,>>"
    • Use << and >>, for example << .params.CLUSTER_NAME >>
    • Useful if you are nesting templates and need to differentiate between the delimiters used in the inner and outer templates.