{{- if and .Values.querier.enabled .Values.querier.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "thanos.fullname" . }}-querier
  labels: {{- include "thanos.labels" . | nindent 4 }}
    app.kubernetes.io/component: querier
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "thanos.fullname" . }}-querier
  minReplicas: {{ .Values.querier.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.querier.autoscaling.maxReplicas }}
  metrics:
    {{- if .Values.querier.autoscaling.targetCPU }}
    - type: Resource
      resource:
        name: cpu
        targetAverageUtilization: {{ .Values.querier.autoscaling.targetCPU }}
    {{- end }}
    {{- if .Values.querier.autoscaling.targetMemory }}
    - type: Resource
      resource:
        name: memory
        targetAverageUtilization: {{ .Values.querier.autoscaling.targetMemory  }}
    {{- end }}
{{- end }}    
