Skip to content

Commit a6d8916

Browse files
committed
feat: Add unit tests for Pod Disruption Budget configuration
1 parent e7252f2 commit a6d8916

File tree

1 file changed

+224
-0
lines changed

1 file changed

+224
-0
lines changed
Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
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+
# spec.maxUnavailable (default behavior)
127+
- it: should set default maxUnavailable
128+
set:
129+
podDisruptionBudget.enabled: true
130+
asserts:
131+
- equal:
132+
path: spec.maxUnavailable
133+
value: 1
134+
- isNull:
135+
path: spec.minAvailable
136+
- it: should set custom maxUnavailable
137+
set:
138+
podDisruptionBudget.enabled: true
139+
podDisruptionBudget.maxUnavailable: 2
140+
asserts:
141+
- equal:
142+
path: spec.maxUnavailable
143+
value: 2
144+
- isNull:
145+
path: spec.minAvailable
146+
- it: should set maxUnavailable percentage
147+
set:
148+
podDisruptionBudget.enabled: true
149+
podDisruptionBudget.maxUnavailable: "50%"
150+
asserts:
151+
- equal:
152+
path: spec.maxUnavailable
153+
value: "50%"
154+
- isNull:
155+
path: spec.minAvailable
156+
157+
# spec.minAvailable
158+
- it: should set minAvailable and unset maxUnavailable
159+
set:
160+
podDisruptionBudget.enabled: true
161+
podDisruptionBudget.minAvailable: 2
162+
podDisruptionBudget.maxUnavailable: null
163+
asserts:
164+
- equal:
165+
path: spec.minAvailable
166+
value: 2
167+
- isNull:
168+
path: spec.maxUnavailable
169+
- it: should set minAvailable percentage
170+
set:
171+
podDisruptionBudget.enabled: true
172+
podDisruptionBudget.minAvailable: "75%"
173+
podDisruptionBudget.maxUnavailable: null
174+
asserts:
175+
- equal:
176+
path: spec.minAvailable
177+
value: "75%"
178+
- isNull:
179+
path: spec.maxUnavailable
180+
181+
# spec.selector.matchLabels
182+
- it: should set selector labels to match deployment
183+
set:
184+
podDisruptionBudget.enabled: true
185+
asserts:
186+
- equal:
187+
path: spec.selector.matchLabels
188+
value:
189+
app.kubernetes.io/name: polaris
190+
app.kubernetes.io/instance: polaris-release
191+
- it: should set selector labels with name override
192+
set:
193+
podDisruptionBudget.enabled: true
194+
nameOverride: polaris-override
195+
asserts:
196+
- equal:
197+
path: spec.selector.matchLabels
198+
value:
199+
app.kubernetes.io/name: polaris-override
200+
app.kubernetes.io/instance: polaris-release
201+
- it: should set selector labels with full name override
202+
set:
203+
podDisruptionBudget.enabled: true
204+
fullnameOverride: polaris-override
205+
asserts:
206+
- equal:
207+
path: spec.selector.matchLabels
208+
value:
209+
app.kubernetes.io/name: polaris
210+
app.kubernetes.io/instance: polaris-release
211+
212+
# validation tests
213+
- it: should handle both minAvailable and maxUnavailable set (minAvailable takes precedence)
214+
set:
215+
podDisruptionBudget.enabled: true
216+
podDisruptionBudget.minAvailable: 1
217+
podDisruptionBudget.maxUnavailable: 1
218+
asserts:
219+
- equal:
220+
path: spec.minAvailable
221+
value: 1
222+
- equal:
223+
path: spec.maxUnavailable
224+
value: 1

0 commit comments

Comments
 (0)