---
{{ if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "nim-llm.fullname" . }}
  labels:
    {{- include "nim-llm.labels" . | nindent 4 }}
spec:
  minReplicas: {{ .Values.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.autoscaling.maxReplicas }}
  scaleTargetRef:
    {{- if (and .Values.multiNode.enabled (or (.Capabilities.APIVersions.Has "leaderworkerset.x-k8s.io/v1") .Values.multiNode.leaderWorkerSet.enabled)) }}
    apiVersion: leaderworkerset.x-k8s.io/v1
    kind: LeaderWorkerSet
    {{- else if .Values.statefulSet.enabled }}
    apiVersion: apps/v1
    kind: StatefulSet
    {{- else }}
    apiVersion: apps/v1
    kind: Deployment
    {{- end }}
    {{- if .Values.multiNode.enabled }}
    name: {{ include "nim-llm.fullname.multinode" . }}
    {{- else }}
    name: {{ include "nim-llm.fullname" . }}
    {{- end }}
  metrics:
    {{- range .Values.autoscaling.metrics }}
        - {{ . | toYaml | nindent 10 }}
    {{- end }}
  {{- if .Values.autoscaling.scaleDownStabilizationSecs }}
  behavior:
    scaleDown:
      stabilizationWindowSeconds: {{ .Values.autoscaling.scaleDownStabilizationSecs }}
  {{- end }}
{{ end }}
