{{- if .Values.defaultBackend.enabled -}}
{{- $replicas := .Values.defaultBackend.replicaCount }}
{{- if .Values.defaultBackend.autoscaling.enabled }}
{{- $replicas = .Values.defaultBackend.autoscaling.minReplicas }}
{{- end }}
{{- if gt ($replicas | int) 1 }}
apiVersion: {{ ternary "policy/v1" "policy/v1beta1" (semverCompare ">=1.21.0-0" .Capabilities.KubeVersion.Version) }}
kind: PodDisruptionBudget
metadata:
  labels:
    {{- include "ingress-nginx.labels" . | nindent 4 }}
    app.kubernetes.io/component: default-backend
    {{- with .Values.defaultBackend.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  name: {{ include "ingress-nginx.defaultBackend.fullname" . }}
  namespace: {{ include "ingress-nginx.namespace" . }}
spec:
  selector:
    matchLabels:
      {{- include "ingress-nginx.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: default-backend
  {{- if and .Values.defaultBackend.minAvailable (not (hasKey .Values.defaultBackend "maxUnavailable")) }}
  minAvailable: {{ .Values.defaultBackend.minAvailable }}
  {{- else if .Values.defaultBackend.maxUnavailable }}
  maxUnavailable: {{ .Values.defaultBackend.maxUnavailable }}
  {{- end }}
  {{- if .Values.defaultBackend.unhealthyPodEvictionPolicy }}
  unhealthyPodEvictionPolicy: {{ .Values.defaultBackend.unhealthyPodEvictionPolicy }}
  {{- end }}
{{- end }}
{{- end }}
