{{- if and (.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1/VerticalPodAutoscaler") .Values.autoscaling.vpa.enabled }}
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: {{ include "fluent-bit.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "fluent-bit.labels" . | nindent 4 }}
  {{- with .Values.autoscaling.vpa.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  resourcePolicy:
    containerPolicies:
    - containerName: {{ .Chart.Name }}
      {{- with .Values.autoscaling.vpa.controlledResources }}
      controlledResources: 
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.autoscaling.vpa.maxAllowed }}
      maxAllowed:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.autoscaling.vpa.minAllowed }}
      minAllowed:
        {{- toYaml . | nindent 8 }}
      {{- end }}
  targetRef:
    apiVersion: apps/v1
    kind: {{ .Values.kind }}
    name: {{ include "fluent-bit.fullname" . }}
  {{- if .Values.autoscaling.vpa.updatePolicy }}
  updatePolicy:
    {{- with .Values.autoscaling.vpa.updatePolicy.updateMode }}
    updateMode: {{ . }}
    {{- end }}
  {{- end }}
{{- end }}
