Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Helm can't evaluate field Values in type interface {}

There are two ranges declared inside a template, and the second range errors out on:

Error: render error in "APPLICATION_NAME/templates/server.yaml": template: APPLICATION_NAME/templates/server.yaml:16:17: executing "APPLICATION_NAME/templates/server.yaml" at <.Values.services.def>: can't evaluate field Values in type interface {}

The range that is causing the error can be seen here:

paths:
{{- range $i, $svc := .Values.services.def }}
- path: "{{ $svc.path }}-{{ $x_version }}{{ $endpointPath }}($|(/.*))"
  backend:
    serviceName: {{ $fullName }}-{{ $svc.name }}
    servicePort: {{ $svc.port }}
{{- end }}

Here is the template file with both ranges included:

{{ if .Values.server.enabled -}}
{{- $fullName := include "generic.fullname" . -}}
{{- $appName := include "generic.name" . -}}
{{- $chartName := include "generic.chart" . -}}
{{- $namespace := .Values.namespace -}}
{{- $releaseName := .Release.Name -}}
{{- $managedbyName := .Release.Service -}}
{{- $dnsSuffix := .Values.dns_suffix -}}
{{- $x_version := .Values.server.x_version -}}
{{- range .Values.server.headerless_endpoints -}}
{{- $endpointPath := . -}}
apiVersion: configuration.konghq.com/v1
kind: ServerPlugin
metadata:
  name: "{{ $fullName }}-headerless-endpoint-{{ lower $endpointPath | replace "/" "---" }}-plugin"
  namespace: {{ $namespace }}
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: "{{ $fullName }}-server-headerless-{{ lower $endpointPath | replace "/" "---" }}-ingress"
  namespace: {{ $namespace }}
  labels:
    app: {{ $appName }}
    helm.sh/chart: {{ $chartName }}
    release: {{ $releaseName }}
    managed-by: {{ $managedbyName }}
  annotations:
    kubernetes.io/ingress.class: "server"
    external-dns.alpha.kubernetes.io/hostname: ""
    plugins.konghq.com: "{{ $fullName }}-headerless-endpoint-{{ lower $endpointPath | replace "/" "---" }}-plugin"
    konghq.com/plugins: "{{ $fullName }}-headerless-endpoint-{{ lower $endpointPath | replace "/" "---" }}-plugin"
    konghq.com/strip-path: "true"
spec:
  rules:
    - host: "internal.{{ $dnsSuffix }}"
      http:
        paths:
        {{- range $i, $svc := .Values.services.def }}
        - path: "{{ $svc.path }}-{{ $x_version }}{{ $endpointPath }}($|(/.*))"
          backend:
            serviceName: {{ $fullName }}-{{ $svc.name }}
            servicePort: {{ $svc.port }}
        {{- end }}
---
{{ end }}
{{- end }}

Any tips or pointers would be much appreciated.

like image 815
Theo Sweeny Avatar asked Aug 31 '25 16:08

Theo Sweeny


1 Answers

The fix was to prepend the root identifier $ to the second array like so

paths:
{{- range $i, $svc := $.Values.services.def }}
- path: "{{ $svc.path }}-{{ $x_version }}{{ $endpointPath }}($|(/.*))"
  backend:
    serviceName: {{ $fullName }}-{{ $svc.name }}
    servicePort: {{ $svc.port }}
{{- end }}
like image 178
Theo Sweeny Avatar answered Sep 02 '25 23:09

Theo Sweeny