{{- if or .Values.etcdOperator.vpa.enabled .Values.kubeRbacProxy.vpa.enabled }}
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: {{ include "etcd-operator.fullname" . }}-controller-manager
  labels:
    {{- include "etcd-operator.labels" . | nindent 4 }}
spec:
  targetRef:
    apiVersion: "apps/v1"
    kind: Deployment
    name: {{ include "etcd-operator.fullname" . }}-controller-manager
  updatePolicy:
    updateMode: {{ .Values.vpa.updatePolicy | default "Auto" | quote }}
  resourcePolicy:
    containerPolicies:
    {{- if .Values.etcdOperator.vpa.enabled }}
      - containerName: etcd-operator
        {{- with .Values.etcdOperator.vpa.minAllowed }}
        minAllowed:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        {{- with .Values.etcdOperator.vpa.maxAllowed }}
        maxAllowed:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        controlledResources: ["cpu", "memory"]
    {{- end }}
    {{- if .Values.kubeRbacProxy.vpa.enabled }}
      - containerName: kube-rbac-proxy
        {{- with .Values.kubeRbacProxy.vpa.minAllowed }}
        minAllowed:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        {{- with .Values.kubeRbacProxy.vpa.maxAllowed }}
        maxAllowed:
          {{- toYaml . | nindent 10 }}
        {{- end }}
        controlledResources: ["cpu", "memory"]
    {{- end }}
{{- end }}
