{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if .Values.aggregator.autoscaling.enabled }}
apiVersion: {{ include "common.capabilities.hpa.apiVersion" ( dict "beta2" "true" "context" $ ) }}
kind: HorizontalPodAutoscaler
metadata:
  name: {{ printf "%s-aggregator-hpa" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: aggregator
  {{- if or .Values.aggregator.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.aggregator.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.aggregator.autoscaling.behavior }}
  behavior:
    {{- toYaml .Values.aggregator.autoscaling.behavior | nindent 4 }}
  {{- end }}
  scaleTargetRef:
    apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
    kind: StatefulSet
    name: {{ include "common.names.fullname" . }}
  minReplicas: {{ .Values.aggregator.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.aggregator.autoscaling.maxReplicas }}
  metrics:
    {{- include "common.tplvalues.render" (dict "value" .Values.aggregator.autoscaling.metrics "context" $) | nindent 4 }}
{{- end }}
