Skip to content

Commit 9317d85

Browse files
committed
PDB Availability Bugfix
- Fixed PDB rendering both an explicit minAvailable and maxUnavailable at once
1 parent acbf601 commit 9317d85

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

chart/templates/poddisruptionbudget.yaml

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,42 @@ apiVersion: policy/v1
77
kind: PodDisruptionBudget
88
metadata:
99
name: {{ include "vso.chart.fullname" . }}
10+
namespace: {{ .Release.Namespace }}
1011
labels:
1112
app.kubernetes.io/component: controller-manager
1213
control-plane: controller-manager
1314
{{- include "vso.chart.labels" . | nindent 4 }}
14-
namespace: {{ .Release.Namespace }}
1515
spec:
16-
{{/* Throw an error if both maxUnavailable and minAvailable are set and non-zero */}}
17-
{{- $maxUnavailable := toString .Values.controller.podDisruptionBudget.maxUnavailable | trim }}
18-
{{- $minAvailable := toString .Values.controller.podDisruptionBudget.minAvailable | trim }}
19-
{{- if and (not (empty $maxUnavailable)) (not (empty $minAvailable)) (ne $maxUnavailable "0") (ne $minAvailable "0") }}
20-
{{- fail "You cannot set both maxUnavailable and minAvailable in the PodDisruptionBudget" }}
21-
{{- end }}
16+
{{- $rawMax := default "" .Values.controller.podDisruptionBudget.maxUnavailable -}}
17+
{{- $rawMin := default "" .Values.controller.podDisruptionBudget.minAvailable -}}
18+
{{- $max := toString $rawMax | trim -}}
19+
{{- $min := toString $rawMin | trim -}}
2220

23-
{{/* If maxUnavailable is set, use it */}}
24-
{{- if not (empty $maxUnavailable) }}
25-
maxUnavailable:
26-
{{- if contains "%" $maxUnavailable }}
27-
"{{ $maxUnavailable }}"
28-
{{- else }}
29-
{{ $maxUnavailable }}
30-
{{- end }}
31-
{{- end }}
21+
{{- /* Presence & zero-ness checks */ -}}
22+
{{- $maxProvided := ne $max "" -}}
23+
{{- $minProvided := ne $min "" -}}
24+
{{- $maxZero := or (eq $max "0") (eq $max "0%") -}}
25+
{{- $minZero := or (eq $min "0") (eq $min "0%") -}}
26+
{{- $maxNonZero := and $maxProvided (not $maxZero) -}}
27+
{{- $minNonZero := and $minProvided (not $minZero) -}}
3228

33-
{{/* If minAvailable is set, use it */}}
34-
{{- if not (empty $minAvailable) }}
35-
minAvailable:
36-
{{- if contains "%" $minAvailable }}
37-
"{{ $minAvailable }}"
38-
{{- else }}
39-
{{ $minAvailable }}
40-
{{- end }}
29+
{{- /* Hard stop only when both sides are non-zero (K8s forbids both keys at once) */ -}}
30+
{{- if and $minNonZero $maxNonZero -}}
31+
{{- fail "controller.podDisruptionBudget: you cannot set both maxUnavailable and minAvailable to non-zero values." -}}
4132
{{- end }}
4233

34+
{{- /* Emit exactly one key */ -}}
35+
{{- if $minNonZero }}
36+
minAvailable:{{ if contains "%" $min }} "{{ $min }}"{{ else }} {{ $min }}{{ end }}
37+
{{- else if $maxNonZero }}
38+
maxUnavailable:{{ if contains "%" $max }} "{{ $max }}"{{ else }} {{ $max }}{{ end }}
39+
{{- else if and $minProvided (not $maxProvided) }}
40+
minAvailable:{{ if contains "%" $min }} "{{ $min }}"{{ else }} {{ $min }}{{ end }}
41+
{{- else if and $maxProvided (not $minProvided) }}
42+
maxUnavailable:{{ if contains "%" $max }} "{{ $max }}"{{ else }} {{ $max }}{{ end }}
43+
{{- else }}
44+
minAvailable: 1
45+
{{- end }}
4346
selector:
4447
matchLabels:
4548
{{- include "vso.chart.selectorLabels" . | nindent 6 }}

0 commit comments

Comments
 (0)