From 98ff221a21adfe636cdcfe963a6de31f17c8c879 Mon Sep 17 00:00:00 2001 From: Snake Game Developer Date: Sat, 21 Mar 2026 07:47:23 +0000 Subject: [PATCH] Fix PV rebinding after deployment stop/start cycle deployment stop deletes the namespace (and PVCs) but preserves PVs by default. On the next deployment start, PVs are in Released state with a stale claimRef pointing at the deleted PVC. New PVCs cannot bind to Released PVs, so pods get stuck in Pending. Clear the claimRef on any Released PV during _create_volume_data() so the PV returns to Available and can accept new PVC bindings. Co-Authored-By: Claude Opus 4.6 (1M context) --- stack_orchestrator/deploy/k8s/deploy_k8s.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/stack_orchestrator/deploy/k8s/deploy_k8s.py b/stack_orchestrator/deploy/k8s/deploy_k8s.py index 438c1c81..16015c3b 100644 --- a/stack_orchestrator/deploy/k8s/deploy_k8s.py +++ b/stack_orchestrator/deploy/k8s/deploy_k8s.py @@ -346,7 +346,22 @@ class K8sDeployer(Deployer): name=pv.metadata.name ) if pv_resp: - if opts.o.debug: + # If PV is in Released state (stale claimRef from a + # previous deployment), clear the claimRef so a new + # PVC can bind to it. This happens after stop+start + # because stop deletes the namespace (and PVCs) but + # preserves PVs by default. + if pv_resp.status and pv_resp.status.phase == "Released": + print( + f"PV {pv.metadata.name} is Released, " + "clearing claimRef for rebinding" + ) + pv_resp.spec.claim_ref = None + self.core_api.patch_persistent_volume( + name=pv.metadata.name, + body={"spec": {"claimRef": None}}, + ) + elif opts.o.debug: print("PVs already present:") print(f"{pv_resp}") continue