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

{{- if and .Values.hubble.tls.enabled .Values.hubble.tls.autoGenerated.enabled (eq .Values.hubble.tls.autoGenerated.engine "cert-manager") }}
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: {{ printf "%s-client-crt" (include "cilium.hubble.relay.fullname" .) }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: cilium
    app.kubernetes.io/component: hubble-relay
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  secretName: {{ template "cilium.hubble.tls.relayClient.secretName" . }}
  commonName: "*.hubble-relay.cilium.io"
  issuerRef:
    name: {{ printf "%s-ca-issuer" (include "common.names.fullname" .) }}
    kind: Issuer
  subject:
    organizations:
      - "Cilium"
  dnsNames:
    - "*.hubble-relay.cilium.io"
  privateKey:
    algorithm: {{ .Values.hubble.tls.autoGenerated.certManager.keyAlgorithm }}
    size: {{ int .Values.hubble.tls.autoGenerated.certManager.keySize }}
  duration: {{ .Values.hubble.tls.autoGenerated.certManager.duration }}
  renewBefore: {{ .Values.hubble.tls.autoGenerated.certManager.renewBefore }}
{{- end }}
