{{- if and .Values.horizon.enabled .Values.horizon.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "finaegis.fullname" . }}-horizon
  labels:
    {{- include "finaegis.labels" . | nindent 4 }}
    app.kubernetes.io/component: horizon
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "finaegis.fullname" . }}-horizon
  minReplicas: {{ .Values.horizon.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.horizon.autoscaling.maxReplicas }}
  metrics:
    {{- toYaml .Values.horizon.autoscaling.metrics | nindent 4 }}
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 300
      policies:
        - type: Pods
          value: 1
          periodSeconds: 60
    scaleUp:
      stabilizationWindowSeconds: 0
      policies:
        - type: Pods
          value: 2
          periodSeconds: 30
{{- end }}
