{{- if and (.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1") (.Values.prometheusOperator.verticalPodAutoscaler.enabled) }}
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
  name: {{ template "kube-prometheus-stack.operator.fullname" . }}
  namespace: {{ template "kube-prometheus-stack.namespace" . }}
  labels:
    {{- include "kube-prometheus-stack.prometheus-operator.labels" . | nindent 4 }}
spec:
  {{- with .Values.prometheusOperator.verticalPodAutoscaler.recommenders }}
  recommenders:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  resourcePolicy:
    containerPolicies:
    - containerName: {{ template "kube-prometheus-stack.name" . }}
      {{- with .Values.prometheusOperator.verticalPodAutoscaler.controlledResources }}
      controlledResources:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- if .Values.prometheusOperator.verticalPodAutoscaler.controlledValues }}
      controlledValues: {{ .Values.prometheusOperator.verticalPodAutoscaler.controlledValues }}
      {{- end }}
      {{- if .Values.prometheusOperator.verticalPodAutoscaler.maxAllowed }}
      maxAllowed:
        {{- toYaml .Values.prometheusOperator.verticalPodAutoscaler.maxAllowed | nindent 8 }}
      {{- end }}
      {{- if .Values.prometheusOperator.verticalPodAutoscaler.minAllowed }}
      minAllowed:
        {{- toYaml .Values.prometheusOperator.verticalPodAutoscaler.minAllowed | nindent 8 }}
      {{- end }}
  targetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: {{ template "kube-prometheus-stack.operator.fullname" . }}
  {{- with .Values.prometheusOperator.verticalPodAutoscaler.updatePolicy }}
  updatePolicy:
    {{- toYaml . | nindent 4 }}
  {{- end }}
{{- end }}
