{{- if .Values.controller.podDisruptionBudget.enabled }}
{{- $kubeTargetVersion := default .Capabilities.KubeVersion.GitVersion .Values.kubeTargetVersionOverride }}
{{- if semverCompare ">=1.21-0" $kubeTargetVersion -}}
apiVersion: policy/v1
{{- else if semverCompare ">=1.5-0" $kubeTargetVersion -}}
apiVersion: policy/v1beta1
{{- else -}}
apiVersion: {{ .Values.controller.podDisruptionBudget.apiVersion }}
{{- end }}
kind: PodDisruptionBudget
metadata:
  name: {{ template "jenkins.fullname" . }}-pdb
  namespace: {{ template "jenkins.namespace" . }}
  labels:
    "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
    {{- if .Values.renderHelmLabels }}
    "helm.sh/chart": "{{ template "jenkins.label" .}}"
    {{- end }}
    "app.kubernetes.io/managed-by": "{{ .Release.Service }}"
    "app.kubernetes.io/instance": "{{ .Release.Name }}"
    "app.kubernetes.io/component": "{{ .Values.controller.componentName }}"
    {{- if .Values.controller.podDisruptionBudget.labels -}}
    {{ toYaml .Values.controller.podDisruptionBudget.labels | nindent 4 }}
    {{- end }}
  {{- if .Values.controller.podDisruptionBudget.annotations }}
  annotations: {{ toYaml .Values.controller.podDisruptionBudget.annotations | nindent 4 }}
  {{- end }}
spec:
  maxUnavailable: {{ .Values.controller.podDisruptionBudget.maxUnavailable }}
  selector:
    matchLabels:
      "app.kubernetes.io/instance": "{{ .Release.Name }}"
      "app.kubernetes.io/name": '{{ template "jenkins.name" .}}'
{{- end }}
