Skip to content

--set parses number only values as float64 #1707

Closed

Description

@databus23

I just noticed that something like helm install --set tag=20161216 ends up in scientific notation in the template and thats because {{ typeOf .Value.tag }} yields float64.

Thats even true for small integers like helm install --set tag=1 --> float64.

This is happening with helm 2.1.0

Activity

  1. changed the title [-]--set [/-] [+]--set parses big ints as float64[/+] on Dec 17, 2016
  2. changed the title [-]--set parses big ints as float64[/-] [+]--set parses number only values as float64[/+] on Dec 17, 2016
  3. technosophos commented on Dec 19, 2016

    @technosophos
    Member

    Does it work differently if you do --set tag=\"1\"?

  4. technosophos commented on Dec 20, 2016

    @technosophos
    Member

    Thanks to @chancez we know the exact problem: During the conversions to and from JSON done by ghodss/yaml, integers are being cast into float64s to represent Javascript's numeric type. This is causing all integers above a certain value to be represented in scientific notation.

  5. ipedrazas commented on Jan 5, 2017

    @ipedrazas
    Contributor

    I've been bitten by the same problem. The way of getting over the hump (or the bug) is to do this:

    --set bignumber=\\"a185576882739235744\\"

  6. technosophos commented on Feb 15, 2017

    @technosophos
    Member

    Another workaround we have used is to do stuff like this:

    --set port=":1234567"
    

    Then in the template:

    {{ .Values.port | replace ":" "" }}
    
  7. databus23 commented on Feb 15, 2017

    @databus23
    ContributorAuthor

    Yuck! 😷

  8. added
    help wanted
    on Feb 17, 2017
  9. jemc commented on Aug 14, 2017

    @jemc

    This is a heck of a pain, and @ipedrazas' workaround doesn't seem to work for me, or any other combination of quoting/escaping I've tried.

    I'm not quite willing yet to swallow my pride and try @technosophos' ugly hack...

    For now I'm hacking around this by expanding my deploy script to write the data as yaml to a temporary file and use that as a -f argument.

  10. Smana commented on Aug 31, 2017

    @Smana

    I'm facing the same issue from time to time for the image tag.
    I'll try to use one of these workaround. I hope it will be fixed soon :)

  11. added a commit that references this issue on Sep 26, 2017
  12. holybit commented on Oct 5, 2017

    @holybit

    In my case, seeing this below on --set image.tag=5997578:

    $ kubetctl describe po msj-treasure-map-msj-treasure-map-192172122-dnb80
    ...
    Events:
      Type     Reason         Age               From                                    Message
      ----     ------         ----              ----                                    -------
      Normal   Scheduled      1m                default-scheduler                       Successfully assigned msj-treasure-map-msj-treasure-map-192172122-dnb80 to ip-10-253-13-113.ec2.internal
      Warning  InspectFailed  15s (x9 over 1m)  kubelet, ip-10-253-13-113.ec2.internal  Failed to apply default image tag "596297932419.dkr.ecr.us-east-1.amazonaws.com/msj-trmap-uwsgi:5.997578e+06": couldn't parse image reference "596297932419.dkr.ecr.us-east-1.amazonaws.com/msj-trmap-uwsgi:5.997578e+06": invalid reference format
      Warning  InspectFailed  15s (x9 over 1m)  kubelet, ip-10-253-13-113.ec2.internal  Failed to apply default image tag "596297932419.dkr.ecr.us-east-1.amazonaws.com/msj-trmap-nginx:5.997578e+06": couldn't parse image reference "596297932419.dkr.ecr.us-east-1.amazonaws.com/msj-trmap-nginx:5.997578e+06": invalid reference format
      Warning  FailedSync     15s (x9 over 1m)  kubelet, ip-10-253-13-113.ec2.internal  Error syncing pod, skipping: [failed to "StartContainer" for "msj-treasure-map-uwsgi" with InvalidImageName: "Failed to apply default image tag \"596297932419.dkr.ecr.us-east-1.amazonaws.com/msj-trmap-uwsgi:5.997578e+06\": couldn't parse image reference \"596297932419.dkr.ecr.us-east-1.amazonaws.com/msj-trmap-uwsgi:5.997578e+06\": invalid reference format"
    , failed to "StartContainer" for "msj-treasure-map-nginx" with InvalidImageName: "Failed to apply default image tag \"596297932419.dkr.ecr.us-east-1.amazonaws.com/msj-trmap-nginx:5.997578e+06\": couldn't parse image reference \"596297932419.dkr.ecr.us-east-1.amazonaws.com/msj-trmap-nginx:5.997578e+06\": invalid reference format"
    $ helm version                                                                                                                                                                             
    Client: &version.Version{SemVer:"v2.5.1", GitCommit:"7cf31e8d9a026287041bae077b09165be247ae66", GitTreeState:"clean"}
    Server: &version.Version{SemVer:"v2.5.1", GitCommit:"7cf31e8d9a026287041bae077b09165be247ae66", GitTreeState:"clean"}
  13. 116 remaining items

  14. Mo0rBy commented on Dec 14, 2023

    @Mo0rBy

    Also, within my own specific issue, I was using %d to indiciate that I have a number value, I want to put that into the string format, but it would print as %!d(float64=1433) rather than putting 1433 into that position.

  15. nikicat commented on Dec 14, 2023

    @nikicat

    This is exactly what this thread is about no?

    I suppose this thread is about the command line argument parser, not the YAML parser.

  16. Mo0rBy commented on Dec 14, 2023

    @Mo0rBy

    This is exactly what this thread is about no?

    I suppose this thread is about the command line argument parser, not the YAML parser.

    Ah right sorry, I misinterpreted what you meant

  17. dberardo-com commented on Mar 15, 2024

    @dberardo-com

    after reading through all this discussion i am stil confused ... is there any workaround so far ? like using "| quote" ? or what ?

  18. sebastianpiskorski commented on Apr 25, 2024

    @sebastianpiskorski

    after reading through all this discussion i am stil confused ... is there any workaround so far ? like using "| quote" ? or what ?

    | quote doesn't work

  19. MalteMagnussen commented on Apr 30, 2024

    @MalteMagnussen

    Vote for reopening. Just saw this as well.

    deployment.yaml:

              image: "{{ .Values.sidecar.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
    

    with values.yaml:

    image:
      tag: 87940363

    becomes desired manifest of:

            - image: 'redacted-image-name:8.7940363e+07'
    

    Using this does not work, because as soon as the tag changes to something that isn't an int, we have a helm problem.

              image: "{{ .Values.sidecar.image.repository }}:{{ .Values.image.tag | int }}"
    
  20. aoledk commented on Aug 20, 2024

    @aoledk

    Vote for reopening. Just saw this as well.

    deployment.yaml:

              image: "{{ .Values.sidecar.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
    

    with values.yaml:

    image:
      tag: 87940363

    becomes desired manifest of:

            - image: 'redacted-image-name:8.7940363e+07'
    

    Using this does not work, because as soon as the tag changes to something that isn't an int, we have a helm problem.

              image: "{{ .Values.sidecar.image.repository }}:{{ .Values.image.tag | int }}"
    

    You can quote image.tag with "" to resolve this problem.

    https://helm.sh/docs/chart_template_guide/yaml_techniques/#scalar-types-in-yaml

  21. rehevkor5 commented on Oct 11, 2024

    @rehevkor5

    The workaround appears to be to use --set-string instead of --set, added by #3599

  22. bcdurden commented on Nov 17, 2024

    @bcdurden

    How is this still a problem over 7 years later?

  23. alimnette commented on Dec 3, 2024

    @alimnette

    The workaround appears to be to use --set-string instead of --set, added by #3599

    thank you, work for me :)

  24. 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"

    Basically, if the issue is that Helm implicitly interprets number as float64 type, then it should be solved if I explicitly mark it as int64. Once that's done, it's pretty easy to make it a string and pass around.

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

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions