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.
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 }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With