Kubernetes helm "Ingress.spec.rules[0].http.paths" got "map", expected "array" - kubernetes

So I have been trying to fix some charts we inherited and all the others went fine except this 1 which is giving me a headache.
I understand what thew error is telling me
Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Ingress.spec.rules[0].http.paths): invalid type for io.k8s.api.networking.v1.HTTPIngressRuleValue.paths: got "map", expected "array" but I can't find where this map appears in the spec below. I see the paths being in list format.
Does anyone have any idea where exactly the problem is?
Azure AKS 1.24.0
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "something.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
apiVersion: networking.k8s.io/v1
{{- else if .Capabilities.APIVersions.Has "extensions/v1beta1" }}
apiVersion: extensions/v1beta1
{{- else }}
{{ fail "Unsupported API version"}}
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/component: {{ .Values.component }}
app.kubernetes.io/part-of: {{ .Values.partof }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
{{- with .Values.labels.something}}
{{ toYaml . }}
{{- end }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . }}
{{- end }}
http:
paths:
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
pathType: Prefix
backend:
service:
name: {{ default $fullName .Values.service.name }}
port:
number: {{ .Values.service.port }}
{{- else if .Capabilities.APIVersions.Has "extensions/v1beta1" }}
backend:
serviceName: {{ default $fullName .Values.service.name }}
servicePort: {{ .Values.service.port }}
{{- end }}
{{- end }}
EDIT 1
Doing a helm lint . with the same flags that the helm upgrade --install would do, throws no errors

You have:
paths:
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
pathType: Prefix
...
You're missing the actual path:
paths:
- path: /
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
pathType: Prefix
...

Related

Helm3 template error calling include: template: no template "microservice.labels" associated with template "gotpl"

I have helm 3 template created using helm create microservice command. it has below files.
/Chart.yaml
./values.yaml
./.helmignore
./templates/ingress.yaml
./templates/deployment.yaml
./templates/service.yaml
./templates/serviceaccount.yaml
./templates/hpa.yaml
./templates/NOTES.txt
./templates/_helpers.tpl
./templates/tests/test-connection.yaml
Updated values file based on my application, when I try to install the helm chat its giving below error message.
Error: UPGRADE FAILED: template: microservice/templates/ingress.yaml:20:8: executing "microservice/templates/ingress.yaml" at <include "microservice.labels" .>: error calling include: template: no template "microservice.labels" associated with template "gotpl"
helm.go:75: [debug] template: microservice/templates/ingress.yaml:20:8: executing "microservice/templates/ingress.yaml" at <include "microservice.labels" .>: error calling include: template: no template "microservice.labels" associated with template "gotpl"
Here is the ingress.yaml file.
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "microservice.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else 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 "microservice.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- 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 }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
How to I added microservice.labels template?. Do I need to create microservice.labels.tlp file?
Any tips to fix this error.
Thanks
SR
I copied the ingress.yaml file to, chart created older version helm. this value was missing in _helpers.tpl file. Now I copied new version of hellpers.tpl file. deployment works now.

Ingress uses http instead of https

I am using Azure Kubernetes Service to deploy my applications. I deployed application access to it via Ingress. Application must request permissions from another service using https. But in the logs I see this error message
Invalid redirect_uri: "http://test-api.dev.net/signin-oidc"
As if my traffic for application is not using https
ingress.yml
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "test-api.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "test-api.labels" . | nindent 4 }}
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/configuration-snippet: |
more_clear_headers Server;
spec:
{{- if .Values.ingress.tls }}
tls:
- hosts:
- {{ .Values.ingress.tls.hosts }}
secretName: {{ .Values.ingress.tls.secretName }}
{{- end }}
rules:
{{- range $key, $value := .Values.ingress.hosts }}
- host: {{ $value | quote }}
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
service.yml
apiVersion: v1
kind: Secret
metadata:
name: {{ include "test-api.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "test-api.name" . }}
helm.sh/chart: {{ include "test-api.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
{{- toYaml .Values.secretVars | nindent 2 }}
Could you help me? Thanks.

Ingress.yaml template is throwing nil pointer evaluating interface {}.enabled

When I try to do helm install <chartname> . -f values.yaml -n namespace, i am getting:
Error: template: pid-dm-rd-guacamole/templates/ingress.yaml:1:8: executing "pid-dm-rd-guacamole/templates/ingress.yaml" at <$.Values.ingress.enabled>: nil pointer evaluating interface {}.enabled
Can anyone please suggest how we can avoid this error, here I have attached my ingress.yaml and ingress section in values.yaml
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "device-management.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 "device-management.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: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
ingress:
enabled: true
annotations:
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/tls-acme: "true"
certmanager.k8s.io/cluster-issuer: letsencrypt-prod
paths: []
# - backend:
# serviceName: ssl-redirect
# servicePort: use-annotation
# - backend:
# # Don't use string here, use only integer value!
# servicePort: 443
#nginx.ingress.kubernetes.io/proxy-buffering: "off"
path: /
hosts:
#what is the hostname?
- host: guacamole.****.corp.com
paths:
- path: /
backend:
serviceName: guacamole.****.corp.com
servicePort: 80
tls:
- hosts:
- guacamole.danaher.corp.com
As #Ramanichandran mentioned in comment section problem is solved by adding a missing value in first line in the ingress yaml. Line should look like: .Values.guacamole.ingress.enabled. The guacamole value was missed to add.

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.
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 }}

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

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
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 }}
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}}
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 }}
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