Custom Template
Example https://github.com/buttahtoast/helmize/tree/main/examples/example-customization
You can implement your own identifier template, if ours is not practical for you. Let’s see how it’s done.
General configuration for Identifiers.
After the Identifier template is executed, the content in $.wagon.id
is considered as the result of the template and is used for each file. Should the value of this field be unset or empty, the filename of the current executed file is used. You should avoid using the filename because it may result in unwanted behavior if you have multi yaml files. The value for $.wagon.id
is directly set on the context eg.
{{- define "customization.identifier.template" -}}
{{- $_ := set $.wagon "id" "sample" -}}
{{- end -}}
The following return values (YAML Print) are considered:
-
errors
-<slice>
A list of errors which occured during identifier evaluation. The error will make helmize fail with your error message. -
debug
-<slice>
Debug output which can be seen in summary (If something isn’t doing what you thought it does).
The Values are not required to be returned, only if you would like to invoke error/debug messages.
The returned YAML is validated, if the YAML is not valid an error is thrown:
Template customization.identifier.template returned invalid YAML (error converting YAML to JSON: yaml: line 1: did not find expected key):
debug: []
errors: []debug: []
errors: []
In this case your printed YAML from the template is wrong, please fix.
Here’s a minimalstic Post Renderer template to get started.
{{- define "customization.identifier.template" -}}
{{- $return := dict "errors" list "debug" list -}}
{{/* Identifier Logic */}}
...
{{/* Return Metadata (Errors/Debug) */}}
{{- printf "%s" (toYaml $return) -}}
{{- end -}}
An Identifier template receives the following context (Values Change per File):
Let’s create a new Render template which only renders resources, if a specific annotation is set.
Once the identifier template is created we need to reference in the configuration:
identifier_template: "customization.identifier.template"
conditions:
- name: "resources"
allow_root: true
- name: "additional"
allow_root: true