Skip to content

Skip owner references on user secrets when secret deletion is disabled - #3165

Merged
FxKu merged 2 commits into
zalando:masterfrom
cybertec-postgresql:fix/skip-secret-owner-refs-when-deletion-disabled
Aug 11, 2026
Merged

Skip owner references on user secrets when secret deletion is disabled#3165
FxKu merged 2 commits into
zalando:masterfrom
cybertec-postgresql:fix/skip-secret-owner-refs-when-deletion-disabled

Conversation

@adshin21

Copy link
Copy Markdown
Contributor

Closes #3162

enable_secrets_deletion: false is supposed to keep user-credential Secrets when a postgresql CR is deleted. The operator's own Cluster.Delete() does guard deleteSecrets(), but generateSingleUserSecret attaches a controller OwnerReference to every generated Secret whenever enable_owner_references is true, and K8s garbage collection then removes the Secret independently of the operator's deletion logic. This made enable_secrets_deletion=false a no-op whenever enable_owner_references=true.

This PR makes generateSingleUserSecret skip the controller owner reference on user-credential Secrets whenever enable_secrets_deletion is false, so the two flags compose as documented.

How to reproduce / verify

With enable_owner_references: true and enable_secrets_deletion: false, delete a postgresql CR — the user-credential Secret now survives.
With the default (enable_secrets_deletion: true) the Secret still cascades-delete as before. See #3162 for the full reproduction steps.

Notes

  • All other operator-managed resources (StatefulSets, Services, PDBs, logical-backup CronJob) still receive the controller owner reference and continue to cascade-delete as before.
  • Cross-namespace Secrets remain excluded from owner references, as before.
  • A unit test (TestGenerateSingleUserSecret_OwnerReferences) covers all four flag combinations plus the cross-namespace cases.

serdardalgic and others added 2 commits August 11, 2026 14:51
Kubernetes garbage-collects owner-referenced secrets as soon as the
owning Postgresql resource is deleted, regardless of the operator's
own EnableSecretsDeletion check in Delete() (which only guards the
operator's explicit deleteSecrets() call, not GC). This made
enable_secrets_deletion=false ineffective whenever
enable_owner_references was also enabled, since GC removed the
credential secrets anyway.

Now the generated secrets are not removed when
enable_owner_references: true, enable_secrets_deletion: false.
- refresh inline comment in generateSingleUserSecret
- extend enable_owner_references / enable_secrets_deletion docs in
  operator_parameters.md to describe the interaction
- clarify in operator_parameters.md that the protection takes effect
  on the cluster's next sync after the setting is applied
- add third exception in administrator.md "Owner References and Finalizers"
- add TestGenerateSingleUserSecret_OwnerReferences covering all four
  flag combinations plus the cross-namespace cases
@FxKu FxKu added this to the 2.0.2 milestone Aug 11, 2026
@FxKu FxKu added the bugfix label Aug 11, 2026
@FxKu FxKu moved this to Good state for merge in Postgres Operator Aug 11, 2026
@FxKu

FxKu commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

👍

@FxKu
FxKu merged commit bbc3eab into zalando:master Aug 11, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Good state for merge to Done in Postgres Operator Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Secrets still deleted when enable_secrets_deletion: false + enable_owner_references: true

4 participants