{{- if and (.Values.useCertManager) (not .Values.msgTopologyOperator.existingWebhookCertSecret) }}
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: messaging-topology-operator
    app.kubernetes.io/part-of: rabbitmq
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  name: {{ template "rmqco.msgTopologyOperator.webhook.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  commonName: {{ template "rmqco.msgTopologyOperator.webhook.fullname" . }}
  dnsNames:
    - {{ printf "%s.%s.svc" (include "rmqco.msgTopologyOperator.webhook.fullname" .) (include "common.names.namespace" .) }}
    - {{ printf "%s.%s.svc.%s" (include "rmqco.msgTopologyOperator.webhook.fullname" .) (include "common.names.namespace" .) .Values.clusterDomain }}
  issuerRef:
    kind: Issuer
    name: {{ template "common.names.fullname" . }}
  secretName: {{ template "rmqco.msgTopologyOperator.webhook.fullname" . }}
{{- end }}
