{{- if and .Values.storegateway.enabled .Values.storegateway.pdb.create .Values.storegateway.sharded.enabled }}

{{- $shards := int 0 }}
{{- if .Values.storegateway.sharded.hashPartitioning.shards }}
  {{- $shards = int .Values.storegateway.sharded.hashPartitioning.shards }}
{{- else }}
  {{- $shards = len .Values.storegateway.sharded.timePartitioning }}
{{- end }}

{{- range $index, $_ := until $shards }}
apiVersion: {{ include "common.capabilities.policy.apiVersion" $ }}
kind: PodDisruptionBudget
metadata:
  name: {{ printf "%s-storegateway-%s" (include "common.names.fullname" $) (toString $index) | trunc 63 | trimSuffix "-" }}
  namespace: {{ $.Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" $ | nindent 4 }}
    app.kubernetes.io/component: storegateway
    shard: {{ $index | quote }}
    {{- if $.Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" $.Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if $.Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  {{- if $.Values.storegateway.pdb.minAvailable }}
  minAvailable: {{ $.Values.storegateway.pdb.minAvailable }}
  {{- end }}
  {{- if $.Values.storegateway.pdb.maxUnavailable }}
  maxUnavailable: {{ $.Values.storegateway.pdb.maxUnavailable }}
  {{- end }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" $ | nindent 6 }}
      app.kubernetes.io/component: storegateway
      shard: {{ $index | quote }}
---
{{- end }}
{{- end }}
