{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if .Values.pluginBarmanCloud.pdb.create }}
apiVersion: {{ include "common.capabilities.policy.apiVersion" . }}
kind: PodDisruptionBudget
metadata:
  name: {{ template "cloudnative-pg.plugin-barman-cloud.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- /* Updating app.kubernetes.io/name because to avoid "duplicate deployment" error: https://github.com/cloudnative-pg/cloudnative-pg/blob/9c2769815ff78cbfc28e2a2818f3a04add33477c/pkg/certs/operator_deployment.go#L120 */}}
  {{- $appNameLabels := dict "app.kubernetes.io/name" "plugin-barman-cloud" }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list $appNameLabels .Values.commonLabels) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: cloudnative-pg
    app.kubernetes.io/component: plugin-barman-cloud
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.pluginBarmanCloud.pdb.minAvailable }}
  minAvailable: {{ .Values.pluginBarmanCloud.pdb.minAvailable }}
  {{- end }}
  {{- if or .Values.pluginBarmanCloud.pdb.maxUnavailable ( not .Values.pluginBarmanCloud.pdb.minAvailable ) }}
  maxUnavailable: {{ .Values.pluginBarmanCloud.pdb.maxUnavailable | default 1 }}
  {{- end }}
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list $appNameLabels .Values.pluginBarmanCloud.podLabels .Values.commonLabels ) "context" . ) }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }}
      app.kubernetes.io/part-of: cloudnative-pg
      app.kubernetes.io/component: plugin-barman-cloud
{{- end }}
