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) <noreply@anthropic.com>
This commit is contained in:
Snake Game Developer 2026-03-21 07:47:23 +00:00
parent 7141dc7637
commit 98ff221a21

View File

@ -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