Il modello Helm non è compatibile con la struttura values.yaml

Aug 16 2020

Ho il seguente ingress.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 }}

E i seguenti valori per alimentare questo modello:

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

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

Quando eseguo "helm install" fallisce su:

Errore: AGGIORNAMENTO NON RIUSCITO: template: templates/ingress.yaml:31:15: esecuzione di "templates/ingress.yaml" su <.host>: impossibile valutare l'host di campo nell'interfaccia di tipo {}

Quindi per me sembra che gli host debbano essere un elenco, non un dizionario (a causa delle istruzioni sull'intervallo) . Quindi lo converto:

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

Ma in questo caso ottengo:

avviso: la destinazione per gli host è una tabella. Valore non tabella ignorato [map[host:app.example.com percorsi:[/api /oauth]]]

e lo stesso errore di cui sopra in aggiunta.

Come farlo funzionare?

AGGIORNAMENTO 1

I valori:

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"

Modello:

{{- 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 }}

AGGIORNAMENTO 2

Ho capito che il problema non era nel codice ma nella riga di comando. Ho alimentato con string anziché array.

modello helm ... --set ingress.hosts.host=c1.app.example.com ...

Cercherò di capire come fornire più valori e aggiornarlo qui.

AGGIORNAMENTO 3

Ho cancellato i dati dai valori:

ingress:
  enabled: false

  rules:
    - host:

  tls:
    - secretName:
      hosts: []

Risposte

1 seshadri_c Aug 16 2020 at 15:36

Il modello cerca .Values.ingress.hosts, mentre nei valori visualizzati non è presente alcun ingressprefisso. E poiché l' rangeoperatore viene utilizzato, dovremmo avere un elenco di dictionary .

Inoltre, prima di eseguire un helm install, sarebbe opportuno eseguire helm templatesolo per assicurarsi che le definizioni YAML siano rese correttamente.

Considerando il seguente contenuto in 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"

L'esecuzione helm templatedel comando risulta in (ho definito serviceNamecome haproxy e servicePortcome 8080 per l'illustrazione):

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

Rispondendo alla mia stessa domanda.

Il problema era nella mancata corrispondenza della struttura del modello di ingresso e degli argomenti della riga di comando che ho fornito per l'override dei parametri.

Questo è l'adattamento corretto degli argomenti della riga di 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

Che popola values.yaml :

ingress:
  enabled: false

  rules:
    - host:

  tls:
    - secretName:
      hosts: []

Per il modello di ingresso :

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 }}