Skip to content

Commit ba5797f

Browse files
committed
fix(monitoring): scope VM PVC cleanup selector to this release
Address IvanHunters review on #3094: the PVC delete selector was release-agnostic (-l managed-by=vm-operator), matching the VM storage PVCs of every VMCluster/VLCluster in the namespace. If a namespace ever hosted more than one monitoring release, tearing one down would delete the other's VictoriaMetrics/VictoriaLogs storage. Scope the selector to this release via apps.cozystack.io/application.name= <release>-system, the ownership label the monitoring chart stamps on the VM CRs' managedMetadata and vm-operator propagates onto the PVCs — mirroring the merged seaweedfs hook's release scoping. deletecollection is still not needed: kubectl delete -l lists then deletes individually. Tests: assert the release-scoped selector and add a regression guard that the delete never falls back to the bare managed-by=vm-operator selector. Signed-off-by: Алексей Артамонов <[email protected]> Assisted-By: Claude <[email protected]>
1 parent ff0bb1c commit ba5797f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎packages/extra/monitoring/templates/hooks/cleanup.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ spec:
5050
- /bin/sh
5151
- -c
5252
- |
53-
kubectl delete pvc -n {{ .Release.Namespace }} -l managed-by=vm-operator --ignore-not-found --wait=false \
53+
kubectl delete pvc -n {{ .Release.Namespace }} -l managed-by=vm-operator,apps.cozystack.io/application.name={{ .Release.Name }}-system --ignore-not-found --wait=false \
5454
|| echo "WARNING: VM storage PVC cleanup failed for {{ .Release.Name }}; orphaned PVCs may remain" >&2
5555
kubectl delete secret -n {{ .Release.Namespace }} alerta-tls grafana-ingress-tls --ignore-not-found --wait=false \
5656
|| echo "WARNING: TLS secret cleanup failed for {{ .Release.Name }}; orphaned secrets may remain" >&2

‎packages/extra/monitoring/tests/cleanup_test.yaml‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,28 @@ tests:
5757
path: spec.template.spec.containers[0].securityContext.capabilities.drop
5858
content: ALL
5959

60-
- it: deletes the vm-operator storage PVCs by label without blocking teardown
60+
- it: deletes the vm-operator storage PVCs scoped to this release without blocking teardown
6161
documentSelector:
6262
path: kind
6363
value: Job
6464
asserts:
65+
# The selector must be scoped to this monitoring release, not just
66+
# managed-by=vm-operator: the bare label matches every VMCluster/VLCluster
67+
# in the namespace, so tearing one release down could delete another's
68+
# storage. apps.cozystack.io/application.name is stamped on the VM CRs'
69+
# managedMetadata and propagated by vm-operator onto the PVCs.
6570
- matchRegex:
6671
path: spec.template.spec.containers[0].command[2]
67-
pattern: kubectl delete pvc -n tenant-root -l managed-by=vm-operator --ignore-not-found --wait=false
72+
pattern: 'kubectl delete pvc -n tenant-root -l managed-by=vm-operator,apps\.cozystack\.io/application\.name=monitoring-system --ignore-not-found --wait=false'
6873
# Never widen the PVC sweep beyond the vm-operator label scope.
6974
- notMatchRegex:
7075
path: spec.template.spec.containers[0].command[2]
7176
pattern: kubectl delete pvc[^\n]*--all
77+
# Regression guard: the PVC delete must not fall back to the release-agnostic
78+
# managed-by=vm-operator selector (i.e. without the application.name scope).
79+
- notMatchRegex:
80+
path: spec.template.spec.containers[0].command[2]
81+
pattern: 'kubectl delete pvc[^\n]*-l managed-by=vm-operator --ignore-not-found'
7282

7383
- it: deletes the cert-manager TLS secrets by name without blocking teardown
7484
documentSelector:

0 commit comments

Comments
 (0)