What is the difference between the quote function vs using quotation marks?

7/27/2019

Why should I prefer this:

args: [{{ Values.somevalue | quote }}]

to this

args: ["{{ Values.somevalue }}"]

I feel like I read about the difference somewhere but I can find anything about what "" do in the docs, they only mention | quote. But if the two lines I wrote above are equivalent, why would they bother creating the quote function in the first place?

-- Dan
kubernetes-helm

1 Answer

7/28/2019

It looks like quote's actual interesting property is that it can take arbitrarily many parameters, quotes each of them, and puts a single space between each

{{ $v := "foo" }}
{{ quote $v "bar" "baz" }}
{{/* "foo" "bar" "baz" */}}

If you had a need to include it in an extended pipeline, the function form could be convenient.

{{ list (quote $x) | toJson }}
{{/* ["\"foo\""] */}}

But otherwise it doesn't seem to do anything special, and in particular doesn't do any quote escaping.

{{ $x := "foo" -}}
{{/* All produce "foo": */}}
"{{ $x }}"
{{ $x | quote }}
{{ $x | printf "\"%s\"" }}

{{/* Not what you hoped for: */}}
{{ $y := "bar\", \"baz" }}
{{ $y | quote }}
{{/* "bar", "baz" */}}

(FWIW I almost always {{ ... | quote }}; but I think when I started learning Helm I also expected this to actually do escaping and it doesn't.)

-- David Maze
Source: StackOverflow