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

{{- if and .Values.receiveDistributor.enabled .Values.receiveDistributor.autoscaling.enabled }}
apiVersion: {{ include "common.capabilities.hpa.apiVersion" ( dict "context" $ ) }}
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "thanos.receive-distributor.fullname" . }}
  namespace: {{ include "common.names.namespace" . }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: receive-distributor
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.receiveDistributor.autoscaling.behavior }}
  behavior:
    {{- toYaml .Values.receiveDistributor.autoscaling.behavior | nindent 4 }}
  {{- end }}
  scaleTargetRef:
    apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
    kind: Deployment
    name: {{ include "thanos.receive-distributor.fullname" . }}
  minReplicas: {{ .Values.receiveDistributor.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.receiveDistributor.autoscaling.maxReplicas }}
  metrics:
    {{- if .Values.receiveDistributor.autoscaling.targetMemory }}
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: {{ .Values.receiveDistributor.autoscaling.targetMemory }}
    {{- end }}
    {{- if .Values.receiveDistributor.autoscaling.targetCPU }}
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: {{ .Values.receiveDistributor.autoscaling.targetCPU }}
    {{- end }}
{{- end }}
