{{- if and (eq .Values.controller.kind "Deployment") .Values.controller.autoscaling.enabled }}
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  labels:
    app: {{ template "haproxy-ingress.name" . }}
    chart: {{ template "haproxy-ingress.chart" . }}
    component: "{{ .Values.controller.name }}"
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  name: {{ template "haproxy-ingress.controller.fullname" . }}
spec:
  scaleTargetRef:
    apiVersion: apps/v1beta2
    kind: Deployment
    name: {{ template "haproxy-ingress.controller.fullname" . }}
  minReplicas: {{ .Values.controller.autoscaling.minReplicas }}
  maxReplicas: {{ .Values.controller.autoscaling.maxReplicas }}
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: {{ .Values.controller.autoscaling.targetCPUUtilizationPercentage }}
    - type: Resource
      resource:
        name: memory
        target:
          type: Utilization
          averageUtilization: {{ .Values.controller.autoscaling.targetMemoryUtilizationPercentage }}
{{- if .Values.controller.autoscaling.customMetrics }}
{{ toYaml .Values.controller.autoscaling.customMetrics | indent 4 }}
{{- end }}
{{- end }}
