{{- if ((.Values.langfuse.worker).hpa).enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "langfuse.fullname" . }}-worker
  labels:
    {{- include "langfuse.labels" . | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "langfuse.fullname" . }}-worker
  minReplicas: {{ .Values.langfuse.worker.hpa.minReplicas }}
  maxReplicas: {{ .Values.langfuse.worker.hpa.maxReplicas }}
  metrics:
    {{- with .Values.langfuse.worker.hpa.targetCPUUtilizationPercentage }}
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: {{ . }}
    {{- end }}
    {{- with .Values.langfuse.worker.hpa.targetMemoryUtilizationPercentage }}
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: {{ . }}
    {{- end }}
{{- end }}
