Skip to content

Commit

Permalink
wait for NFS PVs to be deleted before continuing
Browse files Browse the repository at this point in the history
Intended to help with flakes, but didn't make a difference.
Probably still worth doing.

Signed-off-by: Maya Rashish <mrashish@redhat.com>
  • Loading branch information
maya-r committed Sep 24, 2020
1 parent 45fe71c commit 1c48937
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tests/framework/nfs-utils.go
Expand Up @@ -29,7 +29,11 @@ func createNFSPVs(client *kubernetes.Clientset, cdiNs string) error {

func deleteNFSPVs(client *kubernetes.Clientset, cdiNs string) error {
for i := 1; i <= pvCount; i++ {
if err := utils.DeletePV(client, nfsPVDef(strconv.Itoa(i), utils.NfsService.Spec.ClusterIP)); err != nil {
pv := nfsPVDef(strconv.Itoa(i), utils.NfsService.Spec.ClusterIP)
if err := utils.DeletePV(client, pv); err != nil {
return err
}
if err := utils.WaitTimeoutForPVDeleted(client, pv, timeout); err != nil {
return err
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/utils/pv.go
Expand Up @@ -83,6 +83,17 @@ func WaitTimeoutForPVStatus(clientSet *kubernetes.Clientset, pvName string, stat
return wait.PollImmediate(2*time.Second, timeout, pvPhase(clientSet, pvName, status))
}

// WaitTimeoutForPVDeleted waits until the given pv no longer exists
func WaitTimeoutForPVDeleted(clientSet *kubernetes.Clientset, pv *k8sv1.PersistentVolume, timeout time.Duration) error {
return wait.PollImmediate(pvPollInterval, timeout, func() (bool, error) {
err := clientSet.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.GetName(), metav1.DeleteOptions{})
if apierrs.IsNotFound(err) {
return true, nil
}
return false, err
})
}

func pvPhase(clientSet *kubernetes.Clientset, pvName string, status k8sv1.PersistentVolumePhase) wait.ConditionFunc {
return func() (bool, error) {
pv, err := clientSet.CoreV1().PersistentVolumes().Get(context.TODO(), pvName, metav1.GetOptions{})
Expand Down

0 comments on commit 1c48937

Please sign in to comment.