-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Description
What would you like to be added?
Add an ability to set Delims (https://pkg.go.dev/text/template#Template.Delims) in go templates.
I think it could be done using cli-flags or something like that.
All we need is add Delims function after all New functions (like here:
Line 289 in cb78d7f
| if _, err := t.New(filename).Parse(r.tpl); err != nil { |
It could be something like that but without hardcoded values
t.New(filename).Delims("[%", "%]").Parse(r.tpl)Why is this needed?
When we have several layers of templating (something like jinja2+helm) it is required to use some ugly approaches to escape helm templating while files are templating by another engine first.
I know that jinja2 can change its own delimiters but it is just an example - it could be another engine which also uses {{ and }} but without ability to change them.
Another example with PrometheusRule.
We have to do something like that:
- alert: GitlabRunnerMissingExportMount
expr: gitlab_runner_missing_export
for: 5m
labels:
gitlabrunner: count
annotations:
summary: |-
GitLab Runner missing /export mountpoint
description: |-
GitLab Runner '{{ printf "{{ $labels.gitlab_runner_name }}" }}' does not have '/export' filesystem mounted.With custom delimiters it could be just:
- alert: GitlabRunnerMissingExportMount
expr: gitlab_runner_missing_export
for: 5m
labels:
gitlabrunner: count
annotations:
summary: |-
GitLab Runner missing /export mountpoint
description: |-
GitLab Runner '{{ $labels.gitlab_runner_name }}' does not have '/export' filesystem mounted.And the whole value would be passed to manifest to allow prometheus use it as is.