Skip to content

feat(plugins): handle requeue behavior from lifecycle hooks#10283

Open
gabriele-wolfox wants to merge 6 commits intocloudnative-pg:mainfrom
gabriele-wolfox:feat/lifecycle-requeue-support
Open

feat(plugins): handle requeue behavior from lifecycle hooks#10283
gabriele-wolfox wants to merge 6 commits intocloudnative-pg:mainfrom
gabriele-wolfox:feat/lifecycle-requeue-support

Conversation

@gabriele-wolfox
Copy link
Copy Markdown
Contributor

@gabriele-wolfox gabriele-wolfox commented Mar 12, 2026

Closes #10290 .
Needs cloudnative-pg/cnpg-i#293, then a commit to update go.mod reference to CNPGI module, removing the replace directives.

Handle the BEHAVIOR_REQUEUE response from plugins in lifecycle hooks, allowing plugins to signal that a dependency is not yet available without treating it as an error condition.

Changes:

  • Add RequeueError type and helper functions in plugin client
  • Handle BEHAVIOR_REQUEUE in lifecycle hook response processing
  • Handle RequeueError gracefully in cluster controller without setting failure phase

@gabriele-wolfox gabriele-wolfox requested a review from a team as a code owner March 12, 2026 16:06
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 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 Mar 12, 2026
@github-actions
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

@dosubot dosubot bot added the enhancement 🪄 New feature or request label Mar 12, 2026
@gabriele-wolfox gabriele-wolfox force-pushed the feat/lifecycle-requeue-support branch 2 times, most recently from f61153b to 401d225 Compare March 16, 2026 13:16
gabriele-wolfox and others added 4 commits March 18, 2026 10:53
Handle the BEHAVIOR_REQUEUE response from plugins in lifecycle hooks,
allowing plugins to signal that a dependency is not yet available
without treating it as an error condition.

Changes:
- Add RequeueError type and helper functions in plugin client
- Handle BEHAVIOR_REQUEUE in lifecycle hook response processing
- Handle RequeueError gracefully in cluster controller without
  setting failure phase

Signed-off-by: Gabriele Quaresima <gabriele.quaresima@enterprisedb.com>
Use the forked cnpg-i that includes BEHAVIOR_REQUEUE support in
OperatorLifecycleResponse.

Signed-off-by: Gabriele Quaresima <gabriele.quaresima@enterprisedb.com>
Call the lifecycle hook before PVC creation/readiness checks to prevent
deadlocks when using WaitForFirstConsumer storage class with plugins
that return REQUEUE (e.g., waiting for a custom resource to be created).

Two code paths are covered:

1. createPrimaryInstance: Call lifecycle hook before generateNodeSerial
   to prevent status update before plugin is ready. Without this, the
   cluster would become unrecoverable (LatestGeneratedNode != 0 with no PVCs).

2. ensureInstancesAreCreated: Call lifecycle hook before PVC readiness
   checks to prevent waiting forever on unbound WaitForFirstConsumer PVCs.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Gabriele Quaresima <gabriele.quaresima@enterprisedb.com>
Ensure wrapAsPluginErrorIfNeeded passes through RequeueError without
wrapping it inside a pluginError. Without this fix, the requeue signal
would also be classified as a plugin failure if check ordering changed.

Also improves RequeueError.Error() to include the duration, extracts
the default requeue interval into a named constant, documents the
double lifecycle hook in createPrimaryInstance, and adds integration
and unit tests for the full BEHAVIOR_REQUEUE path.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@armru armru force-pushed the feat/lifecycle-requeue-support branch from 401d225 to 149600f Compare March 18, 2026 10:48
Add tests for untested paths: zero and negative RequeueAfter values,
non-requeue error propagation from early lifecycle hooks, and
BEHAVIOR_CONTINUE regression test. Guard against negative requeue
durations in the controller with <= 0 check instead of == 0.

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Mar 18, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 18, 2026
@armru armru self-requested a review March 18, 2026 11:21
@armru
Copy link
Copy Markdown
Member

armru commented Mar 18, 2026

/test

@github-actions
Copy link
Copy Markdown
Contributor

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

Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Mar 18, 2026
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 enhancement 🪄 New feature or request 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:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support BEHAVIOR_REQUEUE from plugin lifecycle hooks

3 participants