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 <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2022-04-11 19:54:19 +05:30 committed by mergify[bot]
parent 784b086ea5
commit 2205145654

View File

@ -525,7 +525,8 @@ var _ = Describe("RBD", func() {
e2elog.Logf("pv name is empty %q in namespace %q: %v", pvc.Name, pvc.Namespace, err) 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( _, err = c.CoreV1().PersistentVolumes().Patch(
context.TODO(), context.TODO(),
pvcObj.Spec.VolumeName, pvcObj.Spec.VolumeName,
@ -533,7 +534,7 @@ var _ = Describe("RBD", func() {
patchBytes, patchBytes,
metav1.PatchOptions{}) metav1.PatchOptions{})
if err != nil { 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) pvcObj.Spec.VolumeName, err)
} }
@ -545,6 +546,19 @@ var _ = Describe("RBD", func() {
e2elog.Logf("failed to delete pvc: %w", err) 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 // validate created backend rbd images
validateRBDImageCount(f, 1, defaultRBDPool) validateRBDImageCount(f, 1, defaultRBDPool)