helm icon indicating copy to clipboard operation
helm copied to clipboard

Setting large `int64` values in `values.yaml` converts them to `float64`

Open schnerring opened this issue 3 years ago • 7 comments

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

schnerring avatar Jul 09 '22 16:07 schnerring

related: https://github.com/helm/helm/issues/11045

bacongobbler avatar Jul 09 '22 19:07 bacongobbler

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.

github-actions[bot] avatar Oct 09 '22 00:10 github-actions[bot]

it's still actual

dmekhov avatar Oct 10 '22 06:10 dmekhov

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"

ryanotella avatar Oct 21 '22 01:10 ryanotella

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.

github-actions[bot] avatar Jan 20 '23 00:01 github-actions[bot]

unstale

schnerring avatar Jan 20 '23 15:01 schnerring

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.

joejulian avatar Jan 27 '23 20:01 joejulian

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.

github-actions[bot] avatar Apr 28 '23 00:04 github-actions[bot]