Repository navigation
Description
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
trunk (main)
What version of Kubernetes are you using?
1.37
What is your Kubernetes environment?
Self-managed: kind (evaluation)
How did you install the operator?
Other
What happened?
After a role swap between two replica clusters (demote one with .spec.replica.primary, then promote the other with the demotion token), the demoted cluster reports ConsistentSystemID=False (reason NotFound) with an empty .status.systemID.
PostgreSQL is healthy: all instances are in recovery and streaming within seconds. The condition does not recover on its own.
On main it was still False after 150 seconds, in both swap directions, until something wrote to the Cluster, for example kubectl annotate cluster <name> --overwrite test/touch=1.
I expected the operator to sample the instances again once they are back.
The instance status is read before replicaclusterswitch.Reconcile runs.
In the passes that complete the demotion the instances are still fenced or restarting, so none reports a system ID and the condition becomes False/NotFound.
The last of those passes end without a requeue. Status-only updates do not retrigger the controller, and the fence is too short to flip any Pod readiness, so nothing refreshes the condition.
operator-log-cluster-one-main.log
Cluster resource
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-one
namespace: swap-test
spec:
instances: 3
replica:
primary: cluster-one
source: cluster-two
postgresql:
pg_hba:
- hostssl replication streaming-replica 0.0.0.0/0 cert
bootstrap:
initdb:
database: appSrc
owner: userSrc
postInitApplicationSQL:
- ALTER ROLE "userSrc" REPLICATION
storage:
size: 1Gi
externalClusters:
- name: cluster-two
connectionParameters:
host: cluster-two-rw
user: streaming_replica
sslmode: verify-full
dbname: appSrc
sslKey: {name: cluster-two-replication, key: tls.key}
sslCert: {name: cluster-two-replication, key: tls.crt}
sslRootCert: {name: cluster-two-ca, key: ca.crt}
- name: cluster-one
connectionParameters:
host: cluster-one-rw
user: streaming_replica
sslmode: verify-full
dbname: appSrc
sslKey: {name: cluster-one-replication, key: tls.key}
sslCert: {name: cluster-one-replication, key: tls.crt}
sslRootCert: {name: cluster-one-ca, key: ca.crt}
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-two
namespace: swap-test
spec:
instances: 3
replica:
primary: cluster-one
source: cluster-one
postgresql:
pg_hba:
- hostssl replication streaming-replica 0.0.0.0/0 cert
bootstrap:
pg_basebackup:
database: appSrc
owner: userSrc
source: cluster-one
storage:
size: 1Gi
externalClusters:
- name: cluster-one
connectionParameters:
host: cluster-one-rw
user: streaming_replica
sslmode: verify-full
dbname: appSrc
sslKey: {name: cluster-one-replication, key: tls.key}
sslCert: {name: cluster-one-replication, key: tls.crt}
sslRootCert: {name: cluster-one-ca, key: ca.crt}
- name: cluster-two
connectionParameters:
host: cluster-two-rw
user: streaming_replica
sslmode: verify-full
dbname: appSrc
sslKey: {name: cluster-two-replication, key: tls.key}
sslCert: {name: cluster-two-replication, key: tls.crt}
sslRootCert: {name: cluster-two-ca, key: ca.crt}Relevant log output
The debug excerpt from the `main` run, showing no pass after 09:49:35 until the annotation at 09:52:26, plus the stale status.Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
dosubot commentedon Oct 2, 2026
The instance status behind
ConsistentSystemIDis sampled once per pass byGetStatusFromInstancesand consumed right away byupdateClusterStatusThatRequiresInstancesState, which sets the condition toFalse/NotFoundwhenever none of the sampled instances reported a system ID [1] [2]. That sampling happens beforereplicaclusterswitch.Reconcileruns later in the same pass [3]. When that call is the one completing the demotion, the instances were still fenced or restarting at sampling time, so the condition is written with stale data.The missing requeue also matches the code.
reconcileDemotionTokenreturns a non-zeroctrl.Resultonly on specific error paths (token generation failing or a transient auth error). OncecleanupTransitionMetadatasucceeds, it returns a bare&ctrl.Result{}[4]. ThecleanupTransitionMetadatapatch, like the demotion-token patch before it, goes throughPatchWithOptimisticLock, which diffs against the live object and skips the API call when nothing is left to change [5]. So on a pass where fencing removal and condition cleanup are the only remaining work, and a prior retry already applied that work, no Update or Patch is issued, no watch event fires, and nothing triggers the controller to resample the instances. That explains why an unrelated write (yourkubectl annotate) is needed to get a fresh pass.I didn't find an existing fix for this gap. PR #10871 fixed a similar pattern: it addressed stale primary-side status on Database, Publication and Subscription objects after a cluster demotion by re-checking status on the already-reconciled exit path and watching the Cluster for demotion. That change only touches the
internal/management/controllerresources, notConsistentSystemIDin the main cluster reconciler. PR #11260 and PR #11268 changed howInstancesReportedStateis preserved across passes, butdetectedSystemIDinupdateClusterStatusThatRequiresInstancesStatestill looks only at the freshly sampled list each pass, so they don't fix this either.A fix would likely need either a guaranteed requeue right after a demotion or promotion transition completes, or deferring the system ID condition update until after
replicaclusterswitch.Reconcilehas run in the same pass.To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
fix(replica clusters): requeue until the instances report a system ID
fix(replica clusters): report the system ID while PostgreSQL is down
fix(replica_clusters): report the system ID while PostgreSQL is down (#…
fix(replica_clusters): report the system ID while PostgreSQL is down (c…
fix(replica_clusters): report the system ID while PostgreSQL is down (#…