Skip to content

Helm converts integers to scientific notation even when quoted #3001

Closed

Description

@beeradb

What happened

Our build uses git commit hashes for container tags during the build and then runs our helm chart tests using all the build containers for that specific commit. We had an instance this morning where the tag was completely numeric. As such, the tag got converted to scientific notation.

I was able to find some documentation on this at https://docs.helm.sh/chart_best_practices/#make-types-clear (thanks!), but I was surprised to find out that the behavior persists even when quoting the value when installing the chart via the CLI.

Reproducing this is simple, just run:

helm install stable/minio --set imageTag="1234567"

And observe the following status on the resulting pod: "InvalidImageName"

What I expected to happen

I understand type coercion between all these sources can be difficult. However, I would propose that if the value is quoted when using the CLI, it should be treated as a string and not an integer.

Activity

  1. changed the title [-]Helm converts intigers to scientific notation even when quoted[/-] [+]Helm converts integers to scientific notation even when quoted[/+] on Oct 4, 2017
  2. bacongobbler commented on Oct 4, 2017

    @bacongobbler
    Member

    closing as a duplicate of #1707.

  3. jesselang commented on Feb 13, 2018

    @jesselang

    Related to #3155

  4. ghost added a commit that references this issue on Aug 10, 2023
  5. shivanshs9 commented on Mar 1, 2025

    @shivanshs9

    Sorry to necro this thread, but here's a small Helm function to handle the edge-cases:

    {{/*
    Because of Helm bug (https://github.com/helm/helm/issues/3001), Helm converts
    int value to float64 implictly, like 2748336 becomes 2.748336e+06.
    This breaks the output even when using quote to render.
    
    Use this function when you want to get the string value only.
    It handles the case when the value is string itself as well.
    Parameters: is string/number
    */}}
    {{- define "stringOrNumber" -}}
    {{- if kindIs "string" . }}
      {{- print . -}}
    {{- else  }}
      {{- int64 . | toString -}}
    {{- end -}}
    {{- end -}}
    
    

    Simply use it in your template yamls like so:

    app.kubernetes.io/version: {{ include "stringOrNumber" .Values.global.version | quote }}
    

    ^ handles both these cases:
    global.version = 2748336
    global.version = "2748336"

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions