Repository navigation
fix(controller): let a cluster recover while an instance is fenced - #11274
Merged
Merged
Conversation
Contributor
|
❗ By default, the pull request is configured to backport to all release branches.
|
armru
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
2 times, most recently
from
July 30, 2026 08:18
6c1d7dc to
baa098f
Compare
Member
Author
|
/test |
Contributor
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/30527774801 |
mnencia
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
from
July 31, 2026 14:56
baa098f to
57a0b40
Compare
GabriFedi97
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
from
August 3, 2026 08:10
57a0b40 to
8c27e39
Compare
GabriFedi97
reviewed
Aug 3, 2026
GabriFedi97
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
from
August 6, 2026 09:22
99b43bf to
f28bc78
Compare
GabriFedi97
approved these changes
Aug 6, 2026
litaocdl
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
3 times, most recently
from
August 11, 2026 09:49
f28bc78 to
130a25f
Compare
litaocdl
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
from
August 13, 2026 03:07
7df1164 to
02e19e6
Compare
litaocdl
approved these changes
Aug 13, 2026
Collaborator
|
/test ft=plugin |
Contributor
|
@litaocdl, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/31663044651 |
leonardoce
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
2 times, most recently
from
September 15, 2026 12:01
3021803 to
d24f40a
Compare
leonardoce
approved these changes
Sep 15, 2026
leonardoce
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
from
September 15, 2026 12:02
d24f40a to
440bdb4
Compare
Contributor
|
/test |
Contributor
|
@leonardoce, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/34968801663 |
A fenced instance permanently reports a healthy /pg/status endpoint while PostgreSQL is shut down, so its pod never becomes Ready. The first branch of evaluatePodReadinessGuards was meant to absorb the short window right after un-fencing an instance, where the kubelet has not yet refreshed the readiness probe, but it could not tell that window apart from a fenced instance's permanent not-Ready state, so it kept requeueing forever whenever a fenced instance sorted to the front of the status list. The natural assumption is that the first element of that list is always the primary, but that only holds while the primary is actually present and reachable. PostgresqlStatusList.Less (pkg/postgres/status.go lines 282 to 303) pushes any entry whose status call returned an error to the tail before it even looks at which entry is the primary, so if the primary's pod is gone it is simply absent from the list, and if the primary is present but its /pg/status call cannot be reached it gets pushed to the tail ahead of that check. A fenced replica still answers its instance manager, so in both cases it ends up as the first element instead of the primary. Those are exactly the two situations where the cluster needs to elect a new primary, which is exactly what this guard was blocking. Because this guard runs ahead of both the target-primary election and the rest of the reconciliation, the reconcile loop never reached the election step for as long as that instance stayed fenced, well beyond just the un-fencing window the guard was built for. Skip the branch when the instance is currently fenced, using the existing Cluster.IsInstanceFenced helper (which also covers the fence-all-instances wildcard). Signed-off-by: Armando Ruocco <[email protected]>
A fenced instance has PostgreSQL shut down, so it cannot act on a promotion request. Nothing in the target primary election path excluded fenced instances from becoming a candidate, so with a fenced replica and no healthy primary the operator would elect the fenced instance, then keep retrying a promotion that can never complete: the current primary is never replaced and deleted pods are never recreated, while the reconcile loop spins logging the same failover attempt over and over. Both election paths (the regular election in reconcileTargetPrimaryForNonReplicaCluster and the designated primary election in reconcileTargetPrimaryForReplicaCluster) now skip fenced instances when picking a candidate, using the same fencing check already used elsewhere (including the fence-all wildcard). When no promotable candidate is left, the operator elects nobody and leaves the target primary alone instead of setting it to an instance that will never come up, which is what breaks the hot loop. The case of a fenced current primary is already handled by handleSwitchover, which declines the switchover before reaching this code, so it is left untouched here. Signed-off-by: Armando Ruocco <[email protected]>
The reattachment gate in ensureInstancesAreCreated defers recreating a missing Pod until InstancesReportingStatus() matches cluster.Status.ReadyInstances. The first counter treats a fenced instance as reporting (its instance manager keeps answering MightBeUnavailable while PostgreSQL is shut down); the second is pure kubelet readiness and knows nothing about fencing. With any instance fenced the two counters can never agree, so the gate deferred forever and a deleted pod elsewhere in the cluster was never recreated for as long as the fencing lasted. Add InstancesReportingStatusExcept, a predicate-taking sibling of InstancesReportingStatus that skips instances by name, and have the gate exclude fenced instances from the comparison using the same Cluster.IsInstanceFenced check the other two fencing fixes rely on. InstancesReportingStatus keeps its existing behaviour by delegating to the new method with a nil predicate, since its other three call sites compare against Spec.Instances or Status.Instances and still converge with a fenced instance counted. Signed-off-by: Armando Ruocco <[email protected]>
The readiness guard read Items[0] while the election walked past a fenced entry to the first instance that could actually be promoted, so the two could end up talking about different instances. With a fenced instance at the head of the list the guard found nothing to wait for and let the reconciliation through, and the instance really being promoted, the next one along, had its readiness never looked at: exactly the promotion of a pod the kubelet has not marked Ready that the guard exists to prevent. Ask firstPromotableCandidate in both places. Skipping a fenced instance then falls out of picking a promotable one, so the guard no longer needs a fencing test of its own. An instance fenced a moment ago still reports the LSNs it had while running, and on an idle cluster every replica shares the same LSN, so the pod name breaks the tie: a fenced instance can lead a list whose next entry is an equally advanced healthy one. That is why the candidate is found by walking the list rather than by skipping a fenced first element, and the sorting rules this rests on are now pinned by their own tests, which the existing ones never covered since they all build the list pre-sorted by hand. The candidate is no longer named after the most advanced instance either, because it is not: reading it that way invites a future change that promotes a less advanced instance and loses WAL. The remaining tests cover the steady-state shape of a fenced instance, LSNs never filled in and the connection error masked, instead of describing it as a healthy instance that merely carries a fencing annotation. Signed-off-by: Armando Ruocco <[email protected]>
…s Ready The designated primary election of a replica cluster never looked at the reported status: it elected the first entry of the sorted list even when the operator could not read it, and even when the kubelet had not marked the pod as Ready. Promoting an instance Kubernetes refuses to route traffic to leaves the read-write service without a primary. In the non-replica path readiness is redundant with evaluatePodReadinessGuards, which requeues on the same candidate before the election is reached. It is stated here anyway, so the rule lives where the election is made. That is also why the failover delay test moves its candidate to Ready: the guard intercepts that shape, so the fixture no longer described a reachable input. firstPromotableCandidate becomes firstNonFencedInstance, since fencing is all it filters on, and the designated primary election gets the tests it never had. Assisted-by: Claude Opus 5 Signed-off-by: Gabriele Fedi <[email protected]>
Signed-off-by: Tao Li <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
…ection Push fencing into PostgresqlStatusList's sort order via a new IsFenced field on PostgresqlStatus, instead of a separate candidate-scanning function threaded through every call site. The election and readiness guard go back to reading Items[0] directly, with a fenced check where needed. Also trims duplicate/redundant test coverage the fencing fix had added. Signed-off-by: Leonardo Cecchi <[email protected]>
leonardoce
force-pushed
the
fix/readiness-guard-ignores-fenced-instances
branch
from
September 15, 2026 15:19
440bdb4 to
ddc0c90
Compare
leonardoce
added a commit
that referenced
this pull request
Sep 15, 2026
While any instance is fenced, the cluster currently loses its ability to recover from an unrelated failure: it won't elect a new primary and won't recreate a deleted pod, because a fenced instance still answers its status endpoint as healthy even though its pod is permanently not Ready. This commit makes the readiness guard, the primary-election logic, and the pod-reattachment gate all recognize and skip fenced instances, so the cluster keeps failing over and recreating pods normally instead of stalling until someone manually un-fences. Assisted-by: Claude Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Gabriele Fedi <[email protected]> Signed-off-by: Tao Li <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Gabriele Fedi <[email protected]> Co-authored-by: Tao Li <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit ebd4b56)
leonardoce
added a commit
that referenced
this pull request
Sep 15, 2026
While any instance is fenced, the cluster currently loses its ability to recover from an unrelated failure: it won't elect a new primary and won't recreate a deleted pod, because a fenced instance still answers its status endpoint as healthy even though its pod is permanently not Ready. This commit makes the readiness guard, the primary-election logic, and the pod-reattachment gate all recognize and skip fenced instances, so the cluster keeps failing over and recreating pods normally instead of stalling until someone manually un-fences. Assisted-by: Claude Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Gabriele Fedi <[email protected]> Signed-off-by: Tao Li <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Gabriele Fedi <[email protected]> Co-authored-by: Tao Li <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit ebd4b56) (cherry picked from commit 36bec80)
leonardoce
added a commit
that referenced
this pull request
Sep 15, 2026
While any instance is fenced, the cluster currently loses its ability to recover from an unrelated failure: it won't elect a new primary and won't recreate a deleted pod, because a fenced instance still answers its status endpoint as healthy even though its pod is permanently not Ready. This commit makes the readiness guard, the primary-election logic, and the pod-reattachment gate all recognize and skip fenced instances, so the cluster keeps failing over and recreating pods normally instead of stalling until someone manually un-fences. Assisted-by: Claude Signed-off-by: Armando Ruocco <[email protected]> Signed-off-by: Gabriele Fedi <[email protected]> Signed-off-by: Tao Li <[email protected]> Signed-off-by: Leonardo Cecchi <[email protected]> Co-authored-by: Gabriele Fedi <[email protected]> Co-authored-by: Tao Li <[email protected]> Co-authored-by: Leonardo Cecchi <[email protected]> (cherry picked from commit ebd4b56) (cherry picked from commit 36bec80) (cherry picked from commit dc15c9b)
renovate Bot
added a commit
to sdwilsh/ansible-playbooks
that referenced
this pull request
Sep 24, 2026
##### [\`v1.30.1\`](https://github.com/cloudnative-pg/cloudnative-pg/releases/tag/v1.30.1) **Release date:** Sep 23, 2026 ##### Enhancements - Added `restoreAdditionalCommandArgs` to `.barmanObjectStore.data` for in-tree Barman Cloud recoveries, so custom flags are forwarded to `barman-cloud-restore` during recovery. ([#11278](cloudnative-pg/cloudnative-pg#11278)) <!-- 1.29 1.28 --> - Plugin authors no longer need to re-derive whether an empty WAL archive should be treated as an error: the operator now computes the `check_empty_wal_archive` decision once and passes it to CNPG-I plugins on both WAL archiving and restore hooks. ([#11216](cloudnative-pg/cloudnative-pg#11216)) <!-- 1.29 1.28 --> - Allowed setting the `ssl_ecdh_curve` PostgreSQL parameter in `.spec.postgresql.parameters`. It was previously rejected by the validating webhook even though the operator does not manage it. Contributed by [@Jamstah](https://github.com/Jamstah). ([#11308](cloudnative-pg/cloudnative-pg#11308)) <!-- 1.29 1.28 --> - Added support for setting `auth_user` in `spec.pgbouncer.parameters` to override the user PgBouncer uses for its `auth_query` connection, instead of always deriving it from the `authQuerySecret`. Useful with a custom `authQuerySecret` where the role to authenticate as differs from the one implied by the Secret. Contributed by [@jonasbadstuebner](https://github.com/jonasbadstuebner). ([#10899](cloudnative-pg/cloudnative-pg#10899)) <!-- 1.29 1.28 --> - Fixed PgBouncer metrics silently reporting zero when PgBouncer adds or reorders columns: `SHOW STATS` and `SHOW POOLS` results are now matched by column name instead of by position. Contributed by [@AdzerKI](https://github.com/AdzerKI) (`SHOW STATS`). ([#11366](cloudnative-pg/cloudnative-pg#11366), [#11464](cloudnative-pg/cloudnative-pg#11464)) <!-- 1.29 1.28 --> - `cnpg` plugin: - Added a `--dry-run` option to the `backup` command that prints the `Backup` resource that would be created, without creating it. ([#11233](cloudnative-pg/cloudnative-pg#11233)) <!-- 1.29 1.28 --> ##### Security and Supply Chain - Fixed a webhook validation bypass where an absolute extension path with an embedded `..` traversal (e.g. `/a/../../../../etc`) was accepted because only the raw path was checked; such paths still escaped the extension's mount point once resolved at runtime. Affected entries are now resolved and rejected/skipped consistently across admission, the major-upgrade job, and already-persisted Cluster specs. Contributed by [@Anand-240](https://github.com/Anand-240). ([#11210](cloudnative-pg/cloudnative-pg#11210)) <!-- 1.29 1.28 --> - Updated `google.golang.org/grpc` to v1.83.1, fixing [CVE-2026-84304](https://nvd.nist.gov/vuln/detail/CVE-2026-84304) / GHSA-vp52-pcj8-j9qc (gRPC-Go heap memory exhaustion via HTTP/2 DATA frame fragmentation). ([#11394](cloudnative-pg/cloudnative-pg#11394)) <!-- 1.29 1.28 --> ##### Changes - Updated the default PostgreSQL operand image to 18.6-system-trixie. ([#11257](cloudnative-pg/cloudnative-pg#11257)) <!-- 1.29 1.28 --> - Moved the operator's own base image from Debian 12 (bookworm) to Debian 13 (trixie), now that Debian 12 has moved to LTS-only maintenance. ([#11193](cloudnative-pg/cloudnative-pg#11193)) <!-- 1.29 1.28 --> ##### Fixes - Demoted an unreachable old primary immediately during failover, instead of waiting on checkpoint and fast-shutdown attempts that could never complete. Previously, an old primary whose PostgreSQL had become unresponsive was never shut down, so it could never rejoin the cluster as a replica of the new primary. The shutdown is now requested without blocking the reconciler, though demotion can still take up to a minute or more if PostgreSQL keeps ignoring shutdown signals. ([#11347](cloudnative-pg/cloudnative-pg#11347)) <!-- 1.29 1.28 --> - Fixed failover and Pod recreation getting stuck while any instance in the cluster was fenced. A fenced instance kept reporting itself as healthy on its status endpoint even though its Pod was permanently not Ready, which blocked the readiness guard, the primary-election logic, and the Pod-reattachment gate from reacting to an unrelated failure elsewhere in the cluster, leaving it stalled until someone manually removed the fencing. All three now recognize and skip fenced instances. ([#11274](cloudnative-pg/cloudnative-pg#11274)) <!-- 1.29 1.28 --> - Fixed a failover that could stall forever or get silently reverted. While a failover was pending, the reconciler could skip checking whether it was ready to complete, or mistake the pending state for a missing Pod and reset the target primary back to the unhealthy one. It now keeps progressing a pending failover and completes it once the WAL receivers are down, rechecking quorum safety right before promoting in case it changed while waiting. ([#11336](cloudnative-pg/cloudnative-pg#11336)) <!-- 1.29 1.28 --> - Fixed the designated-primary sort in `PostgresqlStatusList` so a tie on LSN no longer sorts it out of order. If the designated primary's Pod later disappeared from the status list, this could have led the operator to promote the wrong standby. ([#11494](cloudnative-pg/cloudnative-pg#11494)) <!-- 1.29 1.28 --> - Gated PostgreSQL startup on the instance manager actually holding the primary `Lease`, closing a window where a restarting or rescheduled primary could start accepting writes before acquiring the lease. Lease acquisition now happens during instance initialization, strictly before PostgreSQL is allowed to start, instead of only later in the reconciliation loop once the instance was already reported ready. ([#11356](cloudnative-pg/cloudnative-pg#11356)) - Bounded the primary lease take-over `Get` call to the lease's `RenewDeadline`, so a call against an unreachable API server now fails fast and retries instead of blocking indefinitely. Left unbounded, the same stalled call could also delay a primary's own lease renewal after a transient API server blip, risking an unwanted takeover by another instance once the lease appeared to expire. ([#11350](cloudnative-pg/cloudnative-pg#11350)) - Stopped abandoning a fast shutdown after 60 seconds. The request carried no explicit timeout, so `pg_ctl` fell back to its own implicit 60-second limit, and the instance manager, being PID 1 in the container, took PostgreSQL down mid-shutdown regardless of a larger configured `stopDelay`. The fast phase now waits for the full `stopDelay` instead. ([#11263](cloudnative-pg/cloudnative-pg#11263)) <!-- 1.29 1.28 --> - Waited for certificate status before refreshing secrets during bootstrap. ([#11450](cloudnative-pg/cloudnative-pg#11450)) <!-- 1.29 1.28 --> - Fixed in-tree Barman Cloud recovery ignoring `wal.maxParallel` and `wal.restoreAdditionalCommandArgs`, fetching WAL one segment at a time instead of using the configured parallelism. ([#11105](cloudnative-pg/cloudnative-pg#11105)) <!-- 1.29 1.28 --> - Honored the `unrecoverable` annotation on pending and terminating instances. ([#11241](cloudnative-pg/cloudnative-pg#11241)) <!-- 1.29 1.28 --> - Honored `Backup.spec.online` when finalizing VolumeSnapshot-based backups, so a cold backup is no longer reported as online in status. ([#11276](cloudnative-pg/cloudnative-pg#11276)) <!-- 1.29 1.28 --> - Set `--no-data-checksums` explicitly when `.spec.postgresql.dataChecksums` is `false` on PostgreSQL 18+, which now enables checksums by default in `initdb`. Contributed by [@evan314159](https://github.com/evan314159). ([#11488](cloudnative-pg/cloudnative-pg#11488)) <!-- 1.29 1.28 --> - Stopped discarding `.spec.inheritedMetadata` labels on PVC reconciliation; they were applied before, and then overwritten by, the operator's own labels. Contributed by [@GellertBabel](https://github.com/GellertBabel). ([#11499](cloudnative-pg/cloudnative-pg#11499)) <!-- 1.29 1.28 --> - Stopped `Pooler` and `DatabaseRole` from recreating their owned resources after being marked for deletion, which could block an external finalizer (e.g. ArgoCD foreground deletion) waiting for those resources to disappear. Contributed by [@mjlshen](https://github.com/mjlshen). ([#11359](cloudnative-pg/cloudnative-pg#11359)) <!-- 1.29 1.28 --> - Handled a `NULL` `stats_reset` value in the `pg_stat_wal` metric, which could occasionally break Prometheus scraping on PostgreSQL 18 clusters. Contributed by [@HoniSanders](https://github.com/HoniSanders). ([#11207](cloudnative-pg/cloudnative-pg#11207)) <!-- 1.29 1.28 --> - Recovered log streaming when a stale non-FIFO file blocked the log pipe. ([#11246](cloudnative-pg/cloudnative-pg#11246)) <!-- 1.29 1.28 --> - Stopped sampling logs of the Pods' processes, so no log lines are silently dropped. ([#11131](cloudnative-pg/cloudnative-pg#11131)) <!-- 1.29 1.28 --> - Stopped caching Helm release Secrets in the operator, which could spike memory usage and crashloop the operator on clusters with large Helm releases installed alongside it. ([#11211](cloudnative-pg/cloudnative-pg#11211)) <!-- 1.29 1.28 --> - Re-ran owned-resource finalizer cleanup after an operator restart, so a namespace deleted while the operator was down doesn't hang in `Terminating` forever. ([#11215](cloudnative-pg/cloudnative-pg#11215)) <!-- 1.29 1.28 --> - Fixed rejoining replicas taking a long time to complete `pg_rewind` when WAL prefetching (`wal.maxParallel > 1`) was enabled. ([#11204](cloudnative-pg/cloudnative-pg#11204)) <!-- 1.29 1.28 --> - Treated a PostgreSQL instance rejecting connections as started up in probes. ([#11152](cloudnative-pg/cloudnative-pg#11152)) <!-- 1.29 1.28 --> - Stopped issuing a redundant PATCH on every reconciliation when a cluster's `pvcTemplate` set `volumeAttributesClass`. Contributed by [@andrew-farries](https://github.com/andrew-farries). ([#11196](cloudnative-pg/cloudnative-pg#11196)) <!-- 1.29 1.28 --> - Stopped halting replication slot reconciliation at the first failing slot. ([#11119](cloudnative-pg/cloudnative-pg#11119)) <!-- 1.29 1.28 --> - During rollouts, compared the running configuration hash, rather than the on-disk one, avoiding unnecessary switchovers. ([#11130](cloudnative-pg/cloudnative-pg#11130)) <!-- 1.29 1.28 --> - Retried `VolumeSnapshot` errors until the deadline, instead of giving up early. ([#11132](cloudnative-pg/cloudnative-pg#11132)) <!-- 1.29 1.28 --> - Symlinked `pg_wal` to the WAL volume during plugin-based recovery, instead of replaying WAL onto the data volume, which could exhaust it on a large point-in-time recovery. ([#11127](cloudnative-pg/cloudnative-pg#11127)) <!-- 1.29 1.28 --> - Corrected grammar in `PhaseUpgradeDelayed` status messages. Contributed by [@Utkarsh-sharma47](https://github.com/Utkarsh-sharma47). ([#11065](cloudnative-pg/cloudnative-pg#11065)) <!-- 1.29 1.28 --> - CloudNativePG Interface (CNPG-I): - Reported the Postgres capabilities of a plugin correctly. ([#11447](cloudnative-pg/cloudnative-pg#11447)) <!-- 1.29 1.28 --> - Prevented the plugin status field from flapping on Cluster reconciliation. Contributed by [@sharifmshaker](https://github.com/sharifmshaker). ([#11386](cloudnative-pg/cloudnative-pg#11386)) <!-- 1.29 1.28 --> - Replaced a finalizer with in-memory cleanup on Service deletion. This avoids namespaces hanging in `Terminating` state when the operator and its plugins run in the same namespace. Contributed by [@maxlengdell](https://github.com/maxlengdell). ([#10940](cloudnative-pg/cloudnative-pg#10940)) <!-- 1.29 --> - `cnpg` plugin: - Used UTC time zone for the default backup name. ([#11329](cloudnative-pg/cloudnative-pg#11329)) <!-- 1.29 1.28 --> - Deleted PVCs before Pods in `cnpg destroy`, avoiding a race that could leave dangling PVCs needing a second invocation to clean up. Contributed by [@daanvinken](https://github.com/daanvinken). ([#10847](cloudnative-pg/cloudnative-pg#10847)) <!-- 1.29 1.28 -->
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fencing an instance is supposed to take that one instance out of service. Instead, while any instance is fenced the cluster loses its ability to recover from an unrelated failure: it will not elect a new primary, and it will not recreate a pod that has been deleted. Un-fencing by hand is the only way out. Three separate places in the reconciler contribute, each of them reached because a fenced instance looks healthy to the operator while its pod is permanently not Ready.
The shared cause is that a fenced instance keeps answering
/pg/status. PostgreSQL is shut down, but the instance manager is still running and reportsMightBeUnavailable, so the status carries no error while the pod never becomes Ready. Two further details matter. A fenced replica is not necessarily last in the sorted status list: entries whose status call failed are pushed to the tail before the primary-first ordering is applied, so when the primary's pod is gone, or present but unreachable, the fenced replica ends up first. And those are precisely the situations in which the cluster needs to elect a new primary.The first problem is the readiness guard. It defers reconciliation when the first instance in the list serves a healthy status endpoint while the kubelet still reports its pod as not Ready, which normally lasts a few seconds after un-fencing and avoids electing a primary Kubernetes would refuse to route traffic to. A fenced instance sits in that state permanently, and the guard cannot tell the two apart, so it requeues every ten seconds forever. Because it runs ahead of both the election and the reconciliation of the cluster's resources, nothing downstream of it happens at all. The guard now ignores fenced instances, whose not-Ready state is expected rather than a probe yet to catch up.
The second problem surfaces once the guard stops blocking. Nothing excluded a fenced instance from target primary candidacy, so with a fenced replica and no healthy primary the operator elected the fenced instance and then retried a promotion that can never complete, spinning on the same failover attempt. Both election paths now skip fenced instances, and when no promotable candidate is left the operator elects nobody and leaves the target primary alone rather than pointing it at an instance that will never come up. A fenced current primary was already handled earlier, by
handleSwitchoverdeclining the switchover before this code is reached.The third problem is the reattachment gate in
ensureInstancesAreCreated, which defers recreating a missing pod untilInstancesReportingStatus()matchescluster.Status.ReadyInstances. The first counter treats a fenced instance as reporting; the second is pure kubelet readiness and knows nothing about fencing. With anything fenced the two can never agree, so the gate deferred forever and a pod deleted elsewhere in the cluster was never recreated. The gate now excludes fenced instances from the comparison, through a predicate-taking sibling of that counter;InstancesReportingStatuskeeps its behaviour for its other call sites, which compare against the spec or status instance count and do converge with a fenced instance counted.All three use the existing
Cluster.IsInstanceFencedhelper, so the fence-all wildcard is covered as well.