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

Precision loss when handling large int64 numbers inside yaml config #11045

Closed
fishy opened this issue Jun 15, 2022 · 5 comments
Closed

Precision loss when handling large int64 numbers inside yaml config #11045

fishy opened this issue Jun 15, 2022 · 5 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.

Comments

@fishy
Copy link

fishy commented Jun 15, 2022

This is a minimal example to demonstrate the bug:

$ helm version
version.BuildInfo{Version:"v3.9.0", GitCommit:"7ceeda6c585217a19a1131663d8cd1f7d641b2a7", GitTreeState:"clean", GoVersion:"go1.17.5"}
$ helm create example
Creating example
$ sed -i "s/replicaCount: 1/replicaCount: 9123456789012345678/" example/values.yaml
$ helm template example -f example/values.yaml | grep replicas
  replicas: 9.123456789012346e+18

the desired replicaCount is 9123456789012345678 in values.yaml, but it becomes 9.123456789012346e+18 (aka 9123456789012346000) in the final rendered yaml.

fishy added a commit to fishy/baseplate.go that referenced this issue Jun 15, 2022
This is a helper type used in yaml configs, mainly to deal with a helm
bug [1] that large int64 values in yaml config could have precision loss
when going through helm, so we would want to put the string versions of
them in yaml to preserve the precision.

[1]: helm/helm#11045
fishy added a commit to fishy/baseplate.go that referenced this issue Jun 17, 2022
This is a helper type to be used in yaml configs, mainly to deal with a
helm bug [1] that large int64 values in yaml config could have precision
loss when going through helm, so we would want to put the string
versions of them in yaml to preserve the precision.

[1]: helm/helm#11045
fishy added a commit to reddit/baseplate.go that referenced this issue Jun 27, 2022
This is a helper type to be used in yaml configs, mainly to deal with a
helm bug [1] that large int64 values in yaml config could have precision
loss when going through helm, so we would want to put the string
versions of them in yaml to preserve the precision.

[1]: helm/helm#11045
@github-actions
Copy link

github-actions bot commented Oct 5, 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 5, 2022
@fishy
Copy link
Author

fishy commented Oct 6, 2022

this is still an issue.

@github-actions github-actions bot removed the Stale label Oct 7, 2022
@joejulian joejulian added help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. bug Categorizes issue or PR as related to a bug. and removed question/support labels Oct 11, 2022
@joejulian
Copy link
Contributor

This has to do with the go templating float precision. You can solve this yourself using printf:

replicas: {{ printf "%32.0f" .Values.replicaCount | trim }}

@fishy
Copy link
Author

fishy commented Oct 11, 2022

This has to do with the go templating float precision. You can solve this yourself using printf:

replicas: {{ printf "%32.0f" .Values.replicaCount | trim }}

while that workaround works for some cases, it doesn't really work for other cases.

for example, we have a helm template to generate yaml config files to be mounted to our pods, and the value files could be some thing like this:

otherKey: otherValue

config:
  foo: bar
  idDenyList:
    - 9123456789012345678
    - <other really big int64 ids>

...

and when we use helm to generate the config.yaml file out of .Values.config, the precision loss will happen and we got ids in the config that will match the wrong ids.

@joejulian
Copy link
Contributor

Please file an issue with golang at https://github.com/golang/go/issues. Prefix your issue with "x/text:" in the subject line, so it is easy to find.

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.
Projects
None yet
Development

No branches or pull requests

3 participants