Skip to content

Force string values with --set #3155

Closed
Closed

Description

@jiacona

When setting a value such as --set image.tag=3213841, it gets interpreted as a numeric value and comes out of {{ .Values.image.tag }} looking like 3.213841e+06 in the rendered yaml.

This can be worked around, but in a pretty ugly way, by adding a non-numeric character to the value being set so that this fails to parse as a number and then later on, strip out the extraneous characters in the template. For example:

--set image.tag=#3213841

And later in a template:

image: "{{ .Values.image.repository }}:{{ .Values.image.tag | replace "#" ""}}"

This was partially addressed in #2693, in the case where the number has a leading 0, but is still problematic in this case.

What I'm wondering is if there is a reason to try typing values at all or if leaving them as a string would be the more unsurprising behaviour.

For background, this issue came up because I use git short hashes as image tags. Most of the time they include non-numeric chars so work fine. Also, when using values from a file, they can be quoted, thus avoiding the problem. The only time it came up was when using --set which has no easy way to force value type.

Client: &version.Version{SemVer:"v2.7.0", GitCommit:"08c1144f5eb3e3b636d9775617287cc26e53dba4", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.7.0", GitCommit:"08c1144f5eb3e3b636d9775617287cc26e53dba4", GitTreeState:"clean"}

Activity

  1. jiacona commented on Nov 16, 2017

    @jiacona
    ContributorAuthor
  2. thomastaylor312 commented on Nov 16, 2017

    @thomastaylor312
    Contributor

    Thanks for opening this @jiacona

  3. rpsec commented on Feb 2, 2018

    @rpsec

    @jiacona Does this still happen if you use 'quote' ?

    Example:
    " {{ .Values.image.tag | quote }}"

  4. jiacona commented on Feb 5, 2018

    @jiacona
    ContributorAuthor

    @rprobotics yes. The type casting must happen before interpolation in the template, because when using quote you still get a formatted number.

  5. jesselang commented on Feb 12, 2018

    @jesselang

    This continues to be a problem. In addition, I've tried passing --set image.tag='!!str 3213841' and --set 'image.tag=!!str 3213841' using explicit string typing, without remedy, it becomes interpolated as image: tag: '!!str 3213841' in the computed values.

    % helm version
    Client: &version.Version{SemVer:"v2.8.1", GitCommit:"6af75a8fd72e2aa18a2b278cfe5c7a1c5feca7f2", GitTreeState:"clean"}
    Server: &version.Version{SemVer:"v2.8.0", GitCommit:"14af25f1de6832228539259b821949d20069a222", GitTreeState:"clean"}
    
  6. arturo-c commented on Mar 21, 2018

    @arturo-c

    @thomastaylor312 this one can probably be closed , thanks for approving #3599

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