Compare commits

...
Sign in to create a new pull request.

12 commits

Author SHA1 Message Date
Arsolitt
6606206896
docs(mongodb): refine uninstall behavior and add operator recovery note
Update Data lifecycle section to address review feedback:
- Reflect the release-scoped users secret naming.
- Distinguish operator-driven PVC release from actual PV/data
  deletion (depends on StorageClass reclaimPolicy).
- Document that TLS secrets (<release>-ssl, <release>-ssl-internal)
  are not reclaimed automatically.
- Add a recovery note for the case where the operator is removed
  before the CR, leaving finalizers unable to run.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 19:05:16 +03:00
Arsolitt
ff69555dbb
test(mongodb): rename finalizer assertions to reflect both finalizers
Test descriptions said 'percona.com/delete-psmdb-pvc finalizer'
while the assertions verified both delete-psmdb-pvc and
delete-psmdb-pods-in-order. Use 'Percona finalizers' to match
what the tests actually check.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 19:02:40 +03:00
Arsolitt
8e777da24c
fix(mongodb): scope users secret to release name
The operator deletes spec.secrets.users (defaulted to the global
percona-server-mongodb-users) as part of the delete-psmdb-pvc
finalizer flow. With the default value, deleting one MongoDB
release in a namespace would remove the secret shared with any
other MongoDB release there.

Override spec.secrets.users with a release-scoped name so each
release owns its own secret and uninstalls do not collide.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 19:01:25 +03:00
Arsolitt
e1b6793a8a
docs(mongodb): enumerate all secrets affected by uninstall
The previous wording listed only one operator-managed secret with
'e.g.' prefix. The Percona Operator finalizer flow actually deletes
four specific secrets (internal-<release>, internal-<release>-users,
<release>-mongodb-encryption-key, and the global default
percona-server-mongodb-users). Document each by name so operators
understand the full deletion blast radius, especially the global
default which can collide with externally-created secrets sharing
the same name.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 17:01:22 +03:00
Arsolitt
80aa1e0dc5
docs(mongodb): clarify secret cleanup on uninstall
Distinguish between operator-managed secrets reclaimed via the
finalizer flow (e.g. internal-*-users) and Helm-managed secrets
(credentials, user secrets, s3 backup creds) removed by helm
uninstall. The previous wording was ambiguous and could mislead
users about which cleanup path applies to which secret.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 17:01:22 +03:00
Arsolitt
63239c1617
fix(mongodb): add delete-psmdb-pods-in-order finalizer
PerconaServerMongoDB CR now carries the upstream-default finalizer
pair: percona.com/delete-psmdb-pods-in-order ensures primary-last
graceful shutdown before percona.com/delete-psmdb-pvc reclaims
storage. This matches deploy/cr.yaml defaults in operator v1.21.1
and prevents potential data loss on deletion under load.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 17:01:21 +03:00
Arsolitt
1a2cb25376
test(mongodb): assert delete-psmdb-pods-in-order finalizer
Upstream Percona Operator v1.21.1 ships both delete-psmdb-pvc and
delete-psmdb-pods-in-order in deploy/cr.yaml by default. The
pods-in-order finalizer ensures primary-last graceful shutdown,
preventing data loss on cluster deletion under load.

Currently fails — establishes red phase before adding the finalizer.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 17:01:21 +03:00
Arsolitt
733226ded0
test(mongodb): cover sharded mode and drop strict equal
Replace the equal assertion (which would block adding more finalizers)
with a sharded-mode test case ensuring the finalizer is rendered
regardless of replicaset/sharded configuration.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 17:01:21 +03:00
Arsolitt
b9c4c8b497
docs(mongodb): document PVC and secret cleanup on uninstall
Document that uninstalling the release reclaims PVCs and
operator-managed user secrets via the percona.com/delete-psmdb-pvc
finalizer. Pre-existing users who relied on orphaned PVCs to
recover data should take backups before uninstalling.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 17:01:20 +03:00
Arsolitt
8eb764dd40
test(mongodb): tighten finalizer assertion
Rename test description to accurately reflect what's verified
(template renders the finalizer, not runtime cleanup behavior).
Add equal assertion locking the exact finalizer list to catch
regressions where a stray finalizer is appended.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 17:01:20 +03:00
Arsolitt
53636d616a
fix(mongodb): add delete-psmdb-pvc finalizer to PSMDB CR
PerconaServerMongoDB CR now carries percona.com/delete-psmdb-pvc
finalizer. Percona Operator deletes associated PVCs automatically
when the CR is removed, eliminating storage quota leaks.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 17:01:20 +03:00
Arsolitt
5a9c1a4416
test(mongodb): assert PSMDB CR has delete-psmdb-pvc finalizer
Add helm-unittest assertion verifying that the rendered
PerconaServerMongoDB CR carries percona.com/delete-psmdb-pvc finalizer.
Currently fails — establishes red phase before adding the fix.

Signed-off-by: Arsolitt <arsolitt@gmail.com>
2026-04-28 16:34:17 +03:00
3 changed files with 104 additions and 0 deletions

View file

@ -35,6 +35,41 @@ When `external: true` is enabled:
On first install, the credentials secret will be empty until the Percona operator initializes the cluster.
Run `helm upgrade` after MongoDB is ready to populate the credentials secret with the actual password.
### Data lifecycle
When the MongoDB release is uninstalled, the operator finalizers reclaim release-scoped resources:
**Reclaimed by the `percona.com/delete-psmdb-pvc` finalizer:**
- All PVCs backing the replica set storage. Whether the underlying PersistentVolume and on-disk data are actually deleted depends on the StorageClass `reclaimPolicy` (`Delete` removes them, `Retain` leaves them for manual cleanup).
- Operator-managed secrets:
- `<release>-percona-server-mongodb-users` — operator users credentials
- `internal-<release>` — internal operator state
- `internal-<release>-users` — operator-internal users data
- `<release>-mongodb-encryption-key` — at-rest encryption key
**Reclaimed by `helm uninstall`:**
- `<release>-credentials` — connection string for application code
- `<release>-user-<username>` — per-user passwords
- `<release>-s3-creds` — backup destination credentials (if backups are configured)
**Not reclaimed automatically:**
- TLS secrets `<release>-ssl` and `<release>-ssl-internal` (issued by cert-manager) remain in the namespace after uninstall. Delete them manually if no longer needed.
**Recovery from a stuck deletion:**
If the `psmdb-operator` is uninstalled before MongoDB CRs are deleted, the finalizers cannot run and the `PerconaServerMongoDB` CR hangs in `Terminating`. To recover, clear the finalizers manually:
```bash
kubectl --namespace <namespace> patch psmdb <release> --type merge --patch '{"metadata":{"finalizers":[]}}'
```
Note that this skips the operator-driven cleanup — PVCs and operator-managed secrets will remain orphaned and must be removed manually.
If you need to retain data, take a backup before deletion. Refer to the [Percona Operator for MongoDB documentation](https://docs.percona.com/percona-operator-for-mongodb/) for backup/restore workflows.
## Parameters
### Common parameters

View file

@ -4,9 +4,14 @@ apiVersion: psmdb.percona.com/v1
kind: PerconaServerMongoDB
metadata:
name: {{ .Release.Name }}
finalizers:
- percona.com/delete-psmdb-pods-in-order
- percona.com/delete-psmdb-pvc
spec:
crVersion: 1.21.1
clusterServiceDNSSuffix: svc.{{ $clusterDomain }}
secrets:
users: {{ .Release.Name }}-percona-server-mongodb-users
pause: false
unmanaged: false
image: percona/percona-server-mongodb:{{ include "mongodb.versionMap" $ }}

View file

@ -38,6 +38,70 @@ tests:
value: my-mongodb
documentIndex: 0
##################
# Finalizers #
##################
- it: renders Percona finalizers on PSMDB CR
release:
name: test-mongodb
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- contains:
path: metadata.finalizers
content: percona.com/delete-psmdb-pvc
documentIndex: 0
- contains:
path: metadata.finalizers
content: percona.com/delete-psmdb-pods-in-order
documentIndex: 0
- it: renders Percona finalizers in sharded mode
release:
name: test-mongodb
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
sharding: true
shardingConfig:
configServers: 3
configServerSize: 3Gi
mongos: 2
shards:
- name: rs0
replicas: 3
size: 10Gi
asserts:
- contains:
path: metadata.finalizers
content: percona.com/delete-psmdb-pvc
documentIndex: 0
- contains:
path: metadata.finalizers
content: percona.com/delete-psmdb-pods-in-order
documentIndex: 0
##################
# Secrets #
##################
- it: scopes users secret name to the release for namespace isolation
release:
name: test-mongodb
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- equal:
path: spec.secrets.users
value: test-mongodb-percona-server-mongodb-users
documentIndex: 0
##################
# CR Version #
##################