helm chart error can't evaluate field Values in type interface {}

6/19/2019

I know this is some kind of syntax/yaml structure related error but the message is so cryptic I have no idea what the issue is:

Error: render error in "mychart/templates/ingress.yaml": template: mychart/templates/ingress.yaml:35:37: executing "mychart/templates/ingress.yaml" at <.Values.network.appP...>: can't evaluate field Values in type interface {}

This is in my values.yaml:

network:
  appPort: 4141

This is the ingress.yaml:

{{- $fullName := include "mychart.fullname" . -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    app.kubernetes.io/name: {{ include "mychart.name" . }}
    helm.sh/chart: {{ include "mychart.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
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 | quote }}
      http:
        paths:
        {{- range .paths }}
          - path: {{ . }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ .Values.network.appPort }}
        {{- end }}
  {{- end }}

Why doesn't {{ .Values.network.appPort }} work? I have used values with this same structure in other places

-- red888
kubernetes
kubernetes-helm

1 Answer

6/19/2019

Isn't it just scope issue?

Try something as below

{{- $fullName := include "mychart.fullname" . -}}
{{- $networkAppPort  := .Values.network.appPort -}}
...
.... omitted code
...
      http:
        paths:
        {{- range .paths }}
          - path: {{ . }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $networkAppPort }}
        {{- end }}
  {{- end }}
-- VladoDemcak
Source: StackOverflow