Skip to content

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

Open

Description

@GellertBabel

Is there an existing issue already for this bug?

  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.

I have read the troubleshooting guide

  • I have read the troubleshooting guide and I think this is a new bug.

I am running a supported version of CloudNativePG

  • I have read the troubleshooting guide and I think this is a new bug.

Contact Details

No response

Version

1.30.0

What version of Kubernetes are you using?

1.36

What is your Kubernetes environment?

Self-managed: kind (evaluation)

How did you install the operator?

YAML manifest

What happened?

If I change a Cluster spec and then check readiness, I can get Ready=True that was produced before my change was ever looked at. There is nothing in Cluster.status that lets me tell the difference, so kubectl wait --for=condition=Ready returns success on a stale condition.

I ran into this in CI. We upscale Clusters and then assert the resulting replica counts. The assertion races the operator and fails intermittently, more often the more Clusters we have.

The minimal case is three commands against a healthy single-instance Cluster:

$ kubectl get cluster db -o jsonpath='{.status.phase}{" gen="}{.metadata.generation}'
Cluster in healthy state gen=1

$ kubectl patch cluster db --type=merge -p '{"spec":{"instances":3}}'
cluster.postgresql.cnpg.io/db patched

$ kubectl wait --for=condition=Ready cluster/db --timeout=30s
cluster.postgresql.cnpg.io/db condition met      # returns immediately

At that point metadata.generation is 2, but conditions[Ready].lastTransitionTime still holds its pre-change value and only one instance pod exists.

Operator with an idle queue, measuring from the operator's own log timestamps between serving the update webhook and calling RegisterPhase(PhaseUpgrade):

run webhook admit rollout registered delta
1 21:04:13.110614 21:04:13.235556 124.9 ms
2 21:04:39.317498 21:04:39.436688 119.2 ms
3 21:05:05.481548 21:05:05.608910 127.4 ms

The observedGeneration that is in the schema, inherited from metav1.Condition, is never populated. SetClusterReadyCondition builds the condition with only Type, Status, Reason and Message (pkg/resources/status/transactions.go:34), so it stays 0.

What I expected

Ready to mean what the troubleshooting guide says it means, or failing that, some way to tell that the status I am reading corresponds to the spec I applied. The usual one is status.observedGeneration, so that generation == observedGeneration plus Ready=True means the change is done.

The other CRDs in the group already do this. Database, DatabaseRole, Publication and Subscription all set Status.ObservedGeneration = .Generation (api/v1/database_funcs.go:43, databaserole_funcs.go:37, publication_funcs.go:43, subscription_funcs.go:43). Cluster is the only one without it.

Cluster resource

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    bug 🐛
    triage
    on Sep 1, 2026
  2. dosubot commented on Sep 1, 2026

    @dosubot

    @GellertBabel, your root-cause analysis checks out against main. Here's a summary of what the code shows:

    SetClusterReadyCondition constructs the Ready condition with only Type, Status, Reason, and Message — it never sets ObservedGeneration [1]. Every path that updates the Ready condition goes through this helper: RegisterPhase (which is the main reconciler path), the admission-error guard in SetAdmissionError, and the plugin/promote/restart CLI paths. None of them populate ObservedGeneration either.

    ClusterStatus has no status.observedGeneration field [2], unlike DatabaseStatus and the other declarative-object CRDs which each carry an explicit ObservedGeneration int64 set via SetAsReady() / HasReconciliations().

    The observedGeneration field does exist in the CRD schema for each condition entry — it's inherited from the standard metav1.Condition type [3] — but because the Go code never writes it, meta.SetStatusCondition leaves it at 0.

    So kubectl wait --for=condition=Ready can return immediately on a stale Ready=True from a previous generation, exactly as you described. There is no field in Cluster.status that distinguishes "Ready reflects the current generation" from "Ready was set before your patch was reconciled."

    I didn't find an existing issue or in-flight PR targeting this gap. A fix mirroring the Database-style approach — either populating condition.ObservedGeneration inside SetClusterReadyCondition, and/or adding a top-level Status.ObservedGeneration field to ClusterStatus set alongside RegisterPhase — would close it and match the pattern already used elsewhere in the API group.

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about cloudnative-pg with Dosu Add Dosu to your team

  3. added a commit that references this issue on Oct 27, 2026
    363d6dd
  4. github-actions commented on Nov 22, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 60 days with no activity.

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

Metadata

Metadata

Assignees

Labels

Stalebug 🐛triage

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions