From af91e76df80c8c78e2d42ada466a4689398bf887 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 28 May 2020 14:45:17 +0200 Subject: [PATCH] e2epod: use foreground deletion This is useful in case that the pod owns some resources, because then waiting for the pod ensures that those resources also were removed. This should not matter at the moment because pods typically are not owners of any other object, but that will change with the introduction of generic ephemeral inline volumes (https://github.com/kubernetes/enhancements/tree/master/keps/sig-storage/1698-generic-ephemeral-volumes). --- test/e2e/framework/pod/delete.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/test/e2e/framework/pod/delete.go b/test/e2e/framework/pod/delete.go index a9c29526bd6..9fac26bb95e 100644 --- a/test/e2e/framework/pod/delete.go +++ b/test/e2e/framework/pod/delete.go @@ -48,7 +48,7 @@ func DeletePodOrFail(c clientset.Interface, ns, name string) { } // DeletePodWithWait deletes the passed-in pod and waits for the pod to be terminated. Resilient to the pod -// not existing. +// not existing. Also waits for all owned resources to be deleted. func DeletePodWithWait(c clientset.Interface, pod *v1.Pod) error { if pod == nil { return nil @@ -57,10 +57,17 @@ func DeletePodWithWait(c clientset.Interface, pod *v1.Pod) error { } // DeletePodWithWaitByName deletes the named and namespaced pod and waits for the pod to be terminated. Resilient to the pod -// not existing. +// not existing. Also waits for all owned resources to be deleted. func DeletePodWithWaitByName(c clientset.Interface, podName, podNamespace string) error { e2elog.Logf("Deleting pod %q in namespace %q", podName, podNamespace) - err := c.CoreV1().Pods(podNamespace).Delete(context.TODO(), podName, metav1.DeleteOptions{}) + deletionPolicy := metav1.DeletePropagationForeground + err := c.CoreV1().Pods(podNamespace).Delete(context.TODO(), podName, + metav1.DeleteOptions{ + // If the pod is the owner of some resources (like ephemeral inline volumes), + // then we want to be sure that those are also gone before we return. + // Blocking pod deletion via metav1.DeletePropagationForeground achieves that. + PropagationPolicy: &deletionPolicy, + }) if err != nil { if apierrors.IsNotFound(err) { return nil // assume pod was already deleted