{{- if .Values.authorize.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  labels:
    app.kubernetes.io/name: {{ template "pomerium.authorize.name" . }}
    helm.sh/chart: {{ template "pomerium.chart" . }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/component: authorize
  name: {{ template "pomerium.authorize.fullname" . }}-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ template "pomerium.authorize.fullname" . }}
  minReplicas: {{ .Values.authorize.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.authorize.autoscaling.maxReplicas }}
  metrics:
{{- with .Values.authorize.autoscaling.targetMemoryUtilizationPercentage }}
    - type: Resource
      resource:
        name: memory
        targetAverageUtilization: {{ . }}
{{- end }}
{{- with .Values.authorize.autoscaling.targetCPUUtilizationPercentage }}
    - type: Resource
      resource:
        name: cpu
        targetAverageUtilization: {{ . }}
{{- end }}
{{- end }}
