{{- if and (.Values.ssl.enabled) (not .Values.ssl.useExisting) -}}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: {{ include "emqx.fullname" . }}-tls
spec:
  secretName: {{ include "emqx.fullname" . }}-tls
  issuerRef:
    name: {{ default "letsencrypt-staging" .Values.ssl.issuer.name }}
    kind: {{ default "ClusterIssuer" .Values.ssl.issuer.kind }}
  {{- if .Values.ssl.commonName }}
  commonName: {{ .Values.ssl.commonName }}
  {{- end }}
  dnsNames:
    {{- range .Values.ssl.dnsnames }}
    - {{ . }}
    {{- end }}
{{- end -}}
