Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move WaitForPersistentVolumeDeleted() to e2epv #89445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/e2e/framework/pv/pv.go
Expand Up @@ -821,3 +821,21 @@ func SkipIfNoDefaultStorageClass(c clientset.Interface) {
e2eskipper.Skipf("error finding default storageClass : %v", err)
}
}

// WaitForPersistentVolumeDeleted waits for a PersistentVolume to get deleted or until timeout occurs, whichever comes first.
func WaitForPersistentVolumeDeleted(c clientset.Interface, pvName string, Poll, timeout time.Duration) error {
framework.Logf("Waiting up to %v for PersistentVolume %s to get deleted", timeout, pvName)
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {
pv, err := c.CoreV1().PersistentVolumes().Get(context.TODO(), pvName, metav1.GetOptions{})
if err == nil {
framework.Logf("PersistentVolume %s found and phase=%s (%v)", pvName, pv.Status.Phase, time.Since(start))
continue
}
if apierrors.IsNotFound(err) {
framework.Logf("PersistentVolume %s was removed", pvName)
return nil
}
framework.Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err)
}
return fmt.Errorf("PersistentVolume %s still exists within %v", pvName, timeout)
}
18 changes: 0 additions & 18 deletions test/e2e/framework/util.go
Expand Up @@ -304,24 +304,6 @@ func WaitForDefaultServiceAccountInNamespace(c clientset.Interface, namespace st
return waitForServiceAccountInNamespace(c, namespace, "default", ServiceAccountProvisionTimeout)
}

// WaitForPersistentVolumeDeleted waits for a PersistentVolume to get deleted or until timeout occurs, whichever comes first.
func WaitForPersistentVolumeDeleted(c clientset.Interface, pvName string, Poll, timeout time.Duration) error {
Logf("Waiting up to %v for PersistentVolume %s to get deleted", timeout, pvName)
for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) {
pv, err := c.CoreV1().PersistentVolumes().Get(context.TODO(), pvName, metav1.GetOptions{})
if err == nil {
Logf("PersistentVolume %s found and phase=%s (%v)", pvName, pv.Status.Phase, time.Since(start))
continue
}
if apierrors.IsNotFound(err) {
Logf("PersistentVolume %s was removed", pvName)
return nil
}
Logf("Get persistent volume %s in failed, ignoring for %v: %v", pvName, Poll, err)
}
return fmt.Errorf("PersistentVolume %s still exists within %v", pvName, timeout)
}

// findAvailableNamespaceName random namespace name starting with baseName.
func findAvailableNamespaceName(baseName string, c clientset.Interface) (string, error) {
var name string
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/storage/csi_mock_volume.go
Expand Up @@ -188,7 +188,7 @@ var _ = utils.SIGDescribe("CSI mock volume", func() {
claim, err := cs.CoreV1().PersistentVolumeClaims(claim.Namespace).Get(context.TODO(), claim.Name, metav1.GetOptions{})
if err == nil {
cs.CoreV1().PersistentVolumeClaims(claim.Namespace).Delete(context.TODO(), claim.Name, metav1.DeleteOptions{})
framework.WaitForPersistentVolumeDeleted(cs, claim.Spec.VolumeName, framework.Poll, 2*time.Minute)
e2epv.WaitForPersistentVolumeDeleted(cs, claim.Spec.VolumeName, framework.Poll, 2*time.Minute)
}

}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/storage/nfs_persistent_volume-disruptive.go
Expand Up @@ -332,6 +332,6 @@ func tearDownTestCase(c clientset.Interface, f *framework.Framework, ns string,
e2epv.DeletePersistentVolume(c, pv.Name)
return
}
err := framework.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, 5*time.Minute)
err := e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, 5*time.Minute)
framework.ExpectNoError(err, "Persistent Volume %v not deleted by dynamic provisioner", pv.Name)
}
4 changes: 2 additions & 2 deletions test/e2e/storage/pv_protection.go
Expand Up @@ -100,7 +100,7 @@ var _ = utils.SIGDescribe("PV Protection", func() {
ginkgo.By("Deleting the PV")
err = client.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, *metav1.NewDeleteOptions(0))
framework.ExpectNoError(err, "Error deleting PV")
framework.WaitForPersistentVolumeDeleted(client, pv.Name, framework.Poll, e2epv.PVDeletingTimeout)
e2epv.WaitForPersistentVolumeDeleted(client, pv.Name, framework.Poll, e2epv.PVDeletingTimeout)
})

ginkgo.It("Verify that PV bound to a PVC is not removed immediately", func() {
Expand All @@ -127,6 +127,6 @@ var _ = utils.SIGDescribe("PV Protection", func() {
framework.ExpectNoError(err, "Error deleting PVC")

ginkgo.By("Checking that the PV is automatically removed from the system because it's no longer bound to a PVC")
framework.WaitForPersistentVolumeDeleted(client, pv.Name, framework.Poll, e2epv.PVDeletingTimeout)
e2epv.WaitForPersistentVolumeDeleted(client, pv.Name, framework.Poll, e2epv.PVDeletingTimeout)
})
})
2 changes: 1 addition & 1 deletion test/e2e/storage/regional_pd.go
Expand Up @@ -210,7 +210,7 @@ func testZonalFailover(c clientset.Interface, ns string) {
framework.ExpectNoError(c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{}),
"Error deleting claim %s.", pvc.Name)
if pvc.Spec.VolumeName != "" {
err = framework.WaitForPersistentVolumeDeleted(c, pvc.Spec.VolumeName, framework.Poll, pvDeletionTimeout)
err = e2epv.WaitForPersistentVolumeDeleted(c, pvc.Spec.VolumeName, framework.Poll, pvDeletionTimeout)
if err != nil {
framework.Logf("WARNING: PV %s is not yet deleted, and subsequent tests may be affected.", pvc.Spec.VolumeName)
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/storage/testsuites/base.go
Expand Up @@ -292,7 +292,7 @@ func (r *VolumeResource) CleanupResource() error {
cleanUpErrs = append(cleanUpErrs, errors.Wrapf(err, "Failed to delete PVC %v", r.Pvc.Name))
}
if r.Pv != nil {
err = framework.WaitForPersistentVolumeDeleted(f.ClientSet, r.Pv.Name, 5*time.Second, 5*time.Minute)
err = e2epv.WaitForPersistentVolumeDeleted(f.ClientSet, r.Pv.Name, 5*time.Second, 5*time.Minute)
if err != nil {
cleanUpErrs = append(cleanUpErrs, errors.Wrapf(err,
"Persistent Volume %v not deleted by dynamic provisioner", r.Pv.Name))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/storage/testsuites/provisioning.go
Expand Up @@ -369,7 +369,7 @@ func (t StorageClassTest) TestDynamicProvisioning() *v1.PersistentVolume {
// hiccups.
if pv != nil && pv.Spec.PersistentVolumeReclaimPolicy == v1.PersistentVolumeReclaimDelete {
ginkgo.By(fmt.Sprintf("deleting the claim's PV %q", pv.Name))
framework.ExpectNoError(framework.WaitForPersistentVolumeDeleted(client, pv.Name, 5*time.Second, 20*time.Minute))
framework.ExpectNoError(e2epv.WaitForPersistentVolumeDeleted(client, pv.Name, 5*time.Second, 20*time.Minute))
}

return pv
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/storage/volume_metrics.go
Expand Up @@ -86,7 +86,7 @@ var _ = utils.SIGDescribe("[Serial] Volume metrics", func() {
} else {
e2epv.DeletePersistentVolumeClaim(c, newPvc.Name, newPvc.Namespace)
if newPvc.Spec.VolumeName != "" {
err = framework.WaitForPersistentVolumeDeleted(c, newPvc.Spec.VolumeName, 5*time.Second, 5*time.Minute)
err = e2epv.WaitForPersistentVolumeDeleted(c, newPvc.Spec.VolumeName, 5*time.Second, 5*time.Minute)
framework.ExpectNoError(err, "Persistent Volume %v not deleted by dynamic provisioner", newPvc.Spec.VolumeName)
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/storage/volume_provisioning.go
Expand Up @@ -415,7 +415,7 @@ var _ = utils.SIGDescribe("Dynamic Provisioning", func() {

ginkgo.By(fmt.Sprintf("deleting the PV %q", pv.Name))
framework.ExpectNoError(e2epv.DeletePersistentVolume(c, pv.Name), "Failed to delete PV ", pv.Name)
framework.ExpectNoError(framework.WaitForPersistentVolumeDeleted(c, pv.Name, 1*time.Second, 30*time.Second))
framework.ExpectNoError(e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 1*time.Second, 30*time.Second))
})

ginkgo.It("should not provision a volume in an unmanaged GCE zone.", func() {
Expand Down Expand Up @@ -587,7 +587,7 @@ var _ = utils.SIGDescribe("Dynamic Provisioning", func() {
framework.ExpectNoError(err)

ginkgo.By("waiting for the PV to get deleted")
err = framework.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, e2epv.PVDeletingTimeout)
err = e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, e2epv.PVDeletingTimeout)
framework.ExpectNoError(err)
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/storage/vsphere/pv_reclaimpolicy.go
Expand Up @@ -85,7 +85,7 @@ var _ = utils.SIGDescribe("PersistentVolumes [Feature:vsphere][Feature:ReclaimPo
pvc = nil

ginkgo.By("verify pv is deleted")
err = framework.WaitForPersistentVolumeDeleted(c, pv.Name, 3*time.Second, 300*time.Second)
err = e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 3*time.Second, 300*time.Second)
framework.ExpectNoError(err)

pv = nil
Expand Down Expand Up @@ -143,7 +143,7 @@ var _ = utils.SIGDescribe("PersistentVolumes [Feature:vsphere][Feature:ReclaimPo
framework.ExpectNoError(err)

ginkgo.By("Verify PV should be deleted automatically")
framework.ExpectNoError(framework.WaitForPersistentVolumeDeleted(c, pv.Name, 1*time.Second, 30*time.Second))
framework.ExpectNoError(e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 1*time.Second, 30*time.Second))
pv = nil
volumePath = ""
})
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/storage/vsphere/pvc_label_selector.go
Expand Up @@ -97,7 +97,7 @@ var _ = utils.SIGDescribe("PersistentVolumes [Feature:vsphere][Feature:LabelSele
framework.ExpectNoError(e2epv.DeletePersistentVolumeClaim(c, pvcSsd.Name, ns), "Failed to delete PVC ", pvcSsd.Name)

ginkgo.By("verify pvSsd is deleted")
err = framework.WaitForPersistentVolumeDeleted(c, pvSsd.Name, 3*time.Second, 300*time.Second)
err = e2epv.WaitForPersistentVolumeDeleted(c, pvSsd.Name, 3*time.Second, 300*time.Second)
framework.ExpectNoError(err)
volumePath = ""

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/upgrades/storage/volume_mode.go
Expand Up @@ -129,5 +129,5 @@ func (t *VolumeModeDowngradeTest) Teardown(f *framework.Framework) {
framework.ExpectNoError(f.ClientSet.CoreV1().PersistentVolumeClaims(t.pvc.Namespace).Delete(context.TODO(), t.pvc.Name, metav1.DeleteOptions{}))

ginkgo.By("Waiting for the PV to be deleted")
framework.ExpectNoError(framework.WaitForPersistentVolumeDeleted(f.ClientSet, t.pv.Name, 5*time.Second, 20*time.Minute))
framework.ExpectNoError(e2epv.WaitForPersistentVolumeDeleted(f.ClientSet, t.pv.Name, 5*time.Second, 20*time.Minute))
}