23

I can not find a way to iterate over a range in helm templating. I have the next definition in my values.yaml:

ingress:
  app1:
    port: 80
    hosts:
      - example.com
  app2:
    port: 80
    hosts:
      - demo.example.com
      - test.example.com
      - stage.example.com
  app3:
    port: 80
    hosts:
      - app3.example.com

And i want to generate the same nginx ingress rule for each mentioned host with:

spec:
  rules:
  {{- range $key, $value := .Values.global.ingress }}
  - host: {{ $value.hosts }}
    http:
      paths:
      - path: /qapi
        backend:
          serviceName: api-server
          servicePort: 80
  {{- end }}

But it generates wrong hosts:

- host: [example.com]
- host: [test.example.com demo.example.com test.example.com]

Thanks for the help!

u-ways
  • 6,136
  • 5
  • 31
  • 47
aRTURIUS
  • 1,230
  • 2
  • 13
  • 31

1 Answers1

40

I've finally got it working using:

spec:
  rules:
  {{- range $key, $value := .Values.global.ingress }}
  {{- range $value.hosts }}
  - host: {{ . }}
    http:
      paths:
      - path: /qapi
        backend:
          serviceName: api-server
          servicePort: 80
  {{- end }}
  {{- end }}
aRTURIUS
  • 1,230
  • 2
  • 13
  • 31