{{- /*
HorizontalPodAutoscaler — DEFAULT FALSE.

vLLM model load takes minutes (8B+ weight download + GPU pin), so HPA
flapping is hard on capacity planning. Per-Sovereign overlays enable
HPA only on multi-GPU clusters with hot pre-warmed pools.
*/}}
{{- if and .Values.vllm.enabled .Values.hpa.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "bp-vllm.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "bp-vllm.labels" . | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "bp-vllm.fullname" . }}
  minReplicas: {{ .Values.hpa.minReplicas }}
  maxReplicas: {{ .Values.hpa.maxReplicas }}
  metrics:
    {{- if .Values.hpa.targetCPUUtilizationPercentage }}
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
    {{- end }}
    {{- if .Values.hpa.targetMemoryUtilizationPercentage }}
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
    {{- end }}
{{- end }}
