{{- if .Values.admissionController.enabled }}
{{- if (not .Values.admissionController.tls.existingSecret) }}
{{- $ca := genCA (include "vertical-pod-autoscaler.admissionController.fullname" .) 365 }}
# {{- $cn := printf "%s.%s.svc" (include "vertical-pod-autoscaler.admissionController.fullname" .) .Release.Namespace }}
{{- $cn := printf "%s.%s.svc" "vpa-webhook" .Release.Namespace }}
{{- $cert := genSignedCert $cn nil (list $cn) 365 $ca }}
apiVersion: v1
kind: Secret
metadata:
  name: {{ include "vertical-pod-autoscaler.admissionController.tls.secretName" . }}
  labels:
    {{- include "vertical-pod-autoscaler.admissionController.labels" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations:
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
type: Opaque
data:
  ca.crt: {{ default $ca.Cert .Values.admissionController.tls.caCert | b64enc | quote }}
  tls.crt: {{ default $cert.Cert .Values.admissionController.tls.cert | b64enc | quote }}
  tls.key: {{ default $cert.Key .Values.admissionController.tls.key | b64enc | quote }}
{{- end }}
{{- end }}
