New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can Helm support to ignore {{expr}} which is just for configuration but not render? #2798
Comments
I have a similar use case to have a go style template in a config map. Right now helm is trying to evaluate the template and causing errors in the config map. |
I ran into this same/similar problem awhile ago and solved it by embedding including the alerting rules as separate files, as
AFAIK it is extremely difficult to escape |
The way to escape double curly brackets in Go templates is to use |
I'm going to close this issue as we have two separate solutions to the problem, but please re-open if this hasn't been resolved. |
@bacongobbler Hello Matthew, I've been fighting with how to escape curly braces in a Helm template in markdown. Maybe I'm not understanding your solution. How would I render this correctly?
|
@bacongobbler I found the solution. I need to use both pre and |
Could you please show an example? |
A viable hack is to let Helm render the template as a raw string. Note the opening and closing curly bracket with a backtick: # Excerpt from a Prometheus Alertmanager yaml
receivers:
- name: slack-receiver
slack_configs:
- text: |-
{{`{{ range .Alerts }}
*Alert:* {{ .Annotations.summary }}
{{ end }}`}} |
Thank you very much. That solved the big problem |
you can also use printf for that:
|
it works, thx |
This didn't work for me.
|
I can add to the chorus of confirmations that this still works. And you may need it to get this to work: https://www.vaultproject.io/docs/platform/k8s/injector/examples/
|
You can add
and will template properly |
Unfortunately this does not work using |
Awesome!!!. It worked. Thanks. |
Signed-off-by: Roland T. Lichti <rlichti@redhat.com>
That works but how can we make it run for prometheus unit test? Any clues? |
Hi, Just for the persons how reach here and finding the way to use literal like "{{ xxxxx }}" in your helm value file. The snippet below solved my issue. labels:
sink_name: loki_syslog
#Below key useed printf() to escape Helm interprets {{ }}
message: >-
{{ printf "{{ message }}" }}
hostname: >-
{{ printf "{{ hostname }}" }} The helm rendered output look like this labels:
hostname: '{{ hostname }}'
message: '{{ message }}'
sink_name: loki_syslog |
So, I want to add my two cents here on how to get the backtick in the raw string. It is possible, and I have found a way to do it. For example:
I want the label content in backticks, so:
Basically, where you want backticks just add |
The printf approach worked fine for me, I just wanted to add that if you need to print curly braces it's not gonna be valid yaml if not quoted. |
Anyone know how to escape a `sign? example `kubeflow` |
IMHO this thread was closed to early. Just because a workaround was found for something that should be enabled in helm itself via some metadata like {{ignoreTemplateStart}}
...
{{ignoreTemplateEnd}} Where both of this evaluate to "" ofc. Yes - there are workarounds but the original creator of this thread asked for a configuration for helm not a workaround for strings to trick helm. And I think it would be a great addition. Its a feature request and should also be considered as such. |
@rufreakde Since this is actually just how the go template engine works, perhaps file an issue there. The solutions offered in this thread are the only ways to do it with go templates. |
helm could disable the go templating when it find a flag "ignoreTemplateStart" It should be not too difficult and it will sove lots of problems for any jinja configmap |
there is a better workaround and is using toJson apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-dashboards
data:
compute.json:
{{ .Files.Get "dashboards/compute.json" | toJson | indent 4 }} this avoids Go rendering the content of compute.json and puts the content there with the "{{variables}}" and everything. be aware. Confimaps have a limitation of 1 MB. So do not abuse this. Otherwise, consider putting them on a repo and use something like this for GitLab (you can do it for any external URL / repo): dashboards:
default:
your-dashboard-at-gitlab:
url: "https://gitlab.yourdomain.com/api/v4/projects/9999/repository/files/yourfolder%2Fcompute.json/raw?ref=main" |
There is a use case: deploy Prometheus as StatefulSet and config alerting-rules as ConfigMap.
alerting-rules can take more detail on here: https://prometheus.io/docs/alerting/rules/#alerting-rules
it looks like:
Can Helm support to ignore {{expr}} which is just for configuration but not render?
The text was updated successfully, but these errors were encountered: