Search code examples
yamlkubernetes-helm

helm chart for Istio Gateway parsing issue: can't evaluate field ... in type interface {}


I got a parsing issue when I tried to install with a helm chart that has the Istio Gateway and virtual service. Can anyone please help to find out what's wrong with this? Thanks a lot!

Error:

$ helm install my-release ./pipeline-nodejs-app/ --dry-run
Error: template: pipeline-nodejs-app/templates/gateway.yaml:16:17: executing "pipeline-nodejs-app/templates/gateway.yaml" at <.number>: can't evaluate field number in type interface {}

templates/gateway.yaml

{{- if .Values.gateway.enabled -}}
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: {{ .Values.gateway.name }}
  {{- with .Values.gateway.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  selector:
    istio: ingressgateway
  servers:
  {{- range .Values.gateway.port }}
  - port:
      number: {{ .number }}
      name: {{ .portname }}
      protocol: {{ .protocol }}
  {{- end }}
    hosts:
    {{- range .Values.gateway.hosts }}
    - {{ .host | quote }}
    {{- end }}
{{- end }}

values.yaml

...
gateway:
  enabled: true
  annotations: {}
  name: pipeline-nodejs-app-gateway
  hosts:
    host: '*'
  port:
    number: 80 
    name: http
    protocol: HTTP
...

my expected output of the gateway.yaml is:

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: pipeline-javascript-app-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
  - port:
      number: 80
      name: http
      protocol: HTTP
    hosts:
    - "*"

Solution

  • I think, Your issue is here

      {{- range .Values.gateway.port }}
      - port:
          number: {{ .number }}
          name: {{ .portname }}
          protocol: {{ .protocol }}
      {{- end }}
    

    To use range you have to have list of port like number started with -.

      port:
      - number: 80 
        name: http
        protocol: HTTP
    

    just change the values.yaml like

    ...
    gateway:
      enabled: true
      annotations: {}
      name: pipeline-nodejs-app-gateway
      hosts:
        host: '*'
      port:
      - number: 80 
        name: http
        protocol: HTTP
    ...