Skip to content

Integers bigger 1M are being converted into exponential form #12195

Closed

Description

@mearsten

Output of helm version:

version.BuildInfo{Version:"v3.12.1", GitCommit:"f32a527a060157990e2aa86bf45010dfb3cc8b8d", GitTreeState:"clean", GoVersion:"go1.20.4"}

Steps to reproduce:

1) values.yaml:

someVarOne: 999999
someVarTwo: 1000000

2) templates/configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: whatever
data:
  ONE: {{ .Values.someVarOne }}
  TWO: {{ .Values.someVarTwo }}
  TWO_Q: {{ .Values.someVarTwo | quote }}

3) render that

% helm template .
---
# Source: whatever/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: whatever
data:
  ONE: 999999
  TWO: 1e+06
  TWO_Q: "1e+06"

Expected behavior:

% helm template .
---
# Source: whatever/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: whatever
data:
  ONE: 999999
  TWO: 1000000
  TWO_Q: "1000000"

Activity

  1. gjenkins8 commented on Jul 18, 2023

    @gjenkins8
    Member

    Some part of the yaml parsing seems to be converting the seven-digit value into a float:

    https://helm-playground.com/#t=LTBQG9wAgOgNQIYBsCuBTAzjDB7AtmogE4AqA7jlAD5QAORAlgHYAuAZlAEQCkJnUAXwERo8ZOiy4CxcpRr1m7Ltwz8hoIA&v=LQhQGcHsFsFMDUCGAnA8gO1gLgAQE4DCIYEUAVAd0lwEIaBLdAFxwEYAGTroA

    template:

    --
    {{ .Values.someVarTwo | printf "%T" }}
    {{ .Values.someVarTwo | printf "%s" }}
    
    

    values.yaml

    ---
    someVarTwo: !!int 1000000
    

    output:

    --
    float64
    %!s(float64=1e+06)
    

    (unsure which part)

  2. gjenkins8 commented on Jul 19, 2023

    @gjenkins8
    Member

    I would suggest, that unless you plan on doing numeric operations on these values, simply represent them as a string:

    someVarOne: "999999"
    someVarTwo: "1000000"
    

    (and if you do plan on doing numeric operations, use casts/printf to format the numbers as expected)

    Helm itself, I don't think will be converting int -> float here. Rather, one of the libraries/frameworks that Helm uses to parse yaml. First, it would need to be identified where/what this conversion is happening. Then it would need to be understood if this conversion is the expected behavior. Then finally an issue raised upstream (presumably), a fix issued, then Helm would need to incorporate that fix. If you want to take on that investigation, I can point to the code where Helm looks to parse/handle values.

  3. mearsten commented on Jul 20, 2023

    @mearsten
    Author

    Thank you, but the place can be found easily. It's here:

    case f.Name == "values.yaml":
    c.Values = make(map[string]interface{})
    if err := yaml.Unmarshal(f.Data, &c.Values); err != nil {

    The guilty package is sigs.k8s.io/yaml, v1.3.0, released on Sep 23, 2021. It looks abandoned and I doubt it's going to be fixed.

    The issue has somewhat bigger scope because we observe very questionable behavior. And this particular package is just an implementation. For example, that package can be replaced with another one.

    simply represent them as a string:

    I do. And very unhappy with that. Too many workarounds, too many implicit stuff. Not only in helm.

  4. mearsten commented on Jul 20, 2023

    @mearsten
    Author

    I just checked https://github.com/go-yaml/yaml as a drop-in replacement. Works fine but should be tested thoroughly because there are some minor differences (yes/no, on/off, octals).

  5. github-actions commented on Nov 2, 2023

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

  6. stavros-k commented on Nov 2, 2023

    @stavros-k

    Not stale

  7. github-actions commented on Feb 1, 2024

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

  8. ksonney commented on Mar 26, 2024

    @ksonney

    Not complete, still an issue as of Helm 3.14.3

  9. dmartzol commented on May 28, 2024

    @dmartzol

    Still an issue as of Helm 3.15.1

  10. patsevanton commented on Sep 10, 2024

    @patsevanton

    How are you fixed issue?

  11. patsevanton commented on Sep 10, 2024

    @patsevanton

    workaround:

          {{- if .Values.relay.processing.kafkaConfig.messageMaxBytes }}
          - name: "message.max.bytes"
            value: {{ int64 .Values.relay.processing.kafkaConfig.messageMaxBytes | quote }}
          {{- end }}
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions