Skip to content

Does chart support numeric conversion tuple syntax? #4876

Closed

Description

@ygqygq2

values.yaml like this:

replica: 3

I want a list or tuple between zero and three, then I can use range to do someting.
0 1 2

How to writer in chart?

Activity

  1. mattfarina commented on Nov 2, 2018

    @mattfarina
    Collaborator

    Helm uses the go template syntax. range is part of that. You can read about it in the go documentation (e.g., https://golang.org/pkg/text/template/). Does that help?

  2. ygqygq2 commented on Nov 5, 2018

    @ygqygq2
    Author

    @mattfarina I've read it, but there's no range loop like I said.So I'm here to ask for help.

  3. mattfarina commented on Nov 5, 2018

    @mattfarina
    Collaborator

    Half way through the variables section it touches on range. See https://golang.org/pkg/text/template/#hdr-Variables. Does that not work for you?

  4. ygqygq2 commented on Nov 6, 2018

    @ygqygq2
    Author

    @mattfarina Thanks.
    I mean, if give a number 3, then can get a list [0, 1, 2].

  5. mattfarina commented on Nov 6, 2018

    @mattfarina
    Collaborator

    I think you want something like a loop. I am not sure of a way to do that today. It might be a good function for Sprig, the template function package Helm uses.

  6. bacongobbler commented on Nov 6, 2018

    @bacongobbler
    Member

    yeah, bash has a command called seq that takes a number and returns a sequence of numbers up to and including that number, starting at 1: http://tldp.org/LDP/abs/html/extmisc.html

    You can also define the intervals using three arguments: seq $BEGIN $INTERVAL $END. seq 0 1 3 would return the list 0 1 2 3, whereas seq 0 2 10 would return 0 2 4 6 8 10.

    I think a function that performs similar to seq would be a great enhancement to sprig.

    For the time being, you can use list 0 1 2 to achieve the same effect.

  7. ygqygq2 commented on Nov 7, 2018

    @ygqygq2
    Author
  8. bacongobbler commented on Nov 7, 2018

    @bacongobbler
    Member

    I filed Masterminds/sprig#124 to track this upstream. If you feel like contributing that function @ygqygq2, we'd really appreciate a PR.

  9. lentil1016 commented on Nov 29, 2018

    @lentil1016
    Contributor

    {{ untilStep 0 3 1 }} works for now.

    {{- range untilStep 0 3 1 }}
    metadata:
      name: container-{{ . }}
    ---
    {{- end }}
    

    will produce

    metadata:
      name: container-0
    ---
    metadata:
      name: container-1
    ---
    metadata:
      name: container-2
    ---
    

    I wonder if it's a good idea to add this example to control_structures.md. It seems sort of a commonly used looping form to me. 🤔

  10. dominik-ba commented on Aug 28, 2019

    @dominik-ba

    For me it looks like this does not work with values.
    This example just prints out ports: and nothing else ...

    ports:
      {{- range untilStep (int .Values.ports.start) (int .Values.ports.end) 1 }}
      - containerPort: {{ . }}
      protocol: TCP
      {{- end }}
    

    values.yaml contains this

    ports:
      start: 6000
      stop: 7000
    

    Am I doing something wrong or is this not supported?

  11. ygqygq2 commented on Aug 29, 2019

    @ygqygq2
    Author
  12. dominik-ba commented on Aug 29, 2019

    @dominik-ba

    Ok that was embarrassing... :D thanks alot!
    Maybe it would be good if there was an error instead of nothing printed in this case...
    Thanks anyways :)

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