{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.security.enabled .Values.security.mTLS.enabled .Values.security.mTLS.autoGenerated.enabled (eq .Values.security.mTLS.autoGenerated.engine "cert-manager") }}
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: {{ printf "%s-crt" (include "seaweedfs.volume.fullname" .) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: volume
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  secretName: {{ printf "%s-crt" (include "seaweedfs.volume.fullname" .) }}
  commonName: {{ printf "%s.%s.svc.%s" (include "seaweedfs.volume.fullname" .) (include "common.names.namespace" .) .Values.clusterDomain }}
  issuerRef:
    name: {{ printf "%s-ca-issuer" (include "common.names.fullname" .) }}
    kind: Issuer
  subject:
    organizations:
      - "SeaweedFS"
  dnsNames:
    - '*.{{ include "common.names.namespace" . }}'
    - '*.{{ include "common.names.namespace" . }}.svc'
    - '*.{{ include "common.names.namespace" . }}.svc.{{ .Values.clusterDomain }}'
    - '*.{{ include "seaweedfs.volume.fullname" . }}'
    - '*.{{ include "seaweedfs.volume.fullname" . }}.{{ include "common.names.namespace" . }}'
    - '*.{{ include "seaweedfs.volume.fullname" . }}.{{ include "common.names.namespace" . }}.svc'
    - '*.{{ include "seaweedfs.volume.fullname" . }}.{{ include "common.names.namespace" . }}.svc.{{ .Values.clusterDomain }}'
    - '*.{{ printf "%s-headless" (include "seaweedfs.volume.fullname" .) }}'
    - '*.{{ printf "%s-headless" (include "seaweedfs.volume.fullname" .) }}.{{ include "common.names.namespace" . }}'
    - '*.{{ printf "%s-headless" (include "seaweedfs.volume.fullname" .) }}.{{ include "common.names.namespace" . }}.svc'
    - '*.{{ printf "%s-headless" (include "seaweedfs.volume.fullname" .) }}.{{ include "common.names.namespace" . }}.svc.{{ .Values.clusterDomain }}'
  privateKey:
    algorithm: {{ .Values.security.mTLS.autoGenerated.certManager.keyAlgorithm }}
    size: {{ int .Values.security.mTLS.autoGenerated.certManager.keySize }}
  duration: {{ .Values.security.mTLS.autoGenerated.certManager.duration }}
  renewBefore: {{ .Values.security.mTLS.autoGenerated.certManager.renewBefore }}
{{- end }}
