Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting large int64 values in values.yaml converts them to float64 #11130

Closed
schnerring opened this issue Jul 9, 2022 · 8 comments
Closed

Setting large int64 values in values.yaml converts them to float64 #11130

schnerring opened this issue Jul 9, 2022 · 8 comments
Labels
bug Categorizes issue or PR as related to a bug. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. Stale

Comments

@schnerring
Copy link

schnerring commented Jul 9, 2022

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
@bacongobbler
Copy link
Member

related: #11045

@github-actions
Copy link

github-actions bot commented Oct 9, 2022

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 github-actions bot added the Stale label Oct 9, 2022
@dmekhov
Copy link

dmekhov commented Oct 10, 2022

it's still actual

@github-actions github-actions bot removed the Stale label Oct 11, 2022
@ryanotella
Copy link

ryanotella commented Oct 21, 2022

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"

@github-actions
Copy link

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 github-actions bot added the Stale label Jan 20, 2023
@schnerring
Copy link
Author

unstale

@github-actions github-actions bot removed the Stale label Jan 21, 2023
@joejulian
Copy link
Contributor

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 kubernetes-sigs/yaml#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.

@github-actions
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Categorizes issue or PR as related to a bug. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. Stale
Projects
None yet
Development

No branches or pull requests

5 participants