{{- $secret_name := "ironic-mariadb" -}} apiVersion: v1 kind: Secret metadata: name: {{ $secret_name }} labels: {{- include "mariadb.labels" . | nindent 4 }} type: Opaque data: # Check if the secret is deployed and has a password {{- $old_sec := lookup "v1" "Secret" .Release.Namespace $secret_name }} {{- if and $old_sec (index $old_sec.data "password") }} password: {{ index $old_sec.data "password" }} {{- else if .Values.password }} # If not, check if a password is provided in values.yaml password: {{ .Values.password | toString | b64enc }} {{- else }} # If no secret and no password in values.yaml, generate a new password password: {{ randAlphaNum 20 | b64enc }} {{- end }}