mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
Re-review on #3094 (IvanHunters, MAJOR): the volumeClaimTemplate label lands on PVCs only at creation — the StatefulSet controller never re-labels existing PVCs and vm-operator's PVC reconcile is resize-only. So on an already-deployed cluster (exactly the #3091 population) the pre-upgrade VM/VL storage PVCs stay unlabeled and the cleanup hook's selector misses them. Add migration 49 (mirrors the ClickHouse-keeper backfill in migration 48 for the sibling #3072). It relabels the pre-existing vmstorage/vmselect/vlstorage PVCs of every cozystack-managed VMCluster/VLCluster with apps.cozystack.io/application.name read from the CR's own spec.managedMetadata, so only monitoring's clusters are touched (a user's own VMCluster carries no such label) and the value always matches what the cleanup hook selects. Best-effort like #48: a skipped relabel is no worse than the pre-existing leak, so transient apiserver errors never abort the platform upgrade. Bump platform targetVersion 49 -> 50. Also correct the misleading comments (IvanHunters MINOR): spec.managedMetadata is never applied to PVCs by vm-operator at any current version, so the claim-template label is the only mechanism — do not imply a v0.71.0 crossover. Signed-off-by: Алексей Артамонов <aleksei.artamonov@aenix.io> Assisted-By: Claude <noreply@anthropic.com>
169 lines
6.0 KiB
YAML
169 lines
6.0 KiB
YAML
suite: monitoring post-delete cleanup hook removes orphaned VM PVCs and TLS secrets
|
|
|
|
release:
|
|
name: monitoring
|
|
namespace: tenant-root
|
|
|
|
templates:
|
|
- templates/hooks/cleanup.yaml
|
|
|
|
tests:
|
|
- it: renders the cleanup Job as a post-delete hook with the hardened pod spec
|
|
documentSelector:
|
|
path: kind
|
|
value: Job
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: monitoring-cleanup
|
|
- equal:
|
|
path: metadata.annotations["helm.sh/hook"]
|
|
value: post-delete
|
|
- equal:
|
|
path: metadata.annotations["helm.sh/hook-weight"]
|
|
value: "10"
|
|
# The Job keeps only before-hook-creation so a Failed cleanup survives for
|
|
# post-mortem; hook-succeeded stays on the SA/Role/RoleBinding (see #3072).
|
|
- equal:
|
|
path: metadata.annotations["helm.sh/hook-delete-policy"]
|
|
value: before-hook-creation
|
|
# Backstop so a stuck delete can never stall the HelmRelease teardown.
|
|
- equal:
|
|
path: spec.activeDeadlineSeconds
|
|
value: 120
|
|
# Best-effort, never retry.
|
|
- equal:
|
|
path: spec.backoffLimit
|
|
value: 0
|
|
- equal:
|
|
path: spec.template.metadata.labels["policy.cozystack.io/allow-to-apiserver"]
|
|
value: "true"
|
|
- equal:
|
|
path: spec.template.spec.serviceAccountName
|
|
value: monitoring-cleanup
|
|
- equal:
|
|
path: spec.template.spec.restartPolicy
|
|
value: Never
|
|
- equal:
|
|
path: spec.template.spec.securityContext.runAsNonRoot
|
|
value: true
|
|
- equal:
|
|
path: spec.template.spec.securityContext.runAsUser
|
|
value: 65534
|
|
- equal:
|
|
path: spec.template.spec.containers[0].name
|
|
value: cleanup
|
|
- equal:
|
|
path: spec.template.spec.containers[0].image
|
|
value: docker.io/clastix/kubectl:v1.32
|
|
- equal:
|
|
path: spec.template.spec.containers[0].securityContext.readOnlyRootFilesystem
|
|
value: true
|
|
- contains:
|
|
path: spec.template.spec.containers[0].securityContext.capabilities.drop
|
|
content: ALL
|
|
|
|
- it: deletes the vm-operator storage PVCs scoped to this release without blocking teardown
|
|
documentSelector:
|
|
path: kind
|
|
value: Job
|
|
asserts:
|
|
# The selector is scoped to this release by apps.cozystack.io/application.name
|
|
# alone. That label is stamped on the VM/VL CRs'
|
|
# storage.volumeClaimTemplate.metadata.labels (packages/system/monitoring) and
|
|
# is copied onto the PVCs by vm-operator (IntoSTSVolume); spec.managedMetadata
|
|
# is not applied to PVCs, so the claim template is the only path that works.
|
|
# managed-by=vm-operator is deliberately NOT in the selector: on v0.68.4 it
|
|
# lives only on the StatefulSet selector/pod labels, so relying on it is
|
|
# fragile; application.name=<release>-system is already release-scoped and
|
|
# provably present on the PVC, and the CNPG db PVCs (grafana-db/alerta-db)
|
|
# do not carry it, so they stay untouched.
|
|
- matchRegex:
|
|
path: spec.template.spec.containers[0].command[2]
|
|
pattern: 'kubectl delete pvc -n tenant-root -l apps\.cozystack\.io/application\.name=monitoring-system --ignore-not-found --wait=false'
|
|
# Never widen the PVC sweep beyond the release-scoped label.
|
|
- notMatchRegex:
|
|
path: spec.template.spec.containers[0].command[2]
|
|
pattern: kubectl delete pvc[^\n]*--all
|
|
# Regression guard: never re-introduce managed-by=vm-operator into the PVC
|
|
# selector — on the shipped v0.68.4 it is not stamped on the storage PVCs,
|
|
# so an AND with it silently matches nothing (see #3094 review).
|
|
- notMatchRegex:
|
|
path: spec.template.spec.containers[0].command[2]
|
|
pattern: 'kubectl delete pvc[^\n]*managed-by=vm-operator'
|
|
|
|
- it: deletes the cert-manager TLS secrets by name without blocking teardown
|
|
documentSelector:
|
|
path: kind
|
|
value: Job
|
|
asserts:
|
|
- matchRegex:
|
|
path: spec.template.spec.containers[0].command[2]
|
|
pattern: kubectl delete secret -n tenant-root alerta-tls grafana-ingress-tls --ignore-not-found --wait=false
|
|
# The secret deletion must stay name-scoped — never a label or --all sweep.
|
|
- notMatchRegex:
|
|
path: spec.template.spec.containers[0].command[2]
|
|
pattern: kubectl delete secret[^\n]*(-l |--all)
|
|
|
|
- it: creates the cleanup ServiceAccount as a post-delete hook
|
|
documentSelector:
|
|
path: kind
|
|
value: ServiceAccount
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: monitoring-cleanup
|
|
- equal:
|
|
path: metadata.annotations["helm.sh/hook"]
|
|
value: post-delete
|
|
- equal:
|
|
path: metadata.annotations["helm.sh/hook-weight"]
|
|
value: "0"
|
|
|
|
- it: grants RBAC to delete PVCs by label and the two named TLS secrets
|
|
documentSelector:
|
|
path: kind
|
|
value: Role
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: monitoring-cleanup
|
|
- equal:
|
|
path: metadata.annotations["helm.sh/hook-weight"]
|
|
value: "5"
|
|
- equal:
|
|
path: rules[0].resources[0]
|
|
value: persistentvolumeclaims
|
|
- contains:
|
|
path: rules[0].verbs
|
|
content: delete
|
|
- equal:
|
|
path: rules[1].resources[0]
|
|
value: secrets
|
|
- equal:
|
|
path: rules[1].resourceNames
|
|
value:
|
|
- alerta-tls
|
|
- grafana-ingress-tls
|
|
- contains:
|
|
path: rules[1].verbs
|
|
content: delete
|
|
|
|
- it: binds the cleanup Role to the cleanup ServiceAccount
|
|
documentSelector:
|
|
path: kind
|
|
value: RoleBinding
|
|
asserts:
|
|
- equal:
|
|
path: metadata.name
|
|
value: monitoring-cleanup
|
|
- equal:
|
|
path: roleRef.name
|
|
value: monitoring-cleanup
|
|
- equal:
|
|
path: subjects[0].name
|
|
value: monitoring-cleanup
|
|
- equal:
|
|
path: subjects[0].namespace
|
|
value: tenant-root
|