{{- $vpa := .Values.verticalPodAutoscaling }}
{{- if and (.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1") $vpa.enabled }}
{{- $ctx := dict "helm" . }}
{{- $fullname := include "vm.plain.fullname" $ctx }}
{{- $ns := include "vm.namespace" $ctx }}
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  {{- $_ := set $ctx "extraLabels" .Values.extraLabels }}
  labels: {{ include "vm.labels" $ctx | nindent 4 }}
  {{- $_ := unset $ctx "extraLabels" }}
  name: {{ $fullname }}
  namespace: {{ $ns }}
spec:
  {{- with $vpa.recommenders }}
  recommenders: {{ toYaml . | nindent 4 }}
  {{- end }}
  targetRef:
    apiVersion: apps/v1
    kind: {{ title .Values.mode }}
    name: {{ $fullname }}
  {{- with $vpa.updatePolicy }}
  updatePolicy: {{ toYaml . | nindent 4 }}
  {{- end }}
  {{- with $vpa.resourcePolicy }}
  resourcePolicy: {{ toYaml . | nindent 4 }}
  {{- end }}
{{- end }}
