Repository navigation
Description
Is there an existing issue already for this bug?
- I have searched for an existing issue, and could not find anything. I believe this is a new bug.
I have read the troubleshooting guide
- I have read the troubleshooting guide and I think this is a new bug.
I am running a supported version of CloudNativePG
- I have read the troubleshooting guide and I think this is a new bug.
Contact Details
Version
1.26 (latest patch)
What version of Kubernetes are you using?
1.31
What is your Kubernetes environment?
Cloud: Azure AKS
How did you install the operator?
YAML manifest
What happened?
When scaling up a CloudNativePG cluster, if the snapshot recovery job for a new replica fails, the controller can get stuck in a reconciliation loop. The cluster status remains in "Creating a new replica", and even after manually deleting the failed job, the cluster does not return to a healthy state. This prevents any further scaling operations and can lead to production issues if not manually resolved.
To Reproduce
Steps to reproduce the behavior:
- Have a healthy CNPG cluster.
- Attempt to scale up the number of instances (e.g., from 9 to 10).
- Induce a failure in the snapshot recovery process for the new replica. This could be due to a missing PVC, an invalid volume snapshot, or other underlying infrastructure issues that make the job unscheduleable.
- Observe that a
snapshot-recoveryjob is created. - The job fails and the pod for the job remains in a
Pendingstate because the required PVCs are not found. - The cluster status becomes
Creating a new replicaand gets stuck there. - Manually delete the failed job using
kubectl delete job <job-name>. - Observe that the cluster status does not change and remains stuck.
Expected behavior
- After a snapshot recovery job fails a certain number of times, the controller should abandon the attempt for that specific instance and either:
a. Try creating the replica again from scratch (e.g., via streaming replication).
b. Mark the instance as failed and allow the cluster to return to aReadystate with the existing healthy replicas. - Deleting a failed job should immediately trigger the controller to re-evaluate the cluster state and either retry the operation or clear the stuck phase.
Actual behavior
The controller remains stuck in the Creating a new replica phase, even after the failed job is deleted. The only way to recover is to manually patch the cluster's status to remove the phase and phaseReason fields.
Workaround
The following manual intervention was required to unstick the cluster:
-
Delete the stuck snapshot-recovery job:
kubectl delete job <cluster-name>-<instance-id>-snapshot-recovery -n <namespace>
-
Clear the cluster phase and reason from the status:
kubectl patch cluster <cluster-name> -n <namespace> --type='json' -p='[ {"op": "remove", "path": "/status/phase"}, {"op": "remove", "path": "/status/phaseReason"} ]' --subresource=status
Supporting data
-
Cluster Status when stuck:
status: phase: Creating a new replica phaseReason: Creating replica <cluster-name>-<instance-id>-snapshot-recovery
-
Job Pod Events:
Events: Type Reason Age From Message ---- ------ ---- ---- ------- Warning FailedScheduling 3m40s (x201 over 7h3m) default-scheduler 0/90 nodes are available: persistentvolumeclaim "<pvc-name>" not found.
System information
- CloudNativePG version: 1.26.0
- Kubernetes version: 1.31
- Cloud provider: Azure (AKS)
Additional context
The use of Jobs for recovery is not immediately obvious to end-users (due to how instance pods are scheduled without using deployments), making troubleshooting difficult. Improving the controller's resilience to such failures and documenting the recovery process would be highly beneficial. I'd like to try to clean up parts of my run book to add to a troubleshooting section while we still have some rough edges.
Cluster resource
Relevant log output
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsIn Development
Activity
dosubot commentedon Sep 8, 2025
Hi, @jmealo. I'm Dosu, and I'm helping the cloudnative-pg team manage their backlog and am marking this issue as stale.
Issue Summary:
Next Steps:
Thank you for your understanding and contribution!
jmealo commentedon Sep 8, 2025
This is still relevant. I have a PR open to fix it, but I haven't had a chance to test it in a cluster yet, I've only run the unit tests. It hasn't passed the E2E tests (not sure how to get those triggered). #7794
github-actions commentedon Nov 14, 2025
This issue is stale because it has been open for 60 days with no activity.
github-actions commentedon Nov 29, 2025
This issue was closed because it has been inactive for 14 days since being marked as stale.
fix(controller): handle failed jobs and stuck scaling phases