41

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

4 Answers 4

44

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 }}
3
  • 4
    hmm can you explain this? I cant find good docs that explain this scoping related stuff. In another template (service.yaml) I dont define a var like that at the top of the yaml file and I can just do {{ include "bombora-atlantis.fullname" . }} directly throughout the file and it just works- whats different about the ingress.yaml?
    – red888
    Jun 19, 2019 at 16:24
  • @red888 Maybe setting-the-scope-of-a-template and modifying-scope-using-with. it's pretty hard to say why it works in your case but I assume you simply pass a scope (.) to the include. Jun 19, 2019 at 17:03
  • The urls above have changed. Current location of Helm scope documentation control-structures Aug 14, 2020 at 13:00
22

In the range block . refers to the current value in the execution time. Instead of . you can use $ to access to the root data object in the range block instead of declaring top level variables.

Example:

  {{- range $host := .Values.ingress.hosts }}
    - host: {{ $host }}
      http:
        paths:
        - path: /
          pathType: Prefix
          backend:
            service:
              name: frontend
              port:
                number: {{ $.Values.frontend.service.port }}
  {{- end}}
4
  • 7
    IMO That should be the accepted answer.
    – Joao M
    Aug 29, 2022 at 20:57
  • 1
    $ is actually documented in Helm documentation, but I found it hard to find. Its in helm.sh/docs/chart_template_guide/variables "However, there is one variable that is always global - $ - this variable will always point to the root context. This can be very useful when you are looping in a range and you need to know the chart's release name."
    – swoop81
    Oct 28, 2022 at 18:46
  • 1
    worked for me. I was using .Release.Name inside range, just adding $ fixed the issue. Nov 1, 2022 at 6:43
  • Thanks for the explanation. The accepted answer doesn't provide an explanation Nov 11, 2022 at 13:06
5

I use helm3 and I have the same error message, when i run helm template my-chart. In my case, i have define wrongly in values.yaml,

WRONG configuration (In my values.yaml missing path under paths):

ingress:
  enabled: true
  annotations:
     kubernetes.io/ingress.class: "nginx"
     nginx.ingress.kubernetes.io/rewrite-target: /$2
     nginx.ingress.kubernetes.io/ssl-redirect: "false"
     nginx.ingress.kubernetes.io/use-regex: "true"

  hosts:
    - host: "dev"
      paths:
      - /dev(/|$)(.*)
  tls: []

correct the ingress definition like this , it works

ingress:
  enabled: true
  annotations:
     kubernetes.io/ingress.class: "nginx"
     nginx.ingress.kubernetes.io/rewrite-target: /$2
     nginx.ingress.kubernetes.io/ssl-redirect: "false"
     nginx.ingress.kubernetes.io/use-regex: "true"

  hosts:
    - host:
      paths:
      - path: "/dev(/|$)(.*)"
  tls: []

my ingress template, ingress.yaml, which is generated automatically via helm

{{- if .Values.ingress.enabled -}}
{{- $fullName := include "bsb-lookup.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    {{- include "bsb-lookup.labels" . | nindent 4 }}
  {{- 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: {{ .path }}
            backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
          {{- end }}
    {{- end }}
  {{- end }}
0

for YAML it is also required to have the immediate parent of any optional value.

Like you are trying to do a check "a.b.c" in some yaml during helm build its gives similar error. it is required to have a.b at least in the default values.yaml.

Solved by going details in - https://github.com/helm/helm/issues/5435

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.