{{- $privateKey := default (genPrivateKey "ecdsa") .Values.global.secret.privateKey | b64enc | quote }}

{{- if not .Values.global.secret.privateKey }}
{{- $existingKey := (lookup "v1" "Secret" .Release.Namespace .Values.global.secret.secretName) }}
{{- if $existingKey }}
{{- $privateKey = index $existingKey.data "key" }}
{{- end -}}
{{- end -}}

apiVersion: v1
kind: Secret
metadata:
  name: {{ .Values.global.secret.secretName }}
  annotations:
    "helm.sh/resource-policy": "keep"
type: Opaque
data:
  key: {{ $privateKey }}
