Skip to content

Commit 4a5194f

Browse files
authored
feat: option to keep all services PVCs when uninstalling helm (#98)
Address issue #95 + part of #92
1 parent 8be949c commit 4a5194f

10 files changed

+241
-96
lines changed

.changeset/whole-badgers-make.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"helm-charts": patch
3+
---
4+
5+
feat: option to keep all services PVCs when uninstalling helm

charts/hdx-oss-v2/templates/claims/persistent-volume-claims.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

charts/hdx-oss-v2/templates/clickhouse-deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ metadata:
147147
name: {{ include "hdx-oss.fullname" . }}-clickhouse-data
148148
labels:
149149
{{- include "hdx-oss.labels" . | nindent 4 }}
150+
{{- if .Values.global.keepPVC }}
151+
annotations:
152+
"helm.sh/resource-policy": keep
153+
{{- end }}
150154
spec:
151155
accessModes:
152156
- ReadWriteOnce
@@ -163,6 +167,10 @@ metadata:
163167
name: {{ include "hdx-oss.fullname" . }}-clickhouse-logs
164168
labels:
165169
{{- include "hdx-oss.labels" . | nindent 4 }}
170+
{{- if .Values.global.keepPVC }}
171+
annotations:
172+
"helm.sh/resource-policy": keep
173+
{{- end }}
166174
spec:
167175
accessModes:
168176
- ReadWriteOnce

charts/hdx-oss-v2/templates/mongodb-deployment.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
11
{{- if .Values.mongodb.enabled }}
2+
{{- if .Values.mongodb.persistence.enabled }}
3+
apiVersion: v1
4+
kind: PersistentVolumeClaim
5+
metadata:
6+
name: {{ include "hdx-oss.fullname" . }}-mongodb
7+
labels:
8+
{{- include "hdx-oss.labels" . | nindent 4 }}
9+
{{- if .Values.global.keepPVC }}
10+
annotations:
11+
"helm.sh/resource-policy": keep
12+
{{- end }}
13+
spec:
14+
accessModes:
15+
- ReadWriteOnce
16+
{{- if .Values.global.storageClassName }}
17+
storageClassName: {{ .Values.global.storageClassName }}
18+
{{- end }}
19+
resources:
20+
requests:
21+
storage: {{ .Values.mongodb.persistence.dataSize }}
22+
---
23+
{{- end }}
224
apiVersion: apps/v1
325
kind: Deployment
426
metadata:

charts/hdx-oss-v2/tests/clickhouse-deployment_test.yaml

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,76 @@ tests:
266266
- documentIndex: 0
267267
equal:
268268
path: spec.template.spec.containers[0].readinessProbe.httpGet.port
269-
value: 8124
269+
value: 8124
270+
271+
- it: should add keep annotation to PVCs when global.keepPVC is true
272+
set:
273+
clickhouse:
274+
enabled: true
275+
persistence:
276+
enabled: true
277+
dataSize: 10Gi
278+
logSize: 5Gi
279+
global:
280+
keepPVC: true
281+
asserts:
282+
- documentIndex: 4
283+
isKind:
284+
of: PersistentVolumeClaim
285+
- documentIndex: 4
286+
equal:
287+
path: metadata.annotations["helm.sh/resource-policy"]
288+
value: keep
289+
- documentIndex: 5
290+
isKind:
291+
of: PersistentVolumeClaim
292+
- documentIndex: 5
293+
equal:
294+
path: metadata.annotations["helm.sh/resource-policy"]
295+
value: keep
296+
297+
- it: should not add keep annotation to PVCs when global.keepPVC is false
298+
set:
299+
clickhouse:
300+
enabled: true
301+
persistence:
302+
enabled: true
303+
dataSize: 10Gi
304+
logSize: 5Gi
305+
global:
306+
keepPVC: false
307+
asserts:
308+
- documentIndex: 4
309+
isKind:
310+
of: PersistentVolumeClaim
311+
- documentIndex: 4
312+
isNull:
313+
path: metadata.annotations
314+
- documentIndex: 5
315+
isKind:
316+
of: PersistentVolumeClaim
317+
- documentIndex: 5
318+
isNull:
319+
path: metadata.annotations
320+
321+
- it: should not add keep annotation to PVCs when global.keepPVC is not set
322+
set:
323+
clickhouse:
324+
enabled: true
325+
persistence:
326+
enabled: true
327+
dataSize: 10Gi
328+
logSize: 5Gi
329+
asserts:
330+
- documentIndex: 4
331+
isKind:
332+
of: PersistentVolumeClaim
333+
- documentIndex: 4
334+
isNull:
335+
path: metadata.annotations
336+
- documentIndex: 5
337+
isKind:
338+
of: PersistentVolumeClaim
339+
- documentIndex: 5
340+
isNull:
341+
path: metadata.annotations

charts/hdx-oss-v2/tests/mongodb-deployment_test.yaml

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ tests:
88
image: mongo:5.0.14-focal
99
port: 27017
1010
enabled: true
11+
persistence:
12+
enabled: false
1113
asserts:
1214
- hasDocuments:
1315
count: 2
@@ -26,38 +28,57 @@ tests:
2628
- hasDocuments:
2729
count: 0
2830

29-
- it: should use PVC when persistence is enabled
31+
- it: should create PVC, deployment and service when persistence is enabled
3032
set:
3133
mongodb:
3234
enabled: true
3335
persistence:
3436
enabled: true
37+
dataSize: 10Gi
3538
asserts:
39+
- hasDocuments:
40+
count: 3
3641
- documentIndex: 0
3742
isKind:
38-
of: Deployment
43+
of: PersistentVolumeClaim
44+
- documentIndex: 0
45+
matchRegex:
46+
path: metadata.name
47+
pattern: .*-mongodb$
3948
- documentIndex: 0
49+
equal:
50+
path: spec.resources.requests.storage
51+
value: 10Gi
52+
- documentIndex: 1
53+
isKind:
54+
of: Deployment
55+
- documentIndex: 1
4056
equal:
4157
path: spec.template.spec.volumes[0].name
4258
value: mongodb-data
43-
- documentIndex: 0
59+
- documentIndex: 1
4460
isNotNull:
4561
path: spec.template.spec.volumes[0].persistentVolumeClaim
46-
- documentIndex: 0
62+
- documentIndex: 1
4763
matchRegex:
4864
path: spec.template.spec.volumes[0].persistentVolumeClaim.claimName
4965
pattern: .*-mongodb$
50-
- documentIndex: 0
66+
- documentIndex: 1
5167
isNull:
5268
path: spec.template.spec.volumes[0].emptyDir
69+
- documentIndex: 2
70+
isKind:
71+
of: Service
5372

54-
- it: should use emptyDir when persistence is disabled
73+
- it: should use emptyDir when persistence is disabled and not create PVC
5574
set:
5675
mongodb:
5776
enabled: true
5877
persistence:
5978
enabled: false
6079
asserts:
80+
- hasDocuments:
81+
count: 2 # Only Deployment and Service, no PVC
6182
- documentIndex: 0
6283
isKind:
6384
of: Deployment
@@ -71,11 +92,16 @@ tests:
7192
- documentIndex: 0
7293
isNull:
7394
path: spec.template.spec.volumes[0].persistentVolumeClaim
95+
- documentIndex: 1
96+
isKind:
97+
of: Service
7498

7599
- it: should include livenessProbe with tcpSocket when enabled
76100
set:
77101
mongodb:
78102
enabled: true
103+
persistence:
104+
enabled: false # To ensure predictable document ordering
79105
asserts:
80106
- documentIndex: 0
81107
isSubset:
@@ -92,6 +118,8 @@ tests:
92118
set:
93119
mongodb:
94120
enabled: true
121+
persistence:
122+
enabled: false # To ensure predictable document ordering
95123
asserts:
96124
- documentIndex: 0
97125
isSubset:
@@ -108,6 +136,8 @@ tests:
108136
set:
109137
mongodb:
110138
enabled: true
139+
persistence:
140+
enabled: false # To ensure predictable document ordering
111141
livenessProbe:
112142
enabled: false
113143
asserts:
@@ -119,6 +149,8 @@ tests:
119149
set:
120150
mongodb:
121151
enabled: true
152+
persistence:
153+
enabled: false # To ensure predictable document ordering
122154
readinessProbe:
123155
enabled: false
124156
asserts:
@@ -130,6 +162,8 @@ tests:
130162
set:
131163
mongodb:
132164
enabled: true
165+
persistence:
166+
enabled: false # To ensure predictable document ordering
133167
livenessProbe:
134168
enabled: true
135169
initialDelaySeconds: 20
@@ -152,6 +186,8 @@ tests:
152186
set:
153187
mongodb:
154188
enabled: true
189+
persistence:
190+
enabled: false # To ensure predictable document ordering
155191
readinessProbe:
156192
enabled: true
157193
initialDelaySeconds: 5
@@ -169,3 +205,63 @@ tests:
169205
periodSeconds: 20
170206
timeoutSeconds: 3
171207
failureThreshold: 2
208+
209+
- it: should not create PVC when mongodb is disabled
210+
set:
211+
mongodb:
212+
enabled: false
213+
persistence:
214+
enabled: true # Even with persistence enabled, no PVC should be created
215+
asserts:
216+
- hasDocuments:
217+
count: 0 # No resources should be created
218+
219+
- it: should include keep annotation on PVC when global.keepPVC is true
220+
set:
221+
mongodb:
222+
enabled: true
223+
persistence:
224+
enabled: true
225+
global:
226+
keepPVC: true
227+
asserts:
228+
- documentIndex: 0
229+
isKind:
230+
of: PersistentVolumeClaim
231+
- documentIndex: 0
232+
equal:
233+
path: metadata.annotations["helm.sh/resource-policy"]
234+
value: keep
235+
236+
- it: should not include keep annotation on PVC when global.keepPVC is false
237+
set:
238+
mongodb:
239+
enabled: true
240+
persistence:
241+
enabled: true
242+
global:
243+
keepPVC: false
244+
asserts:
245+
- documentIndex: 0
246+
isKind:
247+
of: PersistentVolumeClaim
248+
- documentIndex: 0
249+
isNull:
250+
path: metadata.annotations["helm.sh/resource-policy"]
251+
252+
- it: should use global storageClassName when specified
253+
set:
254+
mongodb:
255+
enabled: true
256+
persistence:
257+
enabled: true
258+
global:
259+
storageClassName: fast-ssd
260+
asserts:
261+
- documentIndex: 0
262+
isKind:
263+
of: PersistentVolumeClaim
264+
- documentIndex: 0
265+
equal:
266+
path: spec.storageClassName
267+
value: fast-ssd

charts/hdx-oss-v2/tests/node-selector_test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ tests:
128128
- it: should apply nodeSelector and tolerations to MongoDB deployment
129129
set:
130130
mongodb:
131+
persistence:
132+
enabled: false # Disable PVC to have predictable document order
131133
nodeSelector:
132134
node-role: database
133135
tolerations:
@@ -254,6 +256,8 @@ tests:
254256
value: clickhouse
255257
effect: NoExecute
256258
mongodb:
259+
persistence:
260+
enabled: false # Disable PVC to have predictable document order
257261
nodeSelector:
258262
component: database
259263
storage: standard

0 commit comments

Comments
 (0)