Skip to content

fix(roles): check primary status before each role reconciliation#9971

Merged
mnencia merged 3 commits intomainfrom
dev/9800
Feb 22, 2026
Merged

fix(roles): check primary status before each role reconciliation#9971
mnencia merged 3 commits intomainfrom
dev/9800

Conversation

@jsilvela
Copy link
Collaborator

@jsilvela jsilvela commented Feb 12, 2026

Move the IsPrimary() check from a one-time evaluation at startup into
the reconciliation loop so that replicas and designated primaries skip
role writes, and a promoted instance starts reconciling without
requiring a pod restart.

Closes #9800

@jsilvela jsilvela requested a review from a team as a code owner February 12, 2026 14:20
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 12, 2026
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 release-1.27 release-1.28 labels Feb 12, 2026
@github-actions
Copy link
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

@dosubot dosubot bot added the chore Intangible work to reduce technical debt label Feb 12, 2026
@jsilvela jsilvela changed the title chore: reconcile managed roles in primary only chore: skip managed roles reconciliation in replica clusters Feb 12, 2026
@jsilvela jsilvela changed the title chore: skip managed roles reconciliation in replica clusters chore(roles): skip managed roles reconciliation in replica clusters Feb 12, 2026
@jsilvela jsilvela changed the title chore(roles): skip managed roles reconciliation in replica clusters chore(roles): skip managed role reconciliation in replica clusters Feb 12, 2026
@jsilvela
Copy link
Collaborator Author

/test depth=push

@github-actions
Copy link
Contributor

@jsilvela, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/21954653320

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Feb 12, 2026
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 16, 2026
@armru
Copy link
Member

armru commented Feb 16, 2026

/test

@github-actions
Copy link
Contributor

@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/22058441399

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 19, 2026
jsilvela and others added 2 commits February 21, 2026 21:16
…promotion

Move the IsPrimary() check from Start() startup into the goroutine's
per-trigger loop. The previous one-time startup check blocked the
synchronizer permanently after an in-place promotion (pg_promote does
not restart the pod), preventing role reconciliation on the newly
promoted instance and leaking goroutines from TriggerRoleSynchronizer
calls on the unbuffered channel.

The goroutine now always runs but skips reconciliation on non-primary
instances, correctly handling both the original issue (no role writes
on replicas/designated primaries) and subsequent promotions.

Signed-off-by: Armando Ruocco <[email protected]>
@mnencia mnencia removed the ok to merge 👌 This PR can be merged label Feb 22, 2026
@mnencia
Copy link
Member

mnencia commented Feb 22, 2026

/test

@github-actions
Copy link
Contributor

@mnencia, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/22278433595

@mnencia mnencia changed the title chore(roles): skip managed role reconciliation in replica clusters fix(roles): check primary status before each role reconciliation Feb 22, 2026
@mnencia mnencia added bug 🐛 Something isn't working release-1.25 release-1.27 and removed chore Intangible work to reduce technical debt labels Feb 22, 2026
@mnencia
Copy link
Member

mnencia commented Feb 22, 2026

/ok-to-merge

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Feb 22, 2026
@mnencia mnencia merged commit 24225c6 into main Feb 22, 2026
64 of 70 checks passed
@mnencia mnencia deleted the dev/9800 branch February 22, 2026 21:01
@dosubot
Copy link

dosubot bot commented Feb 22, 2026

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

cnpg-bot pushed a commit that referenced this pull request Feb 22, 2026
Move the IsPrimary() check from a one-time evaluation at startup into
the reconciliation loop so that replicas and designated primaries skip
role writes, and a promoted instance starts reconciling without
requiring a pod restart.

Closes #9800

Signed-off-by: Jaime Silvela <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit 24225c6)
cnpg-bot pushed a commit that referenced this pull request Feb 22, 2026
Move the IsPrimary() check from a one-time evaluation at startup into
the reconciliation loop so that replicas and designated primaries skip
role writes, and a promoted instance starts reconciling without
requiring a pod restart.

Closes #9800

Signed-off-by: Jaime Silvela <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit 24225c6)
mnencia added a commit that referenced this pull request Feb 22, 2026
Move the IsPrimary() check from a one-time evaluation at startup into
the reconciliation loop so that replicas and designated primaries skip
role writes, and a promoted instance starts reconciling without
requiring a pod restart.

Closes #9800

Signed-off-by: Jaime Silvela <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit 24225c6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases bug 🐛 Something isn't working lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged release-1.25 release-1.27 release-1.28 size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CNPG tries to create managed users in replica clusters, while using distributed topology

4 participants