Skip to content

fix(restore): clean up the orphan primary Lease and grant delete on leases - #11609

Merged
mnencia merged 5 commits into
mainfrom
dev/lease-adoption
Oct 22, 2026
Merged

mnencia merged 5 commits into
mainfrom
dev/lease-adoption

Conversation

@armru

@armru armru commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

A Cluster recreated over the resources it left behind, for example by a backup tool, finds its primary Lease already there without an owner. The operator adopts it by setting the ownerReference, but with the OwnerReferencesPermissionEnforcement admission plugin the API server only allows that to callers that can delete the object. The operator could not, so the restored Cluster stayed in "Unable to create required cluster objects" with cannot set an ownerRef on a resource you can't delete.

Grant delete on leases. A leftover Lease is still adopted, except when the Cluster is restored over orphan PVCs with no status: no instance runs yet, so the old holder is stale and adopting it would delay the new primary by a lease duration. There the operator deletes the Lease without owner, as it does for orphan Pods, and creates a fresh one. An e2e test deletes a Cluster with orphan propagation, recreates it, and checks that it gets ready and owns a new Lease.

Closes #11737

@armru
armru requested review from a team, NiccoloFei and litaocdl as code owners October 5, 2026 12:13
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 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 Oct 5, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

@leonardoce

Copy link
Copy Markdown
Contributor

A single combination didn't start because of a network error. Approving.

Error: utils/sternmultitailer/multitailer.go:34:2: github.com/stern/[email protected]: read "https://proxy.golang.org/github.com/stern/stern/@v/v1.34.0.zip": stream error: stream ID 3; INTERNAL_ERROR; received from peer

armru and others added 3 commits October 21, 2026 18:20
A Cluster recreated over the resources it left behind, for example by a
backup tool, finds its primary Lease already there without an owner. The
operator adopts it by setting the ownerReference, but with the
`OwnerReferencesPermissionEnforcement` admission plugin the API server
only allows that to callers that can delete the object. The operator
could not, so the restored Cluster stayed in "Unable to create required
cluster objects" with `cannot set an ownerRef on a resource you can't
delete`.

Grant `delete` on leases. The operator never deletes a Lease; the verb
is only there to satisfy that admission check. An e2e test deletes a
Cluster with orphan propagation, recreates it, and checks that it gets
ready and owns the old Lease.

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
The restore cleanup deletes a Lease without owner, while any other leftover is adopted. Say so in the doc comment and in the upgrade notes, and drop the word that needed a wordlist entry.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia
mnencia force-pushed the dev/lease-adoption branch from 9c46f7a to 4af6ab4 Compare October 21, 2026 16:37
@mnencia mnencia changed the title fix(rbac): let the operator adopt a leftover primary Lease fix(restore): clean up the orphan primary Lease and grant delete on leases Oct 21, 2026
@mnencia

mnencia commented Oct 21, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

Signed-off-by: Marco Nenciarini <[email protected]>
@gbartolini gbartolini linked an issue Oct 22, 2026 that may be closed by this pull request
@gbartolini gbartolini added this to the 1.31.0 milestone Oct 22, 2026
The operator can adopt the Lease again while the Cluster is being
deleted, after the garbage collector orphaned it, and the Lease is then
lost. The spec failed before reaching the code it covers. Build the
orphan Lease after the Cluster and its Pods are gone instead.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia

mnencia commented Oct 22, 2026

Copy link
Copy Markdown
Member

/test depth=push ft=self-healing

@gbartolini

Copy link
Copy Markdown
Contributor

Related to #11721

@github-actions

Copy link
Copy Markdown
Contributor

@mnencia

mnencia commented Oct 22, 2026

Copy link
Copy Markdown
Member

/test depth=main ft=self-healing

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 22, 2026
@mnencia
mnencia merged commit 2a54673 into main Oct 22, 2026
@mnencia
mnencia deleted the dev/lease-adoption branch October 22, 2026 08:42
cnpg-bot pushed a commit that referenced this pull request Oct 22, 2026
…eases (#11609)

A Cluster recreated over the resources it left behind, for example by a
backup tool, finds its primary Lease already there without an owner. The
operator adopts it by setting the ownerReference, but with the
`OwnerReferencesPermissionEnforcement` admission plugin the API server
only allows that to callers that can delete the object. The operator
could not, so the restored Cluster stayed in "Unable to create required
cluster objects" with `cannot set an ownerRef on a resource you can't
delete`.

Grant `delete` on leases. A leftover Lease is still adopted, except when
the Cluster is restored over orphan PVCs with no status: no instance
runs yet, so the old holder is stale and adopting it would delay the new
primary by a lease duration. There the operator deletes the Lease
without owner, as it does for orphan Pods, and creates a fresh one. An
e2e test deletes a Cluster with orphan propagation, recreates it, and
checks that it gets ready and owns a new Lease.

Related to #11721

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Leonardo Cecchi <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit 2a54673)
@gbartolini gbartolini linked an issue Oct 23, 2026 that may be closed by this pull request
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 no-issue ok to merge 👌 This PR can be merged release-1.30

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restored Cluster cannot adopt a leftover primary Lease

5 participants