I have this helper template
{{/*
Selector labels
*/}}
{{- define "app.selectorLabels" -}}
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- with .Values.app.selectorLabels }}
{{- range $key, $value := . }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- end }}
the values.yaml looks like
nameOverride: alexandria
namespace: alexandria
image:
repository: test/alexandria
tag: 59def22
service:
containerPort: 9001
port: 9001
replicas: 1
resources:
requests:
memory: "750Mi"
cpu: "2000m"
limits:
memory: "3Gi"
cpu: "3500m"
prometheus:
port: 9001
job:
enabled: false
service template looks like
{{- if and .Values.service (not .Values.rollout) }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "app.name" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "app.labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- name: {{ include "app.name" . | trunc 15 }}
port: {{ default "80" .Values.service.port }}
protocol: TCP
targetPort: {{ .Values.service.containerPort }}
selector:
{{- include "app.selectorLabels" . | nindent 4 }}
{{- end }}
I get this error if I don’t define the app.selector in values.yaml. Can someone help please
Error: template: base-chart/templates/service.yaml:8:8: executing "base-chart/templates/service.yaml" at <include "app.labels" .>: error calling include: template: base-chart/templates/_helpers.tpl:12:3: executing "app.labels" at <include "app.selectorLabels" .>: error calling include: template: base-chart/templates/_helpers.tpl:25:14: executing "app.selectorLabels" at <.Values.app.selectorLabels>: nil pointer evaluating interface {}.selectorLabels
helm.go:84: [debug] template: base-chart/templates/service.yaml:8:8: executing "base-chart/templates/service.yaml" at <include "app.labels" .>: error calling include: template: base-chart/templates/_helpers.tpl:12:3: executing "app.labels" at <include "app.selectorLabels" .>: error calling include: template: base-chart/templates/_helpers.tpl:25:14: executing "app.selectorLabels" at <.Values.app.selectorLabels>: nil pointer evaluating interface {}.selectorLabels
If I don't define the app.selector then I get error