0

I have a simple api that I've been deploying to K8s as a NodePort service via Helm. I'm working to add an ingress to the Helm chart but I'm having some difficulty getting the variables correct

values.yaml

ingress:
  metadata:
    name: {}
    labels: {}
    annotations:
      kubernetes.io/ingress.class: nginx
  spec:
    rules:
    - host: "testapi.local.dev"
      http:
        paths:
        - pathType: Prefix
          path: "/"
          backend:
            service:
              name: {}
              port: 
                number: 80

templates/ingress.yaml, showing only the spec section where I'm having issues.

spec:
    rules:
      {{- range .Values.ingress.spec.rules }}
      - host: {{ .host | quote }}
        http:
          paths:
          {{- range .paths }}
            - path: {{ .path | quote }}
              pathType: {{ .pathType | quote }}
              backend:
                service:
                  name: {{ include "testapi.service.name" . }}
                  port:
                  {{- range $key, $value := (include "testapi.deployment.ports" . | fromYaml) }}
                    number: {{ .port }}
                  {{- end}}
           {{- end}}
         {{- end}}

When running helm template it just leaves these values blank and I'm not sure where the syntax is wrong. Removing the {{- range .paths }} and the following .path and .pathType and replacing them with the value corrects the issue

spec:
    rules:
      - host: "testapi.local.dev"
        http:
          paths:
Oxyauna
  • 75
  • 2
  • 9
  • When you call `include`, it's inside a `range` loop, and the special variable `.` is the `paths` item. Saving `.` outside the loop or using `$` as the parameter will probably help. [helm chart error can't evaluate field Values in type interface {}](https://stackoverflow.com/questions/56671452/helm-chart-error-cant-evaluate-field-values-in-type-interface) is a similar problem (even involving a `range` loop in an Ingress object) and there's a little more discussion there. – David Maze Jun 03 '22 at 10:45
  • 1
    Shouldn't `{{- range .paths }}` be `{{- range .http.paths }}`? – β.εηοιτ.βε Jun 03 '22 at 10:47

1 Answers1

0

Comments revealed I should be using {{- range .http.paths }}.

Oxyauna
  • 75
  • 2
  • 9