Repository navigation
Conversation
…tate Nothing stopped decision code from reading an observed field (e.g. IsWalReceiverActive, IsPrimary, TimeLineID) off an instance whose /pg/status probe failed and getting back a Go zero value instead of a real observation. Add InstanceSet, which splits a PostgresqlStatusList into the instances that actually reported their status and the ones that didn't, the latter further split by whether kubelet still considers the pod Ready. Only Pod and Node, which are always populated regardless of the probe outcome, are exposed for a silent instance. updateClusterStatusThatRequiresInstancesState is the first consumer: it rebuilt InstancesReportedState from scratch every reconciliation and wrote an entry for every item in the status list unconditionally, so an instance whose status probe failed had its IsPrimary, TimeLineID and IP published as zero values into the CRD as though they had been observed. Keep the map across reconciliations instead of rebuilding it, and only write or overwrite an entry for an instance that is actually reporting; a silent instance keeps whatever entry it already had, and gets no entry at all if this is its first-ever observation. An instance is only removed from the map once it stops appearing in the status list altogether (scaled down, or replaced under the same name), which is also what keeps ensureInstancesAreReachable in the isolation check from pinging a pod that is actually gone rather than merely unreachable this pass. Signed-off-by: Armando Ruocco <[email protected]>
The comment claimed that a pod goes missing from the probed status list only when it has been scaled down or replaced, and that every instance still belonging to the cluster shows up in that list on every pass. The first half is incomplete and the second one is wrong: GetStatusFromInstances probes only the pods accepted by utils.IsPodActive, so a pod that is pending or terminating never enters the list at all, and its entry is pruned while it is being recreated. That pruning is the behaviour we want, because the entry goes away before the replacement pod exists and so cannot survive to hand the isolation check an address that has meanwhile moved to a different pod. Say that, instead of resting the explanation on a guarantee the code does not give. Signed-off-by: Armando Ruocco <[email protected]>
The existing cases all pair a failed probe with a zero-valued status, so they cannot tell a decision taken on the error apart from one taken on the values happening to look empty. Feed a failed probe carrying a full status that disagrees with the last known observation on every field, and assert that both the reported state and the timeline on the status root keep the values last actually observed. Signed-off-by: Armando Ruocco <[email protected]>
When a cluster is switched to replica cluster mode, the operator looks for a primary among the instances that reported their status and fences the cluster to demote it. An instance whose status probe failed reports no role at all, so a single failing probe made the operator conclude that there was no primary to demote and skip the transition entirely, while that primary kept accepting writes. The pass ends up requeued a few seconds later, so the demotion did eventually happen, but only once the probe answered again: for as long as the operator could not reach an instance that clients could, the cluster was a replica cluster on paper with a writable primary behind it. The decision now falls back on the last state observed for the instance recorded as the current primary, kept in .status.instancesReportedState. Fencing is a metadata write that goes through the API server, so stopping that primary never required reaching it in the first place. The fallback is deliberately narrow. It asks for an instance that was actually observed as a primary, which a designated primary never is since it runs with a standby.signal file, so a replica cluster created from scratch is left alone when its designated primary goes quiet. It also requires the instance to still be among the probed ones, because one that has left the status list has no PostgreSQL left to stop, and it steps aside once a demotion token exists, so a probe failing right after a completed transition cannot start a second one. Signed-off-by: Armando Ruocco <[email protected]>
Contributor
|
❗ By default, the pull request is configured to backport to all release branches.
|
Contributor
|
Warning Linked issue missing. Reference one in the PR body using a keyword (Closes / Fixes / Resolves / Refs / See) followed by Alternatively, apply the |
armru
marked this pull request as draft
July 29, 2026 08:13
Member
Author
|
merged on 11260 |
Contributor
|
❗ By default, the pull request is configured to backport to all release branches.
|
4 tasks done
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.
Based on #11260, whose commits are included here: the fallback below reads
.status.instancesReportedState, which only becomes trustworthy once a failedprobe stops overwriting an instance's entry with zeros.
When a cluster is switched to replica cluster mode,
replicaclusterswitchlooks for a primary among the instances that reported their status and, when it
finds one, fences the cluster to demote it. An instance whose
/pg/statusprobe failed reports no role at all,
IsPrimaryincluded, so a single failingprobe made
containsPrimaryInstancereturn false and the reconciler take its"no primary instance present means that we have no work to do" branch, skipping
the transition while that primary kept accepting writes.
Nothing else in that pass fences it either.
AllReadyInstancesStatusUnreachableonly trips when every ready instance is silent, and the
IsCompletegate thatdoes stop the reconcile sits further down, past the point where the demotion
would have started. The pass is requeued about ten seconds later by
evaluatePodReadinessGuards, so the demotion does eventually happen, but onlyonce the probe answers again: for as long as the operator could not reach an
instance that clients could, the cluster was a replica cluster on paper with a
writable primary behind it.
The decision now falls back on the last state observed for the instance
recorded as the current primary. Fencing is a metadata write that goes through
the API server, so stopping that primary never required reaching it in the
first place, and the transition completes on the instance manager's own watch of
the Cluster object rather than on an operator probe.
The fallback is deliberately narrow, so that it fires only where a primary
really is at stake:
designated primary never is since it runs with a
standby.signalfile, so areplica cluster created from scratch is left alone when its designated primary
goes quiet;
has left the status list has no PostgreSQL left to stop;
completed transition cannot start a second one and fence a healthy replica
cluster.
The package had no coverage of
Reconcileat all, so the tests come with it:the silent-primary case, the reporting-primary case that must keep working, and
one case per carve-out above.
There is no issue tracking this. It came out of reviewing #11260, which fixes
the fabricated data this fallback relies on not being fabricated.