Skip to content

Commit c5fd368

Browse files
authored
feat: Add Pod Disruption Budget support to Helm chart (#2380)
1 parent fcd4777 commit c5fd368

File tree

4 files changed

+275
-0
lines changed

4 files changed

+275
-0
lines changed

helm/polaris/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ ct install --namespace polaris --charts ./helm/polaris
311311
| persistence.relationalJdbc.secret.username | string | `"username"` | The secret key holding the database username for authentication |
312312
| persistence.type | string | `"in-memory"` | The type of persistence to use. Two built-in types are supported: in-memory and relational-jdbc. The eclipse-link type is also supported but is deprecated. |
313313
| podAnnotations | object | `{}` | Annotations to apply to polaris pods. |
314+
| podDisruptionBudget | object | `{"annotations":{},"enabled":false,"maxUnavailable":null,"minAvailable":null}` | Pod disruption budget settings. |
315+
| podDisruptionBudget.annotations | object | `{}` | Annotations to add to the pod disruption budget. |
316+
| podDisruptionBudget.enabled | bool | `false` | Specifies whether a pod disruption budget should be created. |
317+
| podDisruptionBudget.maxUnavailable | string | `nil` | The maximum number of pods that can be unavailable during disruptions. Can be an absolute number (ex: 5) or a percentage of desired pods (ex: 50%). IMPORTANT: Cannot be used simultaneously with minAvailable. |
318+
| podDisruptionBudget.minAvailable | string | `nil` | The minimum number of pods that should remain available during disruptions. Can be an absolute number (ex: 5) or a percentage of desired pods (ex: 50%). IMPORTANT: Cannot be used simultaneously with maxUnavailable. |
314319
| podLabels | object | `{}` | Additional Labels to apply to polaris pods. |
315320
| podSecurityContext | object | `{"fsGroup":10001,"seccompProfile":{"type":"RuntimeDefault"}}` | Security context for the polaris pod. See https://kubernetes.io/docs/tasks/configure-pod-container/security-context/. |
316321
| podSecurityContext.fsGroup | int | `10001` | GID 10001 is compatible with Polaris OSS default images; change this if you are using a different image. |
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{/*
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
*/}}
19+
20+
{{- if .Values.podDisruptionBudget.enabled -}}
21+
apiVersion: policy/v1
22+
kind: PodDisruptionBudget
23+
metadata:
24+
name: {{ include "polaris.fullname" . }}
25+
namespace: {{ .Release.Namespace }}
26+
labels:
27+
{{- include "polaris.labels" . | nindent 4 }}
28+
{{- if .Values.podDisruptionBudget.annotations }}
29+
annotations:
30+
{{- tpl (toYaml .Values.podDisruptionBudget.annotations) . | nindent 4 }}
31+
{{- end }}
32+
spec:
33+
{{- if and .Values.podDisruptionBudget.minAvailable .Values.podDisruptionBudget.maxUnavailable }}
34+
{{- fail "podDisruptionBudget.minAvailable and podDisruptionBudget.maxUnavailable cannot be both set." -}}
35+
{{- end }}
36+
{{- if .Values.podDisruptionBudget.minAvailable }}
37+
minAvailable: {{ .Values.podDisruptionBudget.minAvailable }}
38+
{{- end }}
39+
{{- if .Values.podDisruptionBudget.maxUnavailable }}
40+
maxUnavailable: {{ .Values.podDisruptionBudget.maxUnavailable }}
41+
{{- end }}
42+
selector:
43+
matchLabels:
44+
{{- include "polaris.selectorLabels" . | nindent 6 }}
45+
{{- end }}
Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
chart:
21+
version: 1.2.3
22+
appVersion: 4.5.6
23+
24+
release:
25+
name: polaris-release
26+
namespace: polaris-ns
27+
28+
templates:
29+
- poddisruptionbudget.yaml
30+
31+
tests:
32+
33+
# kind
34+
- it: should not create PDB by default
35+
asserts:
36+
- containsDocument:
37+
kind: PodDisruptionBudget
38+
apiVersion: policy/v1
39+
not: true
40+
- it: should create PDB when enabled
41+
set:
42+
podDisruptionBudget.enabled: true
43+
asserts:
44+
- containsDocument:
45+
kind: PodDisruptionBudget
46+
apiVersion: policy/v1
47+
48+
# metadata.name (with PDB enabled)
49+
- it: should set PDB name
50+
set:
51+
podDisruptionBudget.enabled: true
52+
asserts:
53+
- equal:
54+
path: metadata.name
55+
value: polaris-release
56+
- it: should set PDB name with override
57+
set:
58+
podDisruptionBudget.enabled: true
59+
nameOverride: polaris-override
60+
asserts:
61+
- equal:
62+
path: metadata.name
63+
value: polaris-release-polaris-override
64+
- it: should set PDB name with full override
65+
set:
66+
podDisruptionBudget.enabled: true
67+
fullnameOverride: polaris-override
68+
asserts:
69+
- equal:
70+
path: metadata.name
71+
value: polaris-override
72+
73+
# metadata.namespace (with PDB enabled)
74+
- it: should set PDB namespace
75+
set:
76+
podDisruptionBudget.enabled: true
77+
asserts:
78+
- equal:
79+
path: metadata.namespace
80+
value: polaris-ns
81+
82+
# metadata.labels (with PDB enabled)
83+
- it: should set PDB default labels
84+
set:
85+
podDisruptionBudget.enabled: true
86+
asserts:
87+
- isSubset:
88+
path: metadata.labels
89+
content:
90+
app.kubernetes.io/name: polaris
91+
app.kubernetes.io/instance: polaris-release
92+
app.kubernetes.io/version: 4.5.6
93+
app.kubernetes.io/managed-by: Helm
94+
helm.sh/chart: polaris-1.2.3
95+
96+
# metadata.annotations (with PDB enabled)
97+
- it: should not set annotations by default
98+
set:
99+
podDisruptionBudget.enabled: true
100+
asserts:
101+
- isNull:
102+
path: metadata.annotations
103+
- it: should set custom annotations
104+
set:
105+
podDisruptionBudget.enabled: true
106+
podDisruptionBudget.annotations:
107+
example.com/policy: "critical"
108+
kubernetes.io/description: "PDB for Polaris"
109+
asserts:
110+
- equal:
111+
path: metadata.annotations
112+
value:
113+
example.com/policy: "critical"
114+
kubernetes.io/description: "PDB for Polaris"
115+
- it: should template annotations
116+
set:
117+
podDisruptionBudget.enabled: true
118+
podDisruptionBudget.annotations:
119+
app.example.com/release: "{{ .Release.Name }}"
120+
asserts:
121+
- equal:
122+
path: metadata.annotations
123+
value:
124+
app.example.com/release: "polaris-release"
125+
126+
- it: should set custom maxUnavailable
127+
set:
128+
podDisruptionBudget.enabled: true
129+
podDisruptionBudget.maxUnavailable: 2
130+
asserts:
131+
- equal:
132+
path: spec.maxUnavailable
133+
value: 2
134+
- isNull:
135+
path: spec.minAvailable
136+
- it: should set maxUnavailable percentage
137+
set:
138+
podDisruptionBudget.enabled: true
139+
podDisruptionBudget.maxUnavailable: "50%"
140+
asserts:
141+
- equal:
142+
path: spec.maxUnavailable
143+
value: "50%"
144+
- isNull:
145+
path: spec.minAvailable
146+
147+
# spec.minAvailable
148+
- it: should set minAvailable and unset maxUnavailable
149+
set:
150+
podDisruptionBudget.enabled: true
151+
podDisruptionBudget.minAvailable: 2
152+
podDisruptionBudget.maxUnavailable: null
153+
asserts:
154+
- equal:
155+
path: spec.minAvailable
156+
value: 2
157+
- isNull:
158+
path: spec.maxUnavailable
159+
- it: should set minAvailable percentage
160+
set:
161+
podDisruptionBudget.enabled: true
162+
podDisruptionBudget.minAvailable: "75%"
163+
podDisruptionBudget.maxUnavailable: null
164+
asserts:
165+
- equal:
166+
path: spec.minAvailable
167+
value: "75%"
168+
- isNull:
169+
path: spec.maxUnavailable
170+
171+
# spec.selector.matchLabels
172+
- it: should set selector labels to match deployment
173+
set:
174+
podDisruptionBudget.enabled: true
175+
asserts:
176+
- equal:
177+
path: spec.selector.matchLabels
178+
value:
179+
app.kubernetes.io/name: polaris
180+
app.kubernetes.io/instance: polaris-release
181+
- it: should set selector labels with name override
182+
set:
183+
podDisruptionBudget.enabled: true
184+
nameOverride: polaris-override
185+
asserts:
186+
- equal:
187+
path: spec.selector.matchLabels
188+
value:
189+
app.kubernetes.io/name: polaris-override
190+
app.kubernetes.io/instance: polaris-release
191+
- it: should set selector labels with full name override
192+
set:
193+
podDisruptionBudget.enabled: true
194+
fullnameOverride: polaris-override
195+
asserts:
196+
- equal:
197+
path: spec.selector.matchLabels
198+
value:
199+
app.kubernetes.io/name: polaris
200+
app.kubernetes.io/instance: polaris-release
201+
202+
# validation tests
203+
- it: should fail when both minAvailable and maxUnavailable are set
204+
set:
205+
podDisruptionBudget.enabled: true
206+
podDisruptionBudget.minAvailable: 1
207+
podDisruptionBudget.maxUnavailable: 1
208+
asserts:
209+
- failedTemplate:
210+
errorMessage: "podDisruptionBudget.minAvailable and podDisruptionBudget.maxUnavailable cannot be both set."

helm/polaris/values.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ podLabels: {}
6262
# -- Additional Labels to apply to polaris configmap.
6363
configMapLabels: {}
6464

65+
# -- Pod disruption budget settings.
66+
podDisruptionBudget:
67+
# -- Specifies whether a pod disruption budget should be created.
68+
enabled: false
69+
# -- The minimum number of pods that should remain available during disruptions.
70+
# Can be an absolute number (ex: 5) or a percentage of desired pods (ex: 50%).
71+
# IMPORTANT: Cannot be used simultaneously with maxUnavailable.
72+
minAvailable: ~
73+
# -- The maximum number of pods that can be unavailable during disruptions.
74+
# Can be an absolute number (ex: 5) or a percentage of desired pods (ex: 50%).
75+
# IMPORTANT: Cannot be used simultaneously with minAvailable.
76+
maxUnavailable: ~
77+
# -- Annotations to add to the pod disruption budget.
78+
annotations: {}
79+
6580
# -- The number of old ReplicaSets to retain to allow rollback (if not set, the default Kubernetes value is set to 10).
6681
revisionHistoryLimit: ~
6782

0 commit comments

Comments
 (0)