Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does chart support numeric conversion tuple syntax? #4876

Closed
ygqygq2 opened this issue Nov 2, 2018 · 12 comments
Closed

Does chart support numeric conversion tuple syntax? #4876

ygqygq2 opened this issue Nov 2, 2018 · 12 comments

Comments

@ygqygq2
Copy link

ygqygq2 commented Nov 2, 2018

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?

@mattfarina
Copy link
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?

@ygqygq2
Copy link
Author

ygqygq2 commented Nov 5, 2018

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

@mattfarina
Copy link
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?

@ygqygq2
Copy link
Author

ygqygq2 commented Nov 6, 2018

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

@mattfarina
Copy link
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.

@bacongobbler
Copy link
Member

bacongobbler commented Nov 6, 2018

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.

@ygqygq2
Copy link
Author

ygqygq2 commented Nov 7, 2018

@mattfarina @bacongobbler Thanks a lot.
Yes, your are right.
http://masterminds.github.io/sprig/integer_slice.html

{{ untilStep 0 3 1 }} can get [0 1 2]

@bacongobbler
Copy link
Member

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

@lentil1016
Copy link
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. 🤔

@dominik-ba
Copy link

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?

@ygqygq2
Copy link
Author

ygqygq2 commented Aug 29, 2019

@dominik-ba
image

@dominik-ba
Copy link

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
Projects
None yet
Development

No branches or pull requests

5 participants