La plantilla de Helm no es compatible con la estructura de valores.yaml

Aug 16 2020

Tengo el siguiente ingreso.yaml:

spec:
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.hosts }}
    - host: {{ .host }}                 // row 31
      http:
        paths:
        {{- range .paths }}
          - path: {{ . | quote }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
        {{- end }}
  {{- end }}
{{- end }}

Y los siguientes valores para alimentar esta plantilla:

  hosts:
    host: "app.example.com"
    paths:
      - "/api"
      - "/oauth"

  tls:
    - secretName: "example-tls"
      hosts:
        - "*.app.example.com"
        - "dev.example.com"

Cuando ejecuto "helm install" falla en:

Error: ACTUALIZACIÓN FALLIDA: plantilla: templates/ingress.yaml:31:15: ejecutando "templates/ingress.yaml" en <.host>: no se puede evaluar el host de campo en la interfaz de tipo {}

Entonces, para mí, parece que los hosts deben ser una lista, no un diccionario (debido a la instrucción de rango ). Entonces lo convierto:

  hosts:
    - host: "app.example.com"
      paths:
        - "/api"
        - "/oauth"

Pero en este caso me sale:

advertencia: el destino de los hosts es una tabla. Ignorando el valor que no es de tabla [map[host:app.example.com paths:[/api /oauth]]]

y el mismo error que el anterior además.

¿Cómo hacer que funcione?

ACTUALIZAR 1

Valores:

ingress:
  enabled: true

  rules:
    - host: c1.app.example.com
      paths:
        - /api
        - /oauth
    - host: c2.app.example.com
      paths:
        - /api
        - /oauth
  tls:
    - secretName: "example-tls"
      hosts:
        - "*.app.example.com"
        - "dev.example.com"

Modelo:

{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
      secretName: {{ .secretName }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.rules }}
    - host: {{ .host | quote }}
      http:
        paths:
        {{- range .paths }}
          - path: {{ . | quote }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
        {{- end }}
  {{- end }}
{{- end }}

ACTUALIZAR 2

Comprendí que el problema no estaba en el código sino en la línea de comandos. Me alimenté con una cadena en lugar de una matriz.

plantilla de timón... --set ingress.hosts.host=c1.app.example.com...

Intentaré descubrir cómo proporcionar múltiples valores y actualizarlo aquí.

ACTUALIZAR 3

Borré datos de valores:

ingress:
  enabled: false

  rules:
    - host:

  tls:
    - secretName:
      hosts: []

Respuestas

1 seshadri_c Aug 16 2020 at 15:36

La plantilla está buscando .Values.ingress.hosts, mientras que en los valores mostrados no hay ingressprefijo. Y como rangese usa el operador, deberíamos tener una lista de dictionary .

Además, antes de hacer un helm install, sería bueno ejecutar helm templatesolo para asegurarse de que las definiciones de YAML se representen correctamente.

Teniendo en cuenta el siguiente contenido en values.yaml:

--- 
ingress: 
  hosts: 
    - 
      host: app1.example.com
      paths: 
        - /api
        - /oauth
    - 
      host: app2.example.com
      paths: 
        - /api1
        - /authz
  tls:
    - hosts:
      - "*.app.example.com"
      - "dev.example.com"
      secretName: "example-tls"

Ejecutar el helm templatecomando da como resultado (lo he definido serviceNamecomo haproxy y servicePortcomo 8080 para ilustración):

spec:
  tls:
    - hosts:
        - "*.app.example.com"
        - "dev.example.com"
      secretName: example-tls
  rules:
    - host: app1.example.com                 // row 31
      http:
        paths:
          - path: "/api"
            backend:
              serviceName: haproxy
              servicePort: 8080
          - path: "/oauth"
            backend:
              serviceName: haproxy
              servicePort: 8080
    - host: app2.example.com                 // row 31
      # similar output for app2.example.com

1 MichaelA. Aug 27 2020 at 00:13

Respondiendo a mi propia pregunta.

El problema estaba en la falta de coincidencia de la estructura de la plantilla de ingreso y los argumentos de la línea de comando que proporcioné para anular los parámetros.

Este es el ajuste adecuado de los argumentos de la línea de comando :

helm upgrade <some other options here>
--values ./values.yaml
--set ingress.enabled=True
--set ingress.tls[0].hosts[0]=app.example.com
--set ingress.tls[0].secretName=example-tls
--set ingress.rules[0].host=app.example.com

Eso llena valores.yaml :

ingress:
  enabled: false

  rules:
    - host:

  tls:
    - secretName:
      hosts: []

Para la plantilla de ingreso :

spec:
{{- if .Values.ingress.tls }}
  tls:
  {{- range .Values.ingress.tls }}
    - secretName: {{ .secretName }}
      hosts:
      {{- range .hosts }}
        - {{ . | quote }}
      {{- end }}
  {{- end }}
{{- end }}
  rules:
  {{- range .Values.ingress.rules }}
    - host: {{ .host | quote }}
      http:
        paths:
        - path: /api
          backend:
            serviceName: {{ $fullName }}
            servicePort: {{ $svcPort }}
  {{- end }}
{{- end }}