Skip to content

Commit 16635f5

Browse files
committed
storage E2E: explicitly wait for PV deletion after ephemeral test
Even with foreground deletion, removal of the PVs that may have been created for a pod with generic ephemeral volumes happens asynchronously, in the worst case after the test has completed and the driver for the volume got removed. Perhaps this can be fixed in Kubernetes itself, but for now we need to deal with it as part of the test.
1 parent 1c6057b commit 16635f5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/e2e/storage/testsuites/provisioning.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,28 @@ func StopPodAndDependents(c clientset.Interface, pod *v1.Pod) {
725725
} else {
726726
framework.Logf("Pod %s has the following logs: %s", pod.Name, body)
727727
}
728+
729+
// We must wait explicitly for removal of the generic ephemeral volume PVs.
730+
// For that we must find them first...
731+
pvs, err := c.CoreV1().PersistentVolumes().List(context.TODO(), metav1.ListOptions{})
732+
framework.ExpectNoError(err, "list PVs")
733+
var podPVs []v1.PersistentVolume
734+
for _, pv := range pvs.Items {
735+
if pv.Spec.ClaimRef == nil ||
736+
pv.Spec.ClaimRef.Namespace != pod.Namespace {
737+
continue
738+
}
739+
pvc, err := c.CoreV1().PersistentVolumeClaims(pod.Namespace).Get(context.TODO(), pv.Spec.ClaimRef.Name, metav1.GetOptions{})
740+
if err != nil && apierrors.IsNotFound(err) {
741+
// Must have been some unrelated PV, otherwise the PVC should exist.
742+
continue
743+
}
744+
framework.ExpectNoError(err, "get PVC")
745+
if pv.Spec.ClaimRef.UID == pvc.UID && metav1.IsControlledBy(pvc, pod) {
746+
podPVs = append(podPVs, pv)
747+
}
748+
}
749+
728750
framework.Logf("Deleting pod %q in namespace %q", pod.Name, pod.Namespace)
729751
deletionPolicy := metav1.DeletePropagationForeground
730752
err = c.CoreV1().Pods(pod.Namespace).Delete(context.TODO(), pod.Name,
@@ -742,6 +764,14 @@ func StopPodAndDependents(c clientset.Interface, pod *v1.Pod) {
742764
}
743765
framework.Logf("Wait up to %v for pod %q to be fully deleted", e2epod.PodDeleteTimeout, pod.Name)
744766
e2epod.WaitForPodNotFoundInNamespace(c, pod.Name, pod.Namespace, e2epod.PodDeleteTimeout)
767+
if len(podPVs) > 0 {
768+
for _, pv := range podPVs {
769+
// As with CSI inline volumes, we use the pod delete timeout here because conceptually
770+
// the volume deletion needs to be that fast (whatever "that" is).
771+
framework.Logf("Wait up to %v for pod PV %s to be fully deleted", e2epod.PodDeleteTimeout, pv.Name)
772+
e2epv.WaitForPersistentVolumeDeleted(c, pv.Name, 5*time.Second, e2epod.PodDeleteTimeout)
773+
}
774+
}
745775
}
746776

747777
func verifyPVCsPending(client clientset.Interface, pvcs []*v1.PersistentVolumeClaim) {

0 commit comments

Comments
 (0)