Skip to content

Commit ae48a6b

Browse files
author
Jeel Oza
committed
[patch] delete config-pvc on storageClass mismatch before recreating
1 parent 943f4f6 commit ae48a6b

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/mas/devops/tekton.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,28 @@ def preparePipelinesNamespace(
579579

580580
# Create config PVC if requested
581581
if createConfigPVC:
582+
# If config-pvc already exists with a different storageClass, delete it first.
583+
# Kubernetes does not allow changing storageClassName on an existing PVC (immutable
584+
# field), so patching would fail with a conflict error. Deleting and recreating
585+
# is safe here because config-pvc only holds transient pipeline workspace data —
586+
# it is not a source of truth for any persistent application state.
587+
try:
588+
existingConfigPVC = pvcAPI.get(name="config-pvc", namespace=namespace)
589+
existingStorageClass = existingConfigPVC.spec.storageClassName
590+
if existingStorageClass != storageClass:
591+
logger.info(
592+
f"config-pvc already exists with storageClassName='{existingStorageClass}' "
593+
f"which differs from requested storageClassName='{storageClass}'. "
594+
f"Deleting existing config-pvc so it can be recreated with the correct storageClass."
595+
)
596+
pvcAPI.delete(name="config-pvc", namespace=namespace)
597+
else:
598+
logger.info(
599+
f"config-pvc already exists with matching storageClassName='{existingStorageClass}', skipping delete."
600+
)
601+
except NotFoundError:
602+
pass # PVC does not exist yet — will be created below
603+
582604
logger.info("Creating config PVC")
583605
template = env.get_template("pipelines-pvc.yml.j2")
584606
renderedTemplate = template.render(

0 commit comments

Comments
 (0)