{{- if .Values.gateway.autoscaling.enabled }}
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: {{ include "gateway.name" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "gateway.labels" . | nindent 4 }}
  annotations:
    {{- .Values.gateway.annotations | toYaml | nindent 4 }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ include "gateway.name" . }}
  minReplicas: {{ .Values.gateway.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.gateway.autoscaling.maxReplicas }}
  metrics:
    {{- if .Values.gateway.autoscaling.targetCPUUtilizationPercentage }}
    - type: Resource
      resource:
        name: cpu
        target:
          averageUtilization: {{ .Values.gateway.autoscaling.targetCPUUtilizationPercentage }}
          type: Utilization
    {{- end }}

{{- end }}
