Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding single quotes to helm value

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

like image 868
King Avatar asked Nov 30 '19 20:11

King


People also ask

How do I set the values of a helm chart?

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.

Does helm support double-quoted string values?

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."

How to include single quotes in a YAML string?

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.

How do I include newline characters in value strings in helm?

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.


2 Answers

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 }}
like image 148
David Maze Avatar answered Nov 15 '22 11:11

David Maze


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.

like image 32
SHC Avatar answered Nov 15 '22 10:11

SHC