Skip to content

fix(controller): set observedGeneration on the Cluster Ready condition - #11560

Open
GellertBabel wants to merge 10 commits into
cloudnative-pg:mainfrom
GellertBabel:dev/11390
Open

GellertBabel wants to merge 10 commits into
cloudnative-pg:mainfrom
GellertBabel:dev/11390

Conversation

@GellertBabel

Copy link
Copy Markdown
Contributor

kubectl wait --for=condition=Ready could succeed on a Ready=True value from a stale generation, since the condition never set observedGeneration. Populate it in SetClusterReadyCondition and SetAdmissionError.

Closes #11390

@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30 labels Sep 26, 2026
@github-actions

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 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! As I see it, though, this doesn't quite fix the issue.

SetClusterReadyCondition runs inside PatchWithOptimisticLock, which re-fetches the Cluster, so cluster.Generation is the generation at patch time, not the one the reconciliation evaluated. We re-fetch the Cluster several times during a reconciliation, and the generation can go up in the meantime. In that case we'd mark Ready=True for a generation that hasn't been reconciled yet, and whose reconciliation could still fail.

@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

@armru

armru commented Oct 20, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

GellertBabel and others added 5 commits October 27, 2026 11:03
kubectl wait --for=condition=Ready could succeed on a Ready=True value from a stale generation, since the condition never set observedGeneration. Populate it in SetClusterReadyCondition and SetAdmissionError.

Closes cloudnative-pg#11390

Signed-off-by: Gellért Bábel <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
A status write in the middle of the reconciliation loop reloads the Cluster, so the Ready condition could report a generation the loop never reconciled. Record the generation at the start of Reconcile and use it as observedGeneration.

The instance manager no longer sets the Ready condition after an in-place primary restart: it only moves the phase back to Healthy and leaves Ready to the operator, which knows the generation it has reconciled.

Signed-off-by: Gellért Bábel <[email protected]>
…p evaluated

A status patch can decode a newer spec into the Cluster mid-loop, so the
loop may reach a healthy phase partly thanks to a generation other than the
reconciled one it stamps. RegisterPhase now leaves the Ready condition
untouched when it registers a healthy phase for a Cluster whose generation
no longer matches the reconciled one: the next loop, triggered by the
generation change, marks it as ready.

The instance manager sets the Ready condition again after an in-place
primary restart, as it did before.

Signed-off-by: Armando Ruocco <[email protected]>
While the primary restarts in-place the operator pauses its reconciliation,
so a spec change made in the meantime is not applied. The instance manager
then marked the Cluster ready for the generation it read, letting a wait on
the Ready condition return before the operator reconciled that generation.

The instance manager and the restart command of the kubectl plugin now keep
the generation of the current Ready condition, the last one the operator
reconciled.

Signed-off-by: Armando Ruocco <[email protected]>
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 ok to merge 👌 This PR can be merged release-1.28 release-1.30

Projects

Status: Waiting for First Review

Development

Successfully merging this pull request may close these issues.

[Bug]: Cluster reports Ready=True for a spec generation the operator has not reconciled

6 participants