Skip to content

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

Closed

Description

@fishy

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.

Activity

  1. added a commit that references this issue on Jun 27, 2022
  2. github-actions commented on Oct 5, 2022

    @github-actions

    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.

  3. fishy commented on Oct 6, 2022

    @fishy
    Author

    this is still an issue.

  4. added
    help wanted
    bug
    and removed on Oct 11, 2022
  5. joejulian commented on Oct 11, 2022

    @joejulian
    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 }}
    
  6. fishy commented on Oct 11, 2022

    @fishy
    Author

    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.

  7. joejulian commented on Oct 11, 2022

    @joejulian
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions