Skip to content

Instantly share code, notes, and snippets.

@avbelyaev
Created December 29, 2020 00:10
Show Gist options
  • Save avbelyaev/fd43776b66730682f951e0836588f072 to your computer and use it in GitHub Desktop.
Save avbelyaev/fd43776b66730682f951e0836588f072 to your computer and use it in GitHub Desktop.
Helm quotes

Given the following template template.yml:

data:
  FOO_BAR: {{ .Values.foo.bar | quote }}

And the following value-file values.yaml:

foo:
  bar: 2e0

Then it's interpolated into:

data:
  FOO_BAR: "2"

full example:

$ cat templates/configmap.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-configmap
data:
  FOO_BAR: {{ .Values.foo.bar | quote }}
 
$ cat values/qa.yaml 
foo:
  bar: 2e0
 
$ helm package .
Successfully packaged chart and saved it to: test-1.0.3.tgz
 
$ helm upgrade --install test test-1.0.3.tgz --values values/qa.yaml --dry-run --debug
history.go:52: [debug] getting history for release test
Release "test" does not exist. Installing it now.
install.go:172: [debug] Original chart version: ""
install.go:189: [debug] CHART PATH: test-1.0.3.tgz
 
NAME: test
LAST DEPLOYED: Tue Nov 10 17:16:45 2020
NAMESPACE: anthony
STATUS: pending-install
REVISION: 1
TEST SUITE: None
USER-SUPPLIED VALUES:
foo:
  bar: 2
 
COMPUTED VALUES:
foo:
  bar: 2
 
HOOKS:
MANIFEST:
---
# Source: test/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: test-configmap
data:
  FOO_BAR: "2"

and e.g. the following:

foo:
  bar: 2e6

Then it's interpolated into:

data:
  FOO_BAR: "2000000"

Even though 2e0 seems to be quite a simple value without any escape/spec chars, Helm (actually, yaml parser inside) confuses it for float with E-notation.

Always use quotes to prevent unexpected behavior like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment