{{- /* PodDisruptionBudgets for high-availability services */ -}}

{{- if and .Values.app.enabled .Values.app.pdb.enabled -}}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: {{ include "gitdata.fullname" . }}-app
  namespace: {{ include "gitdata.namespace" . }}
  labels:
    app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-app
    app.kubernetes.io/instance: {{ .Release.Name }}
spec:
  {{- if .Values.app.pdb.minAvailable }}
  minAvailable: {{ .Values.app.pdb.minAvailable }}
  {{- else if .Values.app.pdb.maxUnavailable }}
  maxUnavailable: {{ .Values.app.pdb.maxUnavailable }}
  {{- else }}
  minAvailable: 1
  {{- end }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-app
      app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- if and .Values.gitHook.enabled .Values.gitHook.pdb.enabled -}}
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: {{ include "gitdata.fullname" . }}-git-hook
  namespace: {{ include "gitdata.namespace" . }}
  labels:
    app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-git-hook
    app.kubernetes.io/instance: {{ .Release.Name }}
spec:
  {{- if .Values.gitHook.pdb.minAvailable }}
  minAvailable: {{ .Values.gitHook.pdb.minAvailable }}
  {{- else if .Values.gitHook.pdb.maxUnavailable }}
  maxUnavailable: {{ .Values.gitHook.pdb.maxUnavailable }}
  {{- else }}
  minAvailable: 1
  {{- end }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-git-hook
      app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
