From d2be1ebb5ff6161fcefac62e2d1d29319bb54dbf Mon Sep 17 00:00:00 2001 From: pospispa Date: Sat, 20 Jan 2018 16:29:41 +0100 Subject: [PATCH] Moved func WaitForPersistentVolumeClaimBeRemoved Among Other WaitFor Functions It's better to have all WaitFor functions in the same location even though the func WaitForPersistentVolumeClaimBeRemoved is used only in one file. This was requested in [1]. [1] https://github.com/kubernetes/kubernetes/pull/56931#discussion_r156724019 --- test/e2e/framework/util.go | 16 ++++++++++++++++ test/e2e/storage/pvc_protection.go | 24 ++---------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 5142760840..fdb5ad2dd4 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -5118,3 +5118,19 @@ func waitForServerPreferredNamespacedResources(d discovery.DiscoveryInterface, t } return resources, nil } + +// WaitForPersistentVolumeClaimBeRemoved waits for a PersistentVolumeClaim to be removed from the system until timeout occurs, whichever comes first. +func WaitForPersistentVolumeClaimBeRemoved(c clientset.Interface, ns string, pvcName string, Poll, timeout time.Duration) error { + Logf("Waiting up to %v for PersistentVolumeClaim %s to be removed", timeout, pvcName) + for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) { + _, err := c.CoreV1().PersistentVolumeClaims(ns).Get(pvcName, metav1.GetOptions{}) + if err != nil { + if apierrs.IsNotFound(err) { + Logf("Claim %q in namespace %q doesn't exist in the system", pvcName, ns) + return nil + } + Logf("Failed to get claim %q in namespace %q, retrying in %v. Error: %v", pvcName, ns, Poll, err) + } + } + return fmt.Errorf("PersistentVolumeClaim %s is not removed from the system within %v", pvcName, timeout) +} diff --git a/test/e2e/storage/pvc_protection.go b/test/e2e/storage/pvc_protection.go index 5ead627263..8eaac20439 100644 --- a/test/e2e/storage/pvc_protection.go +++ b/test/e2e/storage/pvc_protection.go @@ -17,14 +17,10 @@ limitations under the License. package storage import ( - "fmt" - "time" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "k8s.io/api/core/v1" - apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clientset "k8s.io/client-go/kubernetes" "k8s.io/kubernetes/pkg/util/slice" @@ -80,7 +76,7 @@ var _ = utils.SIGDescribe("PVC Protection [Feature:PVCProtection]", func() { By("Deleting the PVC") err = client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(pvc.Name, metav1.NewDeleteOptions(0)) Expect(err).NotTo(HaveOccurred(), "Error deleting PVC") - waitForPersistentVolumeClaimBeRemoved(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout) + framework.WaitForPersistentVolumeClaimBeRemoved(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout) pvcCreatedAndNotDeleted = false }) @@ -104,23 +100,7 @@ var _ = utils.SIGDescribe("PVC Protection [Feature:PVCProtection]", func() { Expect(err).NotTo(HaveOccurred(), "Error terminating and deleting pod") By("Checking that the PVC is automatically removed from the system because it's no longer in active use by a pod") - waitForPersistentVolumeClaimBeRemoved(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout) + framework.WaitForPersistentVolumeClaimBeRemoved(client, pvc.Namespace, pvc.Name, framework.Poll, framework.ClaimProvisionTimeout) pvcCreatedAndNotDeleted = false }) }) - -// waitForPersistentVolumeClaimBeRemoved waits for a PersistentVolumeClaim to be removed from the system until timeout occurs, whichever comes first. -func waitForPersistentVolumeClaimBeRemoved(c clientset.Interface, ns string, pvcName string, Poll, timeout time.Duration) error { - framework.Logf("Waiting up to %v for PersistentVolumeClaim %s to be removed", timeout, pvcName) - for start := time.Now(); time.Since(start) < timeout; time.Sleep(Poll) { - _, err := c.CoreV1().PersistentVolumeClaims(ns).Get(pvcName, metav1.GetOptions{}) - if err != nil { - if apierrs.IsNotFound(err) { - framework.Logf("Claim %q in namespace %q doesn't exist in the system", pvcName, ns) - return nil - } - framework.Logf("Failed to get claim %q in namespace %q, retrying in %v. Error: %v", pvcName, ns, Poll, err) - } - } - return fmt.Errorf("PersistentVolumeClaim %s is not removed from the system within %v", pvcName, timeout) -}