Skip to content

Commit c42959e

Browse files
author
Jeel Oza
committed
[patch]unbind PV before deleting config-pvc to avoid Terminating deadlock
1 parent c53da86 commit c42959e

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

‎src/mas/devops/tekton.py‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -588,29 +588,36 @@ def preparePipelinesNamespace(
588588
f"Deleting to recreate with storageClassName='{storageClass}'."
589589
)
590590

591-
# Unbind the PVC by removing claimRef from its backing PV.
592-
# While the PVC is Bound, PVCProtectionController keeps re-adding the pvc-protection
593-
# finalizer, blocking deletion. Removing claimRef moves the PVC to Lost/Released,
594-
# causing the controller to drop the finalizer itself — then a normal delete works cleanly.
591+
# Unbind the PVC by clearing the claimRef on its backing PV, then remove the finalizer.
592+
# PVCProtectionController keeps re-adding pvc-protection on Bound PVCs so we must
593+
# move it to Lost state first before the finalizer patch and delete will stick.
595594
pvName = existingConfigPVC.spec.volumeName
595+
pvAPI = dynClient.resources.get(api_version="v1", kind="PersistentVolume")
596596
if pvName:
597597
logger.info(f"Unbinding config-pvc from PV '{pvName}' to allow clean deletion.")
598-
pvAPI = dynClient.resources.get(api_version="v1", kind="PersistentVolume")
598+
# Clear all claimRef fields — setting name/namespace/uid to empty strings forces
599+
# Lost state even when the PVC already has a deletionTimestamp (Terminating).
599600
pvAPI.patch(
600601
name=pvName,
601-
body={"spec": {"claimRef": None}},
602+
body={"spec": {"claimRef": {"name": "", "namespace": "", "uid": "", "resourceVersion": ""}}},
602603
content_type="application/merge-patch+json",
603604
)
604-
# Wait for the PVC to leave Bound state — once unbound, PVCProtectionController
605-
# removes the finalizer itself so the subsequent delete goes through cleanly.
605+
# Wait for the PVC to leave Bound state
606606
for _ in range(30):
607607
current = pvcAPI.get(name="config-pvc", namespace=namespace)
608608
if current.status.phase != "Bound":
609-
logger.info(f"config-pvc is now '{current.status.phase}', finalizer released.")
609+
logger.info(f"config-pvc is now '{current.status.phase}'.")
610610
break
611611
logger.debug("config-pvc still Bound, waiting 2s...")
612612
sleep(2)
613613

614+
# Remove the finalizer directly — safe now that the PVC is no longer Bound
615+
pvcAPI.patch(
616+
name="config-pvc",
617+
namespace=namespace,
618+
body={"metadata": {"finalizers": []}},
619+
content_type="application/merge-patch+json",
620+
)
614621
pvcAPI.delete(name="config-pvc", namespace=namespace)
615622
logger.info("Waiting for config-pvc deletion to complete...")
616623
while True:

0 commit comments

Comments
 (0)