Skip to content

feat(warn): alert users when a multi-instance cluster has no synchronous replication - #11148

Merged
mnencia merged 11 commits into
cloudnative-pg:mainfrom
leonardoce:warn-users-sync
Jul 23, 2026
Merged

mnencia merged 11 commits into
cloudnative-pg:mainfrom
leonardoce:warn-users-sync

Conversation

@leonardoce

@leonardoce leonardoce commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Multi-instance clusters without synchronous replication are silently exposed to data loss on primary failure: transactions not yet replicated to a standby will be lost when the primary's availability zone goes down.

Add a webhook warning to make this risk visible at apply time. The warning is suppressed when either the current (.spec.postgresql.synchronous) or the legacy (.spec.minSyncReplicas) synchronous replication API is configured.

Closes #11180

@leonardoce
leonardoce requested a review from a team July 8, 2026 09:09
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 8, 2026
@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 Jul 8, 2026
@dosubot dosubot Bot added the enhancement 🪄 New feature or request label Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

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

@leonardoce leonardoce added do not backport This PR must not be backported - it will be in the next minor release no-issue and removed backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30 labels Jul 8, 2026
@armru
armru requested a review from jsilvela as a code owner July 9, 2026 16:04
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 9, 2026
@armru
armru force-pushed the warn-users-sync branch from 0a748e4 to 8937a9b Compare July 9, 2026 16:06
@armru

armru commented Jul 9, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 14, 2026
@mnencia

mnencia commented Jul 21, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

leonardoce and others added 10 commits July 23, 2026 12:09
…ous replication

Multi-instance clusters without synchronous replication are silently
exposed to data loss on primary failure: transactions not yet replicated
to a standby will be lost when the primary's availability zone goes down.

Add a webhook warning to make this risk visible at apply time, targeting
users who deploy a cluster expecting HA and data safety without knowing
that async replication does not guarantee durability. The warning is
suppressed when either the current (.spec.postgresql.synchronous) or the
legacy (.spec.minSyncReplicas) synchronous replication API is configured.

Signed-off-by: Leonardo Cecchi <[email protected]>
The legacy API enables synchronous replication when maxSyncReplicas is
greater than zero, while minSyncReplicas is only the floor applied when
not enough replicas are ready, and validation requires minSyncReplicas
to be lower than or equal to maxSyncReplicas. Checking minSyncReplicas
alone made the warning fire for clusters that run quorum-based
synchronous replication with maxSyncReplicas set and minSyncReplicas
left at its default of zero.

Signed-off-by: Armando Ruocco <[email protected]>
… only

Raising it on every update would repeat the warning on each kubectl
apply and on every patch of the cluster resource, including the ones
issued by the operator and by the plugin. Raising it when the cluster
is created is enough to make the risk visible.

Signed-off-by: Armando Ruocco <[email protected]>
… clusters

A replica cluster replays data coming from another cluster, so losing
its designated primary doesn't lose data from the topology and the
suggestion to configure synchronous replication doesn't apply.

Signed-off-by: Armando Ruocco <[email protected]>
Explain that enabling synchronous replication requires enough standby
servers to tolerate the loss of one of them, recommend planning for it
in clusters with at least three instances, and point smaller clusters
to the preferred data durability setting.

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Gabriele Bartolini <[email protected]>
Signed-off-by: Francesco Canovai <[email protected]>
Restoring the check to every apply, not just creation, is the only
way it can catch the transition that matters most: a cluster losing
its synchronous replication configuration, whether through an update
that clears .spec.postgresql.synchronous or through scaling to two or
more instances. A one-shot check at creation time leaves that change
completely silent, which defeats the purpose of the warning.

The legacy-API suppression is also keyed off minSyncReplicas again
instead of maxSyncReplicas. The self-healing logic in
getSyncReplicasData drops the effective synchronous requirement to
minSyncReplicas whenever fewer replicas are ready than
maxSyncReplicas, and minSyncReplicas defaults to zero. A cluster with
only maxSyncReplicas set therefore loses its durability guarantee
during any transient replica outage, such as a rolling update or a
node drain, which is exactly the risk this warning exists to surface.

Signed-off-by: Marco Nenciarini <[email protected]>
Neither fix in the previous commit had a regression test: reverting
either the minSyncReplicas check or the create/update wiring back to
the old behavior still left the full suite green. Add a case for a
cluster with only maxSyncReplicas set, one at the Instances == 2
boundary, and one asserting the warning is returned by both
ValidateCreate and ValidateUpdate.

Signed-off-by: Marco Nenciarini <[email protected]>
…re in e2e

AssertClusterDefault re-validates a just-created cluster and expects
zero admission warnings, on the assumption that any warning means
defaulting is broken. The e2e fixtures it's used with are multi-instance
clusters that intentionally don't configure synchronous replication,
so they now trip the new warning and fail this unrelated assertion.
Accept that one specific warning while still failing on anything else.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia

mnencia commented Jul 23, 2026

Copy link
Copy Markdown
Member

/test

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Jul 23, 2026
cluster-example.yaml, and its inline copy in the quickstart guide, are
the template most users start a cluster from. Left as-is, applying it
now trips the new missing-synchronous-replication warning on a
three-instance cluster. Enable quorum-based synchronous replication
with one required standby, the configuration replication.md already
uses as the reference example for this exact template.

Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia
mnencia merged commit 0552b9c into cloudnative-pg:main Jul 23, 2026
31 checks passed
gbartolini pushed a commit to leonardoce/cloudnative-pg that referenced this pull request Aug 10, 2026
…ication

The warning fired on any multi-instance cluster with default
configuration, making the webhook end-to-end test fail. The change is
independently proposed in cloudnative-pg#11148, where its design is being discussed:
this PR stays focused on failure domain-aware synchronous replication.

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

do not backport This PR must not be backported - it will be in the next minor release enhancement 🪄 New feature or request lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Warn when a multi-instance cluster has no synchronous replication configured

6 participants