I have the following template in _helpers.tpl:
{{/* Get the system admin username from secret
*/}}
{{- define "get-system-admin-username-value" -}}
{{- $secretObj := (lookup "v1" "Secret" .Release.Namespace "my-secret") }}
{{- if and $secretObj (index $secretObj.data "username") }}
{{- $secretValue := (index $secretObj.data "username") | b64dec }}
{{- $secretValue }}
{{- else }}
{{- "undefined" }}
{{- end }}
{{- end }}
I call this function the following way:
apiVersion: v1
kind: Pod
metadata:
name: "{{ .Chart.Name }}"
labels:
{{- include "labels" . | nindent 4 }}
namespace: {{ default "undefined" $.Values.env.NAMESPACE }}
spec:
containers:
- name: "{{ $.Chart.Name }}--xxx"
env:
- name: SYSTEM_ADMIN_USERNAME
value: {{ include "get-system-admin-username-value" . | default "undefined" }}
- name: SYSTEM_ADMIN_PASSWORD
value: {{ include "get-system-admin-password-value" . | default "undefined" }}
When running, I get the following error:
error calling include: template: _helpers.tpl: executing "get-system-admin-username-value" at <.Release.Namespace>: can't evaluate field Release in type string
What seems to be the issue here?
I’ve already tried passing the namespace from the helm chart as a string, I get the same error, also excluding the if statement, and every possible combination of root context ‘$’.
New contributor
Peti Juhász is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.