In my values.yaml file for helm, I am trying to create a value with quotes but when I run it, it gives a different result
values.yaml
annotation: '"ports": {"88":"sandbox-backendconfig"}}'
{{ .Values.annotation }}
what shows when I do dry run
"ports": {"88":"sandbox-backendconfig"}}
how can I make the single quotes around it show also
A chart’s values.yaml file A values file supplied by helm install -f or helm upgrade -f The values passed to a --set or --set-string flag on helm install or helm upgrade When designing the structure of your values, keep in mind that users of your chart may want to override them via either the -f flag or with the --set option.
Sign in to your account YAML officially supports " within double-quoted string values, but Helm actually chokes when presented with one. In a deployment.yaml, present a string value that contains escaped double quotes. someKey: "This string has some "double-quoted" text."
Have you tried { { .Values.annotation | quote }} ? When the Helm YAML parser reads in the values.yaml file, it sees that the value of annotation: is a single-quoted string and so it keeps the contents of the value without the outer quotes. As the YAML spec suggests, you can include single quotes inside a single-quoted string by doubling the quote.
The Keycloak Helm chart reads the value as a string and then processes the string as a Helm template. Unfortunately, it is not possible to include newline characters in value strings on the command line with escape characters (e.g. n) like you might expect.
When the Helm YAML parser reads in the values.yaml
file, it sees that the value of annotation:
is a single-quoted string and so it keeps the contents of the value without the outer quotes.
As the YAML spec suggests, you can include single quotes inside a single-quoted string by doubling the quote. It might be more familiar to make this a double-quoted string and use backslash escaping. A third possibility is to make this into a block scalar, which would put the value on a separate line, but wouldn't require any escaping at all.
annotation: '''"ports": {"88":"sandbox-backendconfig"}}'''
annotation: "'\"ports\": {\"88\":\"sandbox-backendconfig\"}}'"
annotation: >-
'"ports": {"88":"sandbox-backendconfig"}}'
I'm not sure what context you're trying to use this in, but if this is a more structured format, you can use Helm's toYaml
or toJson
functions to build up the annotation value for you.
# values.yaml
ports:
'88': sandbox-backendconfig
# templates/some-resource.yaml
annotations: {{ printf "\"ports\": %s" (toJson .Values.ports) | squote }}
Check the method below,
Values.yaml
annotation: '"ports": {"88":"sandbox-backendconfig"}}'
Template
{{ .Values.annotation | squote }}
This should resolve your issue.
squote
will put single quotes around the deduced value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With