{{- /*
HorizontalPodAutoscaler — DEFAULT FALSE.

BGE is CPU-bound and stateless, so HPA scales linearly with load.
Per-Sovereign overlays enable on multi-tenant Sovereigns where
embeddings throughput needs autoscaling.
*/}}
{{- if and .Values.bge.enabled .Values.hpa.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "bp-bge.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "bp-bge.labels" . | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "bp-bge.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 }}
