Skip to content

integer with leading zero gets truncated  #2693

Closed

Description

@andiMenge

Hi there,
I use short git commit hashes as docker tags and stumbled across a issue with helm.

Client: &version.Version{SemVer:"v2.5.0", GitCommit:"012cb0ac1a1b2f888144ef5a67b8dab6c2d45be6", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.5.0", GitCommit:"012cb0ac1a1b2f888144ef5a67b8dab6c2d45be6", GitTreeState:"clean"}

Issue

helm truncates integers with leading zeros.

Example

helm install --namespace tools --set deployment.dockerTag=0474915 helm/elastalert --debug --dry-run results in this:

USER-SUPPLIED VALUES:
deployment:
  dockerTag: 474915
spec:
      containers:
      - name: elastalert
        image: my-registry/elastalert:474915

The leading zero 0 gets truncated by helm which results in a kubernetes imagePullError.

I tried different quoting techniques with single and double quotes:

--set 'deployment.dockerTag=0474915'
--set "deployment.dockerTag=0474915"
--set deployment.dockerTag='0474915'
--set deployment.dockerTag="0474915"

All of them resulting in the same behavior described above.

this is the line from my template:
image: {{ .Values.global.dockerRegistry }}/{{ .Values.deployment.dockerImage }}:{{ .Values.deployment.dockerTag }}

Is there a way to stop helm from converting my values?

Activity

  1. changed the title [-]--set integer with leading zero gets truncated [/-] [+]integer with leading zero gets truncated [/+] on Jul 17, 2017
  2. jascott1 commented on Jul 19, 2017

    @jascott1
    Contributor

    @andiMenge Have you tried putting double-quotes around image: value?

    image: "{{ .Values.global.dockerRegistry }}/{{ .Values.deployment.dockerImage }}:{{ .Values.deployment.dockerTag }}"
    
  3. andiMenge commented on Jul 20, 2017

    @andiMenge
    Author

    @jascott1 thank you for the reply. double quotes around the image: value results in the same behavior: image: "my-registry/elastalert:474915"

    I also tried this: image: {{ .Values.global.dockerRegistry }}/{{ .Values.deployment.dockerImage }}:"{{ .Values.deployment.dockerTag }}" with this result:

    image: registry.ucp.fhm.de/elastalert:"474915"

  4. jascott1 commented on Jul 21, 2017

    @jascott1
    Contributor

    @andiMenge Sorry I should have realized its getting stripped before it even makes it to the template. My guess is that this is happening during all the values merging where a lot of conversions take place but idk. Im not sure there is a way to force it to consider a number as a string. You could concatenate the whole image name (change the template and combine the --set values) but I assume you wouldn't be asking if that would suffice.

    Does it keep the leading zero if you put it into the values.yaml with quotes?

  5. thomastaylor312 commented on Jul 21, 2017

    @thomastaylor312
    Contributor

    @andiMenge So --set deployment.dockerTag=0474915 should look like --set deployment.dockerTag="0474915" for safety because if it is all digits, it will treat it as an int. If you wrap the value in quotes when you pass it in, the parser will treat it as a string and you won't lose that digit

  6. andiMenge commented on Jul 21, 2017

    @andiMenge
    Author

    @thomastaylor312 unfortunately quoting the "value" doesn't stop helm from truncating it. I tried that as well as some other quoting styles.

  7. thomastaylor312 commented on Jul 21, 2017

    @thomastaylor312
    Contributor

    Dang, well I'll have to dig into the code that parses --set and see what we can do

  8. Timbus commented on Jul 26, 2017

    @Timbus

    Hello, just got bitten by this as well. If you quote the value in bash it will still be truncated because bash eats the quotes.
    However if you double quote it like so: --set imageTag='"00123"' you now get a string... containing the quotes -_-

    image: {{ .Values.image }}:{{.Values.imageTag}}
    # expands to:
    image: test:"000123"
    # Also I can't quote the template placeholders or it breaks the parser.
    

    Kinda painful.

  9. jiacona commented on Nov 10, 2017

    @jiacona
    Contributor

    FWIW, this issue still requires some pretty ugly workarounds in certain cases. If you want to set something to a bash variable, you need even more layers of quoting just to get the value into helm as a string. e.g.,

    --set image.tag='"'$TAG'"'

    otherwise you will get the literal string "$TAG"

    Then you have to strip out the literal ""s later in the template e.g.,

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

  10. thomastaylor312 commented on Nov 11, 2017

    @thomastaylor312
    Contributor

    @jiacona This was fixed in Helm 2.6.0, are you still having issues?

  11. jiacona commented on Nov 14, 2017

    @jiacona
    Contributor

    Hi @thomastaylor312 I'm not having the exact problem mentioned in this issue, I just found the discussion here useful in working around a related issue. My issue is that when I set that value using --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. So I needed a way of forcing it to be interpreted as a string. Should I open a separate issue to discuss?

  12. thomastaylor312 commented on Nov 16, 2017

    @thomastaylor312
    Contributor

    @jiacona Yes please. Feel free to ping me in the issue you create

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