use secret generated value in another secret during helm chart install

Viewed 32

I have a chart with bitnami/mongodb in the dependencies. I want to use the auto mongodb root password generated secret in another secret, so I have write this

{{- define "mongodb.secretName" -}}
{{- printf "%s-mongodb" .Release.Name }}
{{- end }}

{{- define "mongodb.uri" -}}
{{- $secret := lookup "v1" "Secret" .Release.Namespace (include "mongodb.secretName" .) }}
{{- printf "mongodb://root:%s@%s-mongodb.%s.svc:27017" (index ($secret).data "mongodb-root-password" | b64dec) .Release.Name .Release.Namespace | b64enc | quote }}
{{- end }}

and in my secret I have this

MONGODB_URI: {{ include "mongodb.uri" . }}

But when I try to install it I get this error

Error: INSTALLATION FAILED: template: templates/my-secret.yaml:9:18: executing "templates/my-secret.yaml" at <include "mongodb.uri" .>: error calling include: template: templates/_helpers.tpl:13:56: executing "mongodb.uri" at <index ($secret).data "mongodb-root-password">: error calling index: index of untyped nil

The problem is that when I try to install the chart the mongodb secret still not exists.

Anyone has idea how can I fix this?

0 Answers
Related