Skip to content

Commit

Permalink
e2e: remove claimRef after deleting the PVC
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Madhu-1 authored and mergify[bot] committed Apr 13, 2022
1 parent 784b086 commit 2205145
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions e2e/rbd.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,16 @@ 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,
types.StrategicMergePatchType,
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)
}

Expand All @@ -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)

Expand Down

0 comments on commit 2205145

Please sign in to comment.