Repository navigation
Conversation
|
❗ By default, the pull request is configured to backport to all release branches.
|
|
For maintainers' attention to evaluate inclusion in 1.29.0. |
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]>
Signed-off-by: Armando Ruocco <[email protected]>
…ng phase Add allInstancesAreActive() check to the safety net that clears stuck scaling phases. This prevents an unnecessary PhaseHealthy status write when instances exist but aren't fully active yet, avoiding a brief status flicker before the later inactive-instance check overrides it. Signed-off-by: Armando Ruocco <[email protected]>
24c874a to
ef493a0
Compare
|
/test limit=aks ft=replication tl=1 |
|
@armru, here's the link to the E2E on CNPG workflow run: https://github.com/cloudnative-pg/cloudnative-pg/actions/runs/22136989712 |
98fb519 to
4a10435
Compare
Replace racy pod-deletion approach with a synthetic failed job: create a Job with correct CNPG labels and cluster owner reference, set its status to Failed, then set the cluster phase to "Creating replica". This guarantees the test exercises the failed-job exclusion in runningJobNames() without racing against a real Kubernetes job. Signed-off-by: Armando Ruocco <[email protected]>
9dcecf8 to
f1cf1ef
Compare
|
Hello Jeff, some of my considerations after having spent a bit of time on the patch: Drawbacks of the current approach
3. Dual-purpose objects — A K8s Job is being used both as infrastructure (run a task) AND as application state (don't retry this snapshot).
Alternative design Store the failure state where on the Cluster instead of using jobs as a state:
This eliminates:
And it gains:
|
|
Thanks for the thorough review, @armru. Let me work through each point.
|
|
One thing I didn't articulate well earlier: the retained failed job isn't just for troubleshooting, it's a user-facing control mechanism. If CNPG falls back to With Cluster-level state, the equivalent recovery requires knowing how to clear a CNPG-specific condition or annotation. At 3am, kubectl delete job is a lot more intuitive. |
Slack discussion summary (@armru + @jmealo)Should failed jobs be retained or cleaned up?@armru's position:
@jmealo's position:
Where we landed:
Summarized by: Claude 4.5 Opus |
Summary
When a job fails or is manually deleted during replica creation, the reconciler could get stuck indefinitely in a scaling phase. This PR fixes that by:
runningJobNames())All signals are deterministic: no timeouts.
Changes
pkg/utils/job_conditions.goIsJobFailed()helperapi/v1/cluster_funcs.goIsScalingPhase()helperinternal/controller/cluster_status.gorunningJobNames()excludes failed jobsinternal/controller/cluster_cleanup.gocleanupCompletedJobs()preserves failed jobs (only deletes successful ones)internal/controller/cluster_controller.goreconcileResourcesclears stuck scaling phaseWhat This Fixes
Failed jobs blocking reconciliation: Previously,
runningJobNames()only excluded completed jobs. A failed job would still be considered "running" and block the reconciler.Stuck scaling phase after manual job deletion: The workaround for [Bug]: Cluster reconciliation loop gets stuck when scaling replicas due to failed snapshot recovery jobs #7793 was to manually delete the stuck job, but the cluster phase would remain stuck on "Creating a new replica". The new safety net detects when the cluster is in a scaling phase but has the correct instance count with no running jobs, and clears the phase to Healthy.
Design Decision: Failed Jobs Are Preserved
Failed jobs are intentionally left in place (not cleaned up) for two reasons:
Only completed/successful jobs are cleaned up by
cleanupCompletedJobs().Test Plan
IsJobFailed()helperIsScalingPhase()helperrunningJobNames()excluding failed jobscleanupCompletedJobs()does NOT delete failed jobsRelated
Fixes #7793