掌舵遍历范围

Big*_*oss 8 templates kubernetes kubernetes-helm

我找不到在 helm 模板中迭代某个范围的方法。我的 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
Run Code Online (Sandbox Code Playgroud)

我想为每个提到的主机生成相同的 nginx 入口规则:

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

但它会生成错误的主机:

- host: [example.com]
- host: [test.example.com demo.example.com test.example.com]
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助!

Big*_*oss 16

我终于让它工作了:

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