Repository navigation
Conversation
When a job fails or is manually deleted during replica creation, the reconciler could get stuck. This fix ensures failed jobs don't block reconciliation by excluding them from runningJobNames(). Note: Failed jobs are intentionally NOT deleted by cleanupCompletedJobs. They are kept for troubleshooting and serve as markers for fallback logic (e.g., snapshot recovery fallback in phase 2). Fixes: cloudnative-pg#7793 Assisted-by: Claude Opus 4.5 Signed-off-by: Jeff Mealo <[email protected]>
Add E2E tests to verify: 1. Cluster scaling resilience: - Create cluster, scale up, attempt to disrupt join job - Verify cluster reaches healthy state regardless of job outcome - Verify scaling back down works correctly 2. Safety net clears stuck phase: - Create healthy cluster - Manually set phase to "Creating replica" to simulate stuck state - Verify safety net clears phase when instances match desired count These tests validate the fix for the reconciliation loop getting stuck when jobs fail during scaling operations. Assisted-by: Claude Opus 4.5 Signed-off-by: Jeff Mealo <[email protected]>
Use the typed constant corev1.ConditionTrue instead of the string literal "True" for checking job failure conditions. This matches the project convention used in pod_conditions.go and other condition checks. Assisted-by: Claude Opus 4.5 Signed-off-by: Jeff Mealo <[email protected]>
When a snapshot-recovery job fails, the operator now tracks which specific VolumeSnapshot was attempted using the cnpg.io/snapshotDataSource annotation. This allows the operator to: 1. Skip only the specific snapshot that has failed, not all snapshots 2. Allow new snapshots taken after the failure to be attempted 3. Keep failed jobs for troubleshooting evidence To re-enable snapshot recovery for a specific snapshot, delete its failed job. This change builds on phase 1 which prevents failed jobs from blocking the reconciliation loop by excluding them from runningJobNames(). Assisted-by: Claude Opus 4.5 Signed-off-by: Jeff Mealo <[email protected]>
Add E2E test to verify snapshot-based replica creation and graceful fallback when scaling up a cluster with a completed volume snapshot: 1. Create single-instance cluster with WAL archiving (MinIO) and snapshot support 2. Take volume snapshot backup and wait for completion 3. Scale up to 3 instances to trigger snapshot-based replica creation 4. Verify cluster reaches healthy state with all replicas ready This validates that the operator uses snapshots for replica creation when available and can fall back to pg_basebackup if needed. Assisted-by: Claude Opus 4.6 Signed-off-by: Jeff Mealo <[email protected]>
CreateInstancePVCs returns a requeue request when PVCs are newly created. Previously, we returned early on this requeue, which prevented the init/join job from being created in the same reconciliation loop. This left dangling PVCs without pods, causing the operator to get stuck in "PVC not ready" loop. Fix by intentionally ignoring the ctrl.Result from CreateInstancePVCs, matching the upstream pattern where callers only check the error return. Also fix E2E test assertion type mismatch (ReadyInstances is int, not int32) and use the correct fixture for snapshot fallback test. Assisted-by: Claude Opus 4.6 Signed-off-by: Jeff Mealo <[email protected]>
jmealo
requested review from
NiccoloFei,
jsilvela and
litaocdl
as code owners
February 17, 2026 21:44
Contributor
|
❗ By default, the pull request is configured to backport to all release branches.
|
This was referenced Feb 17, 2026
Contributor
|
For maintainers' attention to evaluate inclusion in 1.29.0. |
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.
Summary
When a snapshot recovery job fails during replica creation, the operator now automatically falls back to using
pg_basebackupinstead of remaining stuck or repeatedly retrying broken snapshot recovery.This provides self-healing behavior: instead of just unblocking (#10004), the cluster recovers by trying an alternative join method.
Changes
internal/controller/cluster_create.gogetFailedSnapshotDataSources(), integrate fallback logic injoinReplicaInstance, and annotate snapshot-recovery jobs with their data sourceinternal/controller/cluster_create_test.gogetFailedSnapshotDataSources()and fallback behaviorpkg/utils/labels_annotations.goSnapshotDataSourceAnnotationNameconstanttests/e2e/failed_job_handling_test.goHow It Works
joinReplicaInstanceis called and a snapshot source is available:This design means:
kubectl delete job <job-name>)Why Create PVCs Before Job
The order of operations was changed from "create job, then PVCs" to "create PVCs, then job" because:
createPrimaryInstanceNote: The
ctrl.ResultfromCreateInstancePVCsis intentionally ignored in bothcreatePrimaryInstanceandjoinReplicaInstance. PVC creation returns a requeue request, but the init/join job must be created in the same reconciliation loop. Returning early would leave dangling PVCs without pods, causing the operator to get stuck.Test Plan
getFailedSnapshotDataSources()Related
Fixes [Bug]: Cluster reconciliation loop gets stuck when scaling replicas due to failed snapshot recovery jobs #7793