nil pointer evaluating interface {}.name when deploy helm chart - kubernetes-helm

I am new to helm and kubernetes, so I maybe missed something.
I have created a Helm Chart to deploy MISP. Unfortunately, I am now getting the following error.
Error: INSTALLATION FAILED: template: misp/templates/serviceaccount.yaml:4:11: executing "misp/templates/serviceaccount.yaml" at <include "misp.fullname" .>: error calling include: template: misp/templates/_helpers.tpl:7:40: executing "misp.fullname" at <.Values.misp.name>: nil pointer evaluating interface {}.name
My helpers.tpl looks like this:
{{/*
This is a helper template file that defines the misp.name variable.
*/}}
{{- define "misp.fullname" -}}
{{- printf "%s-%s" .Release.Name .Values.misp.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "misp.name" -}}
misp
{{- end -}}
{{- define "misp-chart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "misp-chart.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "misp-chart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "misp-chart.labels" -}}
helm.sh/chart: {{ include "misp-chart.chart" . }}
{{ include "misp-chart.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "misp-chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "misp-chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "misp-chart.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "misp-chart.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
and my templates/serviceaccount.yaml like this:
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "misp.fullname" . }}
labels:
app: {{ include "misp.name" . }}
chart: {{ include "misp.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
And here my values.yaml
# Default values for misp.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: coolacid/misp
tag: latest
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 8080
ingress:
enabled: false
# Used to create an Ingress record.
hosts:
- misp.example.com
annotations:
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
tls:
# Secrets must be manually created in the namespace.
- secretName: misp-tls
hosts:
- misp.example.com
database:
mariadb:
enabled: true
image:
repository: bitnami/mariadb
tag: 10.3.23-debian-10-r44
pullPolicy: IfNotPresent
rootUser:
password: password
# databaseName: misp
# user: misp
# password: misp
redis:
enabled: true
image:
repository: bitnami/redis
tag: 6.0.6-debian-10-r0
pullPolicy: IfNotPresent
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
Thank you for your help
try to regenerate the files

Related

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

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

Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', 'updateStrategy' and 'minReadySeconds' are forbidden

I am trying to upgrade my rabbitmq to 3.10 version. When I am deploying using the new image I get below error. I made a small change to the template and not sure why it is throwing this error and nothing else was changed apart from the template.
The StatefulSet "uat-can-gcp-common-rabbitmq-ha-extend" is invalid: spec: Forbidden: updates to statefulset spec for fields other than 'replicas', 'template', 'updateStrategy' and 'minReadySeconds' are forbidden
Below is the code for my statefulset
kind: StatefulSet
metadata:
name: {{ template "rabbitmq-ha.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
app: {{ template "rabbitmq-ha.name" . }}
chart: {{ template "rabbitmq-ha.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- if .Values.extraLabels }}
{{ toYaml .Values.extraLabels | indent 4 }}
{{- end }}
{{- if .Values.statefulSetAnnotations }}
annotations:
{{- range $key, $value := .Values.statefulSetAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
spec:
podManagementPolicy: {{ .Values.podManagementPolicy }}
serviceName: {{ template "rabbitmq-ha.fullname" . }}-discovery
replicas: {{ .Values.replicaCount }}
updateStrategy:
type: {{ .Values.updateStrategy }}
selector:
matchLabels:
app: {{ template "rabbitmq-ha.name" . }}
release: {{ .Release.Name }}
template:
metadata:
labels:
app: {{ template "rabbitmq-ha.name" . }}
release: {{ .Release.Name }}
{{- if .Values.extraLabels }}
{{ toYaml .Values.extraLabels | indent 8 }}
{{- end }}
annotations:
{{- if not .Values.existingConfigMap }}
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- end }}
{{- if not .Values.existingSecret }}
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- end }}
{{- if and .Values.prometheus.exporter.enabled (not .Values.prometheus.operator.enabled) }}
prometheus.io/scrape: "true"
prometheus.io/port: {{ .Values.prometheus.exporter.port | quote }}
{{- end }}
{{- if and .Values.rabbitmqPrometheusPlugin.enabled (not .Values.prometheus.operator.enabled) }}
prometheus.io/scrape: "true"
prometheus.io/port: {{ .Values.rabbitmqPrometheusPlugin.port | quote }}
prometheus.io/path: {{ .Values.rabbitmqPrometheusPlugin.path | quote }}
{{- end }}
{{- if .Values.podAnnotations }}
{{ toYaml .Values.podAnnotations | indent 8 }}
{{- end }}
spec:
{{- if .Values.image.pullSecrets }}
imagePullSecrets:
{{- range .Values.image.pullSecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
securityContext:
{{ toYaml .Values.securityContext | indent 10 }}
serviceAccountName: {{ template "rabbitmq-ha.serviceAccountName" . }}
initContainers:
{{- if .Values.initContainer.enabled }}
- name: bootstrap
image: {{ .Values.busyboxImage.repository}}:{{ .Values.busyboxImage.tag}}
imagePullPolicy: {{ .Values.busyboxImage.pullPolicy }}
securityContext:
{{- toYaml .Values.initContainer.securityContext | nindent 12 }}
command: ['sh']
args:
- "-c"
- |
set -ex
cp /configmap/* /etc/rabbitmq
echo "${RABBITMQ_ERLANG_COOKIE}" > /var/lib/rabbitmq/.erlang.cookie
{{- if .Values.forceBoot }}
if [ -d "${RABBITMQ_MNESIA_DIR}" ]; then
touch "${RABBITMQ_MNESIA_DIR}/force_load"
fi
{{- end }}
{{- if and (.Values.securityContext.runAsUser) (.Values.securityContext.fsGroup) (.Values.initContainer.chownFiles) }}
chown -R {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }} /var/lib/rabbitmq/
chown -R {{ .Values.securityContext.runAsUser }}:{{ .Values.securityContext.fsGroup }} /etc/rabbitmq
{{- end }}
chmod 600 /var/lib/rabbitmq/.erlang.cookie
env:
- name: POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: RABBITMQ_MNESIA_DIR
value: /var/lib/rabbitmq/mnesia/rabbit#$(POD_NAME).{{ template "rabbitmq-ha.fullname" . }}-discovery.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}
- name: RABBITMQ_ERLANG_COOKIE
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq-ha.secretName" . }}
key: rabbitmq-erlang-cookie
resources:
{{ toYaml .Values.initContainer.resources | indent 12 }}
volumeMounts:
- name: configmap
mountPath: /configmap
- name: config
mountPath: /etc/rabbitmq
- name: {{ .Values.persistentVolume.name }}
mountPath: /var/lib/rabbitmq
{{- end}}
{{- if .Values.extraInitContainers }}
{{ tpl (toYaml .Values.extraInitContainers) . | indent 8 }}
{{- end }}
{{- with .Values.dnsConfig }}
dnsConfig:
{{ toYaml . | indent 8 }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: {{ .Values.image.name }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: epmd
protocol: TCP
containerPort: 4369
- name: amqp
protocol: TCP
containerPort: 5672
- name: http
protocol: TCP
containerPort: 15672
{{- if .Values.rabbitmqSTOMPPlugin.enabled }}
- name: stomp-tcp
protocol: TCP
containerPort: 61613
- name: stomp-ssl
protocol: TCP
containerPort: 61614
{{- end }}
{{- if .Values.rabbitmqWebSTOMPPlugin.enabled }}
- name: stomp-ws
protocol: TCP
containerPort: 15674
{{- end }}
{{- if .Values.rabbitmqMQTTPlugin.enabled }}
- name: mqtt-tcp
protocol: TCP
containerPort: 1883
- name: mqtt-ssl
protocol: TCP
containerPort: 8883
{{- end }}
{{- if .Values.rabbitmqWebMQTTPlugin.enabled }}
- name: mqtt-ws
protocol: TCP
containerPort: 15675
{{- end }}
{{- if .Values.rabbitmqAmqpsSupport.enabled }}
- name: amqps
protocol: TCP
containerPort: 5671
{{- end }}
{{- if .Values.rabbitmqPrometheusPlugin.enabled }}
- name: metrics
protocol: TCP
containerPort: {{ .Values.rabbitmqPrometheusPlugin.port }}
{{- end }}
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
{{- toYaml .Values.livenessProbe.config | trim | nindent 12 }}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
{{- toYaml .Values.readinessProbe.config | trim | nindent 12 }}
{{- end }}
{{- if .Values.lifecycle }}
lifecycle:
{{- toYaml .Values.lifecycle | trim | nindent 12 }}
{{- end }}
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
- name: RABBITMQ_USE_LONGNAME
value: "true"
- name: RABBITMQ_NODENAME
value: rabbit#$(MY_POD_NAME).{{ template "rabbitmq-ha.fullname" . }}-discovery.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}
- name: K8S_HOSTNAME_SUFFIX
value: .{{ template "rabbitmq-ha.fullname" . }}-discovery.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }}
- name: K8S_SERVICE_NAME
value: {{ template "rabbitmq-ha.fullname" . }}-discovery
- name: RABBITMQ_ERLANG_COOKIE
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq-ha.secretName" . }}
key: rabbitmq-erlang-cookie
- name: RABBIT_MANAGEMENT_USER
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq-ha.secretName" . }}
key: rabbitmq-management-username
- name: RABBIT_MANAGEMENT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq-ha.secretName" . }}
key: rabbitmq-management-password
{{- if .Values.rabbitmqHipeCompile }}
- name: RABBITMQ_HIPE_COMPILE
value: {{ .Values.rabbitmqHipeCompile | quote }}
{{- end }}
{{- range $key, $value := .Values.env }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
resources:
{{ toYaml .Values.resources | indent 12 }}
volumeMounts:
- name: {{ .Values.persistentVolume.name }}
mountPath: /var/lib/rabbitmq
- name: config
mountPath: /etc/rabbitmq
- name: definitions
mountPath: /etc/definitions
readOnly: true
{{- if .Values.rabbitmqCert.enabled }}
- name: cert
mountPath: /etc/cert
{{- end }}
{{- if .Values.extraVolumeMounts }}
{{ toYaml .Values.extraVolumeMounts | indent 12 }}
{{- end }}
{{ if .Values.prometheus.exporter.enabled }}
- name: {{ .Chart.Name }}-exporter
image: {{ .Values.prometheus.exporter.image.repository }}:{{ .Values.prometheus.exporter.image.tag }}
imagePullPolicy: {{ .Values.prometheus.exporter.image.pullPolicy }}
ports:
- name: exporter
protocol: TCP
containerPort: {{ .Values.prometheus.exporter.port }}
env:
- name: PUBLISH_PORT
value: "{{ .Values.prometheus.exporter.port }}"
{{ if .Values.prometheus.exporter.capabilities }}
- name: RABBIT_CAPABILITIES
value: "{{ .Values.prometheus.exporter.capabilities }}"
{{- end }}
- name: RABBIT_USER
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq-ha.secretName" . }}
key: rabbitmq-username
- name: RABBIT_PASSWORD
valueFrom:
secretKeyRef:
name: {{ template "rabbitmq-ha.secretName" . }}
key: rabbitmq-password
{{- range $key, $value := .Values.prometheus.exporter.env }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
resources:
{{ toYaml .Values.prometheus.exporter.resources | indent 12 }}
{{ end }}
{{- if .Values.extraContainers }}
{{ tpl (toYaml .Values.extraContainers) . | indent 8 }}
{{- end }}
{{- if .Values.nodeSelector }}
nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
{{- end }}
{{- if .Values.tolerations }}
tolerations:
{{ toYaml .Values.tolerations | indent 8 }}
{{- end }}
{{- if .Values.schedulerName }}
schedulerName: "{{ .Values.schedulerName }}"
{{- end }}
{{- if .Values.affinity }}
affinity:
{{- with .Values.affinity }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- else }}
{{- if eq .Values.podAntiAffinity "hard" }}
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: "{{ .Values.podAntiAffinityTopologyKey }}"
labelSelector:
matchLabels:
app: {{ template "rabbitmq-ha.name" . }}
release: {{ .Release.Name }}
{{- else if eq .Values.podAntiAffinity "soft" }}
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 1
podAffinityTerm:
topologyKey: "{{ .Values.podAntiAffinityTopologyKey }}"
labelSelector:
matchLabels:
app: {{ template "rabbitmq-ha.name" . }}
release: {{ .Release.Name }}
{{- end }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
volumes:
- name: config
emptyDir: {}
- name: configmap
configMap:
name: {{ template "rabbitmq-ha.fullname" . }}
- name: definitions
secret:
secretName: {{ template "rabbitmq-ha.secretName" . }}
items:
- key: {{ .Values.definitionsSource }}
path: definitions.json
{{- if .Values.rabbitmqCert.enabled }}
- name: cert
secret:
defaultMode: 420
secretName: {{ template "rabbitmq-ha.certSecretName" . }}
{{- end }}
{{- if .Values.extraVolumes }}
{{ toYaml .Values.extraVolumes | indent 8 }}
{{- end }}
{{- if .Values.persistentVolume.enabled }}
volumeClaimTemplates:
- metadata:
name: {{ .Values.persistentVolume.name }}
annotations:
{{ tpl (toYaml .Values.persistentVolume.annotations) . | indent 10 }}
labels:
{{ tpl (toYaml .Values.persistentVolume.labels) . | indent 10 }}
spec:
accessModes:
{{- range .Values.persistentVolume.accessModes }}
- {{ . | quote }}
{{- end }}
resources:
requests:
storage: {{ .Values.persistentVolume.size | quote }}
{{- if .Values.persistentVolume.storageClass }}
{{- if (eq "-" .Values.persistentVolume.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistentVolume.storageClass }}"
{{- end }}
{{- end }}
{{- with .Values.persistentVolume.selector }}
selector:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- else }}
- name: {{ .Values.persistentVolume.name }}
emptyDir: {}
{{- end }}
It might be useful to render out both iterations and run diff on them to find out whether you are accidentally changing fields that are immutable in the API.

Inject vault secret into k8s config map

For ArgoCD configuration I would like to pass vault secrets into ConfigMap.
My config map template:
{{- if .Values.server.configEnabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
labels:
{{- include "argo-cd.labels" (dict "context" . "component" .Values.server.name "name" "cm") | nindent 4 }}
{{- if .Values.server.configAnnotations }}
annotations:
{{- range $key, $value := .Values.server.configAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
data: {{- include "argo-cd.config" $ | nindent 4 }}
{{- end }}
and values part:
server:
podAnnotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/auth-path: "auth/gke"
vault.hashicorp.com/role: "default-role"
config:
oidc.config: |
name: Google
issuer: https://accounts.google.com
clientID: |
{{- with secret "secret-gke/data/argocd/argocd-server/client" -}}
{{ .Data.data.clientID }}
{{- end -}}
clientSecret: |
{{- with secret "secret-gke/data/argocd/argocd-server/client" -}}
{{ .Data.data.clientSecret }}
{{- end -}}
podAnnotations allow to inject secrets into Pod and configAnnotations do not solve the issue, so how to inject secrets into ConfigMap?

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.

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