{{- /*
HorizontalPodAutoscaler — Catalyst overlay for the KServe
controller-manager Deployment.

DEFAULT FALSE. The KServe controller is leader-elected so multiple
replicas are passive standbys; HPA rarely makes sense for it. Per-
Sovereign overlays MAY enable for multi-tenant Sovereigns where the
controller + webhook see heavy concurrent InferenceService reconcile
pressure.

Per docs/INVIOLABLE-PRINCIPLES.md #4 every threshold + bound is
operator-tunable.
*/}}
{{- if .Values.kserveOverlay.hpa.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: bp-kserve-controller-manager
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "bp-kserve.labels" . | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ .Values.kserveOverlay.hpa.targetDeployment | default "kserve-controller-manager" }}
  minReplicas: {{ .Values.kserveOverlay.hpa.minReplicas }}
  maxReplicas: {{ .Values.kserveOverlay.hpa.maxReplicas }}
  metrics:
    {{- if .Values.kserveOverlay.hpa.targetCPUUtilizationPercentage }}
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: {{ .Values.kserveOverlay.hpa.targetCPUUtilizationPercentage }}
    {{- end }}
    {{- if .Values.kserveOverlay.hpa.targetMemoryUtilizationPercentage }}
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: {{ .Values.kserveOverlay.hpa.targetMemoryUtilizationPercentage }}
    {{- end }}
{{- end }}
