{{- if .Values.ingester.autoscaling.enabled }}
apiVersion: {{ include "common.capabilities.hpa.apiVersion" ( dict "context" $ ) }}
kind: HorizontalPodAutoscaler
metadata:
  name: {{ template "jaeger.ingester.name" . }}
  labels:
    {{- include "jaeger.labels" . | nindent 4 }}
    app.kubernetes.io/component: ingester
spec:
  scaleTargetRef:
    apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
    kind: Deployment
    name: {{ template "jaeger.ingester.name" . }}
  minReplicas: {{ .Values.ingester.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.ingester.autoscaling.maxReplicas }}
  metrics:
  {{- if .Values.ingester.autoscaling.targetMemoryUtilizationPercentage }}
    - type: Resource
      resource:
        name: memory
        {{- if eq "autoscaling/v2" (include "common.capabilities.hpa.apiVersion" ( dict "context" $ )) }}
        target:
          averageUtilization: {{ .Values.ingester.autoscaling.targetMemoryUtilizationPercentage }}
          type: Utilization
        {{- else }}            
        targetAverageUtilization: {{ .Values.ingester.autoscaling.targetMemoryUtilizationPercentage }}
        {{- end }} 
  {{- end }}
    - type: Resource
      resource:
        name: cpu
        {{- if eq "autoscaling/v2" (include "common.capabilities.hpa.apiVersion" ( dict "context" $ )) }}        
        target:
          averageUtilization: {{ .Values.ingester.autoscaling.targetCPUUtilizationPercentage | default 80 }}
          type: Utilization
        {{- else }}    
        targetAverageUtilization: {{ .Values.ingester.autoscaling.targetCPUUtilizationPercentage | default 80 }}
        {{- end }}
  {{- with .Values.ingester.autoscaling.behavior }}
  behavior:
    {{- toYaml . | nindent 4 }}
  {{- end }}   
{{- end }}
