diff --git a/.changeset/whole-badgers-make.md b/.changeset/whole-badgers-make.md new file mode 100644 index 0000000..a0d9a03 --- /dev/null +++ b/.changeset/whole-badgers-make.md @@ -0,0 +1,5 @@ +--- +"helm-charts": patch +--- + +feat: option to keep all services PVCs when uninstalling helm diff --git a/charts/hdx-oss-v2/templates/claims/persistent-volume-claims.yaml b/charts/hdx-oss-v2/templates/claims/persistent-volume-claims.yaml deleted file mode 100644 index 35bb000..0000000 --- a/charts/hdx-oss-v2/templates/claims/persistent-volume-claims.yaml +++ /dev/null @@ -1,18 +0,0 @@ -{{- if .Values.mongodb.persistence.enabled }} -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: {{ include "hdx-oss.fullname" . }}-mongodb - labels: - {{- include "hdx-oss.labels" . | nindent 4 }} -spec: - accessModes: - - ReadWriteOnce - {{- if .Values.global.storageClassName }} - storageClassName: {{ .Values.global.storageClassName }} - {{- end }} - resources: - requests: - storage: {{ .Values.mongodb.persistence.dataSize }} ---- -{{- end }} diff --git a/charts/hdx-oss-v2/templates/clickhouse-deployment.yaml b/charts/hdx-oss-v2/templates/clickhouse-deployment.yaml index 8799a3b..353400f 100644 --- a/charts/hdx-oss-v2/templates/clickhouse-deployment.yaml +++ b/charts/hdx-oss-v2/templates/clickhouse-deployment.yaml @@ -147,6 +147,10 @@ metadata: name: {{ include "hdx-oss.fullname" . }}-clickhouse-data labels: {{- include "hdx-oss.labels" . | nindent 4 }} + {{- if .Values.global.keepPVC }} + annotations: + "helm.sh/resource-policy": keep + {{- end }} spec: accessModes: - ReadWriteOnce @@ -163,6 +167,10 @@ metadata: name: {{ include "hdx-oss.fullname" . }}-clickhouse-logs labels: {{- include "hdx-oss.labels" . | nindent 4 }} + {{- if .Values.global.keepPVC }} + annotations: + "helm.sh/resource-policy": keep + {{- end }} spec: accessModes: - ReadWriteOnce diff --git a/charts/hdx-oss-v2/templates/mongodb-deployment.yaml b/charts/hdx-oss-v2/templates/mongodb-deployment.yaml index 5d23559..7616a86 100644 --- a/charts/hdx-oss-v2/templates/mongodb-deployment.yaml +++ b/charts/hdx-oss-v2/templates/mongodb-deployment.yaml @@ -1,4 +1,26 @@ {{- if .Values.mongodb.enabled }} +{{- if .Values.mongodb.persistence.enabled }} +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: {{ include "hdx-oss.fullname" . }}-mongodb + labels: + {{- include "hdx-oss.labels" . | nindent 4 }} + {{- if .Values.global.keepPVC }} + annotations: + "helm.sh/resource-policy": keep + {{- end }} +spec: + accessModes: + - ReadWriteOnce + {{- if .Values.global.storageClassName }} + storageClassName: {{ .Values.global.storageClassName }} + {{- end }} + resources: + requests: + storage: {{ .Values.mongodb.persistence.dataSize }} +--- +{{- end }} apiVersion: apps/v1 kind: Deployment metadata: diff --git a/charts/hdx-oss-v2/tests/clickhouse-deployment_test.yaml b/charts/hdx-oss-v2/tests/clickhouse-deployment_test.yaml index 05f4135..19f7719 100644 --- a/charts/hdx-oss-v2/tests/clickhouse-deployment_test.yaml +++ b/charts/hdx-oss-v2/tests/clickhouse-deployment_test.yaml @@ -266,4 +266,76 @@ tests: - documentIndex: 0 equal: path: spec.template.spec.containers[0].readinessProbe.httpGet.port - value: 8124 \ No newline at end of file + value: 8124 + + - it: should add keep annotation to PVCs when global.keepPVC is true + set: + clickhouse: + enabled: true + persistence: + enabled: true + dataSize: 10Gi + logSize: 5Gi + global: + keepPVC: true + asserts: + - documentIndex: 4 + isKind: + of: PersistentVolumeClaim + - documentIndex: 4 + equal: + path: metadata.annotations["helm.sh/resource-policy"] + value: keep + - documentIndex: 5 + isKind: + of: PersistentVolumeClaim + - documentIndex: 5 + equal: + path: metadata.annotations["helm.sh/resource-policy"] + value: keep + + - it: should not add keep annotation to PVCs when global.keepPVC is false + set: + clickhouse: + enabled: true + persistence: + enabled: true + dataSize: 10Gi + logSize: 5Gi + global: + keepPVC: false + asserts: + - documentIndex: 4 + isKind: + of: PersistentVolumeClaim + - documentIndex: 4 + isNull: + path: metadata.annotations + - documentIndex: 5 + isKind: + of: PersistentVolumeClaim + - documentIndex: 5 + isNull: + path: metadata.annotations + + - it: should not add keep annotation to PVCs when global.keepPVC is not set + set: + clickhouse: + enabled: true + persistence: + enabled: true + dataSize: 10Gi + logSize: 5Gi + asserts: + - documentIndex: 4 + isKind: + of: PersistentVolumeClaim + - documentIndex: 4 + isNull: + path: metadata.annotations + - documentIndex: 5 + isKind: + of: PersistentVolumeClaim + - documentIndex: 5 + isNull: + path: metadata.annotations \ No newline at end of file diff --git a/charts/hdx-oss-v2/tests/mongodb-deployment_test.yaml b/charts/hdx-oss-v2/tests/mongodb-deployment_test.yaml index e970eae..97b04ad 100644 --- a/charts/hdx-oss-v2/tests/mongodb-deployment_test.yaml +++ b/charts/hdx-oss-v2/tests/mongodb-deployment_test.yaml @@ -8,6 +8,8 @@ tests: image: mongo:5.0.14-focal port: 27017 enabled: true + persistence: + enabled: false asserts: - hasDocuments: count: 2 @@ -26,38 +28,57 @@ tests: - hasDocuments: count: 0 - - it: should use PVC when persistence is enabled + - it: should create PVC, deployment and service when persistence is enabled set: mongodb: enabled: true persistence: enabled: true + dataSize: 10Gi asserts: + - hasDocuments: + count: 3 - documentIndex: 0 isKind: - of: Deployment + of: PersistentVolumeClaim + - documentIndex: 0 + matchRegex: + path: metadata.name + pattern: .*-mongodb$ - documentIndex: 0 + equal: + path: spec.resources.requests.storage + value: 10Gi + - documentIndex: 1 + isKind: + of: Deployment + - documentIndex: 1 equal: path: spec.template.spec.volumes[0].name value: mongodb-data - - documentIndex: 0 + - documentIndex: 1 isNotNull: path: spec.template.spec.volumes[0].persistentVolumeClaim - - documentIndex: 0 + - documentIndex: 1 matchRegex: path: spec.template.spec.volumes[0].persistentVolumeClaim.claimName pattern: .*-mongodb$ - - documentIndex: 0 + - documentIndex: 1 isNull: path: spec.template.spec.volumes[0].emptyDir + - documentIndex: 2 + isKind: + of: Service - - it: should use emptyDir when persistence is disabled + - it: should use emptyDir when persistence is disabled and not create PVC set: mongodb: enabled: true persistence: enabled: false asserts: + - hasDocuments: + count: 2 # Only Deployment and Service, no PVC - documentIndex: 0 isKind: of: Deployment @@ -71,11 +92,16 @@ tests: - documentIndex: 0 isNull: path: spec.template.spec.volumes[0].persistentVolumeClaim + - documentIndex: 1 + isKind: + of: Service - it: should include livenessProbe with tcpSocket when enabled set: mongodb: enabled: true + persistence: + enabled: false # To ensure predictable document ordering asserts: - documentIndex: 0 isSubset: @@ -92,6 +118,8 @@ tests: set: mongodb: enabled: true + persistence: + enabled: false # To ensure predictable document ordering asserts: - documentIndex: 0 isSubset: @@ -108,6 +136,8 @@ tests: set: mongodb: enabled: true + persistence: + enabled: false # To ensure predictable document ordering livenessProbe: enabled: false asserts: @@ -119,6 +149,8 @@ tests: set: mongodb: enabled: true + persistence: + enabled: false # To ensure predictable document ordering readinessProbe: enabled: false asserts: @@ -130,6 +162,8 @@ tests: set: mongodb: enabled: true + persistence: + enabled: false # To ensure predictable document ordering livenessProbe: enabled: true initialDelaySeconds: 20 @@ -152,6 +186,8 @@ tests: set: mongodb: enabled: true + persistence: + enabled: false # To ensure predictable document ordering readinessProbe: enabled: true initialDelaySeconds: 5 @@ -169,3 +205,63 @@ tests: periodSeconds: 20 timeoutSeconds: 3 failureThreshold: 2 + + - it: should not create PVC when mongodb is disabled + set: + mongodb: + enabled: false + persistence: + enabled: true # Even with persistence enabled, no PVC should be created + asserts: + - hasDocuments: + count: 0 # No resources should be created + + - it: should include keep annotation on PVC when global.keepPVC is true + set: + mongodb: + enabled: true + persistence: + enabled: true + global: + keepPVC: true + asserts: + - documentIndex: 0 + isKind: + of: PersistentVolumeClaim + - documentIndex: 0 + equal: + path: metadata.annotations["helm.sh/resource-policy"] + value: keep + + - it: should not include keep annotation on PVC when global.keepPVC is false + set: + mongodb: + enabled: true + persistence: + enabled: true + global: + keepPVC: false + asserts: + - documentIndex: 0 + isKind: + of: PersistentVolumeClaim + - documentIndex: 0 + isNull: + path: metadata.annotations["helm.sh/resource-policy"] + + - it: should use global storageClassName when specified + set: + mongodb: + enabled: true + persistence: + enabled: true + global: + storageClassName: fast-ssd + asserts: + - documentIndex: 0 + isKind: + of: PersistentVolumeClaim + - documentIndex: 0 + equal: + path: spec.storageClassName + value: fast-ssd diff --git a/charts/hdx-oss-v2/tests/node-selector_test.yaml b/charts/hdx-oss-v2/tests/node-selector_test.yaml index 1a3c119..adc4afb 100644 --- a/charts/hdx-oss-v2/tests/node-selector_test.yaml +++ b/charts/hdx-oss-v2/tests/node-selector_test.yaml @@ -128,6 +128,8 @@ tests: - it: should apply nodeSelector and tolerations to MongoDB deployment set: mongodb: + persistence: + enabled: false # Disable PVC to have predictable document order nodeSelector: node-role: database tolerations: @@ -254,6 +256,8 @@ tests: value: clickhouse effect: NoExecute mongodb: + persistence: + enabled: false # Disable PVC to have predictable document order nodeSelector: component: database storage: standard diff --git a/charts/hdx-oss-v2/tests/persistence_test.yaml b/charts/hdx-oss-v2/tests/persistence_test.yaml index 2f06a0e..2b62a62 100644 --- a/charts/hdx-oss-v2/tests/persistence_test.yaml +++ b/charts/hdx-oss-v2/tests/persistence_test.yaml @@ -1,47 +1,64 @@ suite: Test Persistence Settings templates: - - claims/persistent-volume-claims.yaml + - mongodb-deployment.yaml tests: - it: should use correct mongodb PVC name and size set: global: storageClassName: "custom-storage-class" mongodb: + enabled: true persistence: enabled: true dataSize: 15Gi asserts: - - isKind: + - hasDocuments: + count: 3 # PVC, Deployment, Service + - documentIndex: 0 + isKind: of: PersistentVolumeClaim - - matchRegex: + - documentIndex: 0 + matchRegex: path: metadata.name pattern: .*-mongodb$ - - equal: + - documentIndex: 0 + equal: path: spec.storageClassName value: custom-storage-class - - equal: + - documentIndex: 0 + equal: path: spec.resources.requests.storage value: 15Gi - it: should not create PVCs when persistence is disabled set: mongodb: + enabled: true persistence: enabled: false asserts: - hasDocuments: - count: 0 + count: 2 # Only Deployment and Service, no PVC + - documentIndex: 0 + isKind: + of: Deployment + - documentIndex: 1 + isKind: + of: Service - it: should omit storageClassName when global.storageClass is empty string set: global: storageClassName: "" mongodb: + enabled: true persistence: enabled: true dataSize: 10Gi asserts: - - isKind: + - documentIndex: 0 + isKind: of: PersistentVolumeClaim - - isNull: + - documentIndex: 0 + isNull: path: spec.storageClassName \ No newline at end of file diff --git a/charts/hdx-oss-v2/tests/pvc_test.yaml b/charts/hdx-oss-v2/tests/pvc_test.yaml deleted file mode 100644 index 4e25e7b..0000000 --- a/charts/hdx-oss-v2/tests/pvc_test.yaml +++ /dev/null @@ -1,63 +0,0 @@ -suite: Test Persistent Volume Claims -templates: - - claims/persistent-volume-claims.yaml -tests: - - it: should render mongodb pvc correctly when enabled - set: - mongodb: - persistence: - enabled: true - dataSize: 10Gi - global: - storageClassName: standard - asserts: - - isKind: - of: PersistentVolumeClaim - - matchRegex: - path: metadata.name - pattern: -mongodb$ - - equal: - path: spec.resources.requests.storage - value: 10Gi - - equal: - path: spec.storageClassName - value: standard - - equal: - path: spec.accessModes[0] - value: ReadWriteOnce - - - it: should not render mongodb pvc when disabled - set: - mongodb: - persistence: - enabled: false - asserts: - - hasDocuments: - count: 0 - - - it: should not include storageClassName when global.storageClass is empty - set: - mongodb: - persistence: - enabled: true - dataSize: 10Gi - global: - storageClassName: "" - asserts: - - isKind: - of: PersistentVolumeClaim - - isNull: - path: spec.storageClassName - - - it: should use default storageClassName when global.storageClassName is not explicitly overridden - set: - mongodb: - persistence: - enabled: true - dataSize: 10Gi - asserts: - - isKind: - of: PersistentVolumeClaim - - equal: - path: spec.storageClassName - value: local-path \ No newline at end of file diff --git a/charts/hdx-oss-v2/values.yaml b/charts/hdx-oss-v2/values.yaml index 1c48dbf..d2e6859 100644 --- a/charts/hdx-oss-v2/values.yaml +++ b/charts/hdx-oss-v2/values.yaml @@ -2,6 +2,8 @@ global: imageRegistry: "" imagePullSecrets: [] storageClassName: "local-path" + # Keep PVCs when uninstalling helm release to preserve data + keepPVC: false hyperdx: image: