how to use include statement in a for loop (range) helm

597 views Asked by At

I am trying to use an include statement in helm range, but

I am getting an error can't evaluate field Values in type string.

test.yaml

spec: 
  rules: 
    {{- range .Values.tests }}
      - host: {{ . }}
        http:
          paths:
          - backend:
              service:
                name: test-{{ $.Values.somename }}
                port:
                  number: {{- include "testit.get_port" }}
            path: /
            pathType: ImplementationSpecific
    {{- end }}  

and _helper.tpl is this

{{- define "testit.get_port" }}
  {{- if (eq .Values.somtest "test1") }}5000{{- else }}80{{- end }}
{{- end }}

I know for using values, you have to use a $ sign if it is used in range loop. How about include, what should i use there

1

There are 1 answers

0
David Maze On

You didn't include any parameter to the include call, so the template is getting nil as its parameter. Inside a range loop, you probably need to pass the $ top-level object

number: {{- include "testit.get_port" $ }}
#                                     ^