From 2205145654cdcfd87c8f9695745c02e391b0b540 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 11 Apr 2022 19:54:19 +0530 Subject: [PATCH] e2e: remove claimRef after deleting the PVC Instead of patching the PV to update the persistentVolumeReclaimPolicy and the claimRef before deleting the PVC. Patch PV persistentVolumeReclaimPolicy to Retain to retain the PV after deleting the PVC. Remove the claimRef on the PV after deleting the PVC so that claim can be attached to a new PVC. Signed-off-by: Madhu Rajanna --- e2e/rbd.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/e2e/rbd.go b/e2e/rbd.go index a8a7d8c55..f708ca5d7 100644 --- a/e2e/rbd.go +++ b/e2e/rbd.go @@ -525,7 +525,8 @@ var _ = Describe("RBD", func() { e2elog.Logf("pv name is empty %q in namespace %q: %v", pvc.Name, pvc.Namespace, err) } - patchBytes := []byte(`{"spec":{"persistentVolumeReclaimPolicy": "Retain", "claimRef": null}}`) + // patch PV to Retain it after deleting the PVC. + patchBytes := []byte(`{"spec":{"persistentVolumeReclaimPolicy": "Retain"}}`) _, err = c.CoreV1().PersistentVolumes().Patch( context.TODO(), pvcObj.Spec.VolumeName, @@ -533,7 +534,7 @@ var _ = Describe("RBD", func() { patchBytes, metav1.PatchOptions{}) if err != nil { - e2elog.Logf("error Patching PV %q for persistentVolumeReclaimPolicy and claimRef: %v", + e2elog.Logf("error Patching PV %q for persistentVolumeReclaimPolicy: %v", pvcObj.Spec.VolumeName, err) } @@ -545,6 +546,19 @@ var _ = Describe("RBD", func() { e2elog.Logf("failed to delete pvc: %w", err) } + // Remove the claimRef to bind this PV to a new PVC. + patchBytes = []byte(`{"spec":{"claimRef": null}}`) + _, err = c.CoreV1().PersistentVolumes().Patch( + context.TODO(), + pvcObj.Spec.VolumeName, + types.StrategicMergePatchType, + patchBytes, + metav1.PatchOptions{}) + if err != nil { + e2elog.Logf("error Patching PV %q for claimRef: %v", + pvcObj.Spec.VolumeName, err) + } + // validate created backend rbd images validateRBDImageCount(f, 1, defaultRBDPool)