Skip to content

fix: prevent reconciler hook from skipping later plugins when an earlier one returns a continue result#9978

Merged
leonardoce merged 4 commits intocloudnative-pg:mainfrom
sharifmshaker:fix/reconcile-hook-plugin-continue-behavior
Feb 19, 2026
Merged

fix: prevent reconciler hook from skipping later plugins when an earlier one returns a continue result#9978
leonardoce merged 4 commits intocloudnative-pg:mainfrom
sharifmshaker:fix/reconcile-hook-plugin-continue-behavior

Conversation

@sharifmshaker
Copy link
Contributor

@sharifmshaker sharifmshaker commented Feb 13, 2026

Description

Fixes a bug where only the first plugin with ReconcilerHooks capability is executed during cluster/backup reconciliation. When a plugin returns BEHAVIOR_CONTINUE,
the reconciler loop returns immediately instead of continuing to process remaining plugins.

It is not clear that there is another type of reconciler.ReconcilerHooksResult that should be returned to allow processing of subsequent plugins, unless plugins are expected to use ReconcilerHooksResult_BEHAVIOR_UNSPECIFIED, but this seems inconsistent with the documentation.

Root Cause

In internal/cnpi/plugin/client/reconciler.go, the reconcilerHook function's switch statement for BEHAVIOR_CONTINUE returns immediately:

case reconciler.ReconcilerHooksResult_BEHAVIOR_CONTINUE:
    return newContinueResult(plugin.Name()) 

This breaks what I suspect is the intended behavior based on this definition

	// BEHAVIOR_CONTINUE indicates that this reconciliation loop will
	// proceed running.
	// BEHAVIOR_CONTINUE is useful when the plugin executes changes on internal status or resources not directly managed
	// by the main reconciliation loop

where I would imagine BEHAVIOR_CONTINUE should allow the loop to proceed to the next plugin before continuing with the operator's core reconciliation.

Solution

Changed the BEHAVIOR_CONTINUE case to continue the loop instead of returning:

  case reconciler.ReconcilerHooksResult_BEHAVIOR_CONTINUE:
      // Continue to next plugin

Now all plugins that return the BEHAVIOR_CONTINUE cause the reconciler hook to iterate to the next plugin.

Testing

Deployed a cluster with two plugins:

  1. barman-cloud.cloudnative-pg.io (index 0)
  2. modified local version of https://github.com/cloudnative-pg/cnpg-i-hello-world that implemented the reconciler interface (index 1)

Before Fix

The reconciler Pre hook on the second plugin (index 1) never executed

After Fix

The reconciler Pre hook for both plugins executed

Impact

I tested this with the latest version of the operator as of the time of the creation of this ticket at 1bf4584. The logic skipping plugins seems to present ever since internal/cnpi/plugin/client/reconciler.go was introduced a couple years ago and looks to be in v1.28x and v1.27.x.

Assisted-by: Claude Opus 4.6

@sharifmshaker sharifmshaker requested a review from a team as a code owner February 13, 2026 21:00
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Feb 13, 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 13, 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 bug 🐛 Something isn't working label Feb 13, 2026
@sharifmshaker sharifmshaker force-pushed the fix/reconcile-hook-plugin-continue-behavior branch from 0340c6a to 60118b4 Compare February 13, 2026 21:01
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Feb 16, 2026
@sharifmshaker sharifmshaker force-pushed the fix/reconcile-hook-plugin-continue-behavior branch from fd7350d to fcdcbfb Compare February 16, 2026 14:14
@armru armru force-pushed the fix/reconcile-hook-plugin-continue-behavior branch from fcdcbfb to 21069de Compare February 16, 2026 14:27
@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/22066547149

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 17, 2026
@gbartolini gbartolini moved this to Waiting for Second Review in CloudNativePG operator development Feb 18, 2026
@gbartolini gbartolini added this to the 1.29.0 milestone Feb 18, 2026
sharifmshaker and others added 4 commits February 19, 2026 14:01
…ier one returns a continue result

Signed-off-by: Sharif Shaker <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
@leonardoce leonardoce force-pushed the fix/reconcile-hook-plugin-continue-behavior branch from 21069de to 3b77f4e Compare February 19, 2026 13:01
@leonardoce leonardoce added no-issue ok to merge 👌 This PR can be merged labels Feb 19, 2026
@leonardoce leonardoce merged commit abe8a01 into cloudnative-pg:main Feb 19, 2026
33 of 36 checks passed
@github-project-automation github-project-automation bot moved this from Waiting for Second Review to Done in CloudNativePG operator development Feb 19, 2026
cnpg-bot pushed a commit that referenced this pull request Feb 19, 2026
… result (#9978)

When a plugin returned BEHAVIOR_CONTINUE, the reconcilerHook function
incorrectly returned early, causing subsequent plugins to be skipped.
This fix removes the early return, allowing the loop to properly iterate
through all registered plugins.

Assisted-by: Claude Opus 4.6
Signed-off-by: Sharif Shaker <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
(cherry picked from commit abe8a01)
cnpg-bot pushed a commit that referenced this pull request Feb 19, 2026
… result (#9978)

When a plugin returned BEHAVIOR_CONTINUE, the reconcilerHook function
incorrectly returned early, causing subsequent plugins to be skipped.
This fix removes the early return, allowing the loop to properly iterate
through all registered plugins.

Assisted-by: Claude Opus 4.6
Signed-off-by: Sharif Shaker <[email protected]>
Signed-off-by: Armando Ruocco <[email protected]>
Co-authored-by: Armando Ruocco <[email protected]>
(cherry picked from commit abe8a01)
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 no-issue ok to merge 👌 This PR can be merged release-1.27 release-1.28 size:L This PR changes 100-499 lines, ignoring generated files.

Development

Successfully merging this pull request may close these issues.

5 participants