Skip to content

feat(database): skip finalizer for resources with databaseReclaimPolicy retain - #10620

Open
GellertBabel wants to merge 1 commit into
cloudnative-pg:mainfrom
GellertBabel:dev/10535
Open

GellertBabel wants to merge 1 commit into
cloudnative-pg:mainfrom
GellertBabel:dev/10535

Conversation

@GellertBabel

Copy link
Copy Markdown
Contributor

Fixes #10535

Database, Publication and Subscription resources with a retain reclaim policy no longer receive a finalizer. This prevents the resource from getting stuck with a deletionTimestamp when the operator or operand is unavailable, which would block namespace deletion.

…cy retain

Fixes cloudnative-pg#10535

Database, Publication and Subscription resources with a retain reclaim
policy no longer receive a finalizer. This prevents the resource from
getting stuck with a deletionTimestamp when the operator or operand is
unavailable, which would block namespace deletion.

Signed-off-by: Gellért Bábel <[email protected]>
@GellertBabel
GellertBabel requested a review from a team May 5, 2026 11:10
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 5, 2026
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.28 labels May 5, 2026
@github-actions

github-actions Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@armru

armru commented Jul 16, 2026

Copy link
Copy Markdown
Member

Thanks for working on this. Before getting into the implementation details, let me check my understanding of the scenario, because I have a concern with the approach — correct me if I'm getting something wrong.

If I understand it correctly, the hang described in #10535 only occurs when the operator runs in the same namespace as the cluster. In the standard topology, with the operator in its own namespace, deleting the operand namespace should not get stuck today: as soon as the Cluster is deleted, the operator itself removes the finalizers from every Database, Publication and Subscription belonging to it (notifyDeletionToOwnedResources, internal/controller/finalizers_delete.go), even when the instance pods are already gone. If that's right, the fix would only benefit the shared-namespace topology, while the behavior change applies to every deployment.

My worry is what the other deployments would lose: the deletion-time evaluation of the reclaim policy. Today the finalizer is present from the first reconciliation, so switching a resource from retain to delete and deleting it right afterwards still guarantees the drop — the instance manager re-reads the policy while processing the deletion. With this change, a resource created under retain (which is the default) carries no finalizer, so a flip to delete followed by a quick deletion could skip the drop entirely, and the database would silently survive in PostgreSQL despite an explicit delete request.

If my reading is correct, I'd rather scope the mitigation to the shared-namespace topology, or make it an explicit opt-in, than change the default semantics globally. But I may be missing a case where the current finalizer hurts outside that topology — happy to be corrected.

I'd also like the other maintainers to weigh in on this one before we move forward.

@GellertBabel

GellertBabel commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

A user should wait for observedGeneration to equal generation before deleting. Even today I wouldn't assume it's safe to delete the CR right away, a reclaim-policy change is a spec change, and it only takes effect once reconciled.

Yes, the problem is more important for the shared-namespace use case, and I'm fine limiting the code to that. That said, it can still happen in a separate-namespace setup. When multiple namespaces are deleted at the same time, or the operator simply isn't running at that moment, the finalizers never get removed and the namespace hangs.

Not adding the finalizer at all when not needed. Makes for a safer but less feature-rich operator, which is the tradeoff the users hitting this actually want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Finalizer blocks namespace deletion when operator and operand in same namespace

4 participants