Setting large `int64` values in `values.yaml` converts them to `float64`
I've already mentioned this here but since the issue is closed I thought it was a good idea to open a new issue.
Output of helm version:
version.BuildInfo{Version:"v3.8.2", GitCommit:"6e3701edea09e5d55a8ca2aae03a68917630e91b", GitTreeState:"clean", GoVersion:"go1.17.5"}
To reproduce the issue, create the following template.
helm create foo
cd foo
cat << EOF > templates/foo.yaml
value: {{ .Values.foo }}
type: {{ typeOf .Values.foo }}
EOF
Using --set, everything works as expected:
$ helm template foo . --set foo=10485760 --show-only templates/foo.yaml
---
# Source: foo/templates/foo.yaml
value: 10485760
type: int64
However, setting the value in values.yaml:
foo: 10485760
... changes the behavior:
$ helm template foo . --show-only templates/foo.yaml
---
# Source: foo/templates/foo.yaml
value: 1.048576e+07
type: float64
A workaround is multiplying the value with 1 in the template:
value: {{ mul .Values.foo 1 }}
This changes the rendered output to the following (note the type still is float64):
---
# Source: foo/templates/foo.yaml
value: 10485760
type: float64
related: https://github.com/helm/helm/issues/11045
This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.
it's still actual
This is still an issue, but there are work-arounds for template authors who cannot guarantee the quoting semantics of input YAML. For string values which are sometimes integers, it seems it's necessary to avoid that standard Go template string casting - using toJson or toYaml is one option.
For values with are always integers:
{{ .Values.alwaysInteger | int64 | quote }}
For values which are sometimes integers (Hashes, IDs etc):
{{ .Values.sometimesInteger | toJson | trimAll "\"" | quote }}
Test
values.yaml
samples:
alwaysIntegerBare: 325255969
alwaysIntegerQuoted: "325255969"
sometimesIntegerBare: 325a255969
sometimesIntegerQuoted: "325a255969"
template.yaml
# int64 | quote
# {{ .Values.samples.alwaysIntegerBare | int64 | quote }}
# {{ .Values.samples.alwaysIntegerQuoted | int64 | quote }}
# {{ .Values.samples.sometimesIntegerBare | int64 | quote }}
# {{ .Values.samples.sometimesIntegerQuoted | int64 | quote }}
# toJson | trimAll "\"" | quote
# {{ .Values.samples.alwaysIntegerBare | toJson | trimAll "\"" | quote }}
# {{ .Values.samples.alwaysIntegerQuoted | toJson | trimAll "\"" | quote }}
# {{ .Values.samples.sometimesIntegerBare | toJson | trimAll "\"" | quote }}
# {{ .Values.samples.sometimesIntegerQuoted | toJson | trimAll "\"" | quote }}
Output
# int64 | quote
# "325255969"
# "325255969"
# "0"
# "0"
# toJson | trimAll "\"" | quote
# "325255969"
# "325255969"
# "325a255969"
# "325a255969"
This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.
unstale
To everyone who finds this issue, not just the OP:
This is a duplicate of #9362. As stated in that issue, it's a problem that stems from https://github.com/kubernetes-sigs/yaml/issues/45. Also as stated, changing this in helm would require a Helm Improvement Proposal because it's not as straightforward as replacing the yaml library. Give the original issue a look and consider helping write up a HIP. The yaml landscape in go has changed since then, though I don't know if compatibility has gotten any better overall.
Also, feel free to give feedback on the upstream issue, or contribute a fix if you're able.
This issue has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.