{{- if .Values.certManager.generateCertificates }}
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: {{ include "capsule.fullname" . }}-webhook-selfsigned
  labels:
    {{- include "capsule.labels" . | nindent 4 }}
  {{- with .Values.customAnnotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: {{ include "capsule.fullname" . }}-webhook-cert
  labels:
    {{- include "capsule.labels" . | nindent 4 }}
  {{- with .Values.customAnnotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  dnsNames:
  - {{ include "capsule.fullname" . }}-webhook-service.{{ .Release.Namespace }}.svc
  - {{ include "capsule.fullname" . }}-webhook-service.{{ .Release.Namespace }}.svc.cluster.local
  issuerRef:
    kind: Issuer
    name: {{ include "capsule.fullname" . }}-webhook-selfsigned
  secretName: {{ include "capsule.secretTlsName" . }}
  subject:
    organizations:
      - clastix.io
{{- end }}
