{{- if (and (.Capabilities.APIVersions.Has "cert-manager.io/v1alpha2") .Values.issuer.email )  -}}
{{/*  Only install issuer if it doesn't already exist in the cluster */}}
{{- if not ( lookup "cert-manager.io/v1alpha2" "ClusterIssuer"  "" .Values.issuer.clusterIssuer  ) }}
apiVersion: cert-manager.io/v1alpha2
kind: ClusterIssuer
metadata:
  name: {{ .Values.issuer.clusterIssuer }}
spec:
  acme:
    server: https://acme-v02.api.letsencrypt.org/directory
    email: {{ required "expected a valid .Values.issuer.email to enable ClusterIssuer" .Values.issuer.email }}
    privateKeySecretRef:
      name: {{ required "expected .Values.issuer.cluster-issuer to not be empty (letsencrypt-prod | letsencrypt-staging)" .Values.issuer.clusterIssuer }}
    solvers:
    - http01:
        ingress:
          class: nginx
{{- end -}}
{{- end -}}
