diff --git a/test/e2e/apimachinery/garbage_collector.go b/test/e2e/apimachinery/garbage_collector.go index a7c76779cf4..6870a11f285 100644 --- a/test/e2e/apimachinery/garbage_collector.go +++ b/test/e2e/apimachinery/garbage_collector.go @@ -42,6 +42,7 @@ import ( "k8s.io/kubernetes/test/e2e/framework" e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics" e2enode "k8s.io/kubernetes/test/e2e/framework/node" + e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" "github.com/onsi/ginkgo" @@ -443,6 +444,9 @@ var _ = SIGDescribe("Garbage collector", func() { framework.Failf("expect %d pods, got %d pods", e, a) } gatherMetrics(f) + if err = e2epod.DeletePodsWithGracePeriod(clientSet, pods.Items, 0); err != nil { + framework.Logf("WARNING: failed to delete pods: %v", err) + } }) // deleteOptions.OrphanDependents is deprecated in 1.7 and preferred to use the PropagationPolicy. @@ -489,6 +493,9 @@ var _ = SIGDescribe("Garbage collector", func() { framework.Failf("expect %d pods, got %d pods", e, a) } gatherMetrics(f) + if err = e2epod.DeletePodsWithGracePeriod(clientSet, pods.Items, 0); err != nil { + framework.Logf("WARNING: failed to delete pods: %v", err) + } }) /* @@ -827,6 +834,9 @@ var _ = SIGDescribe("Garbage collector", func() { } } gatherMetrics(f) + if err = e2epod.DeletePodsWithGracePeriod(clientSet, pods.Items, 0); err != nil { + framework.Logf("WARNING: failed to delete pods: %v", err) + } }) // TODO: should be an integration test diff --git a/test/e2e/framework/pod/delete.go b/test/e2e/framework/pod/delete.go index 2da92d4d8e0..af28bcd938a 100644 --- a/test/e2e/framework/pod/delete.go +++ b/test/e2e/framework/pod/delete.go @@ -69,3 +69,31 @@ func DeletePodWithWaitByName(c clientset.Interface, podName, podNamespace string } return nil } + +// DeletePodWithGracePeriod deletes the passed-in pod. Resilient to the pod not existing. +func DeletePodWithGracePeriod(c clientset.Interface, pod *v1.Pod, grace int64) error { + return DeletePodWithGracePeriodByName(c, pod.GetName(), pod.GetNamespace(), grace) +} + +// DeletePodsWithGracePeriod deletes the passed-in pods. Resilient to the pods not existing. +func DeletePodsWithGracePeriod(c clientset.Interface, pods []v1.Pod, grace int64) error { + for _, pod := range pods { + if err := DeletePodWithGracePeriod(c, &pod, grace); err != nil { + return err + } + } + return nil +} + +// DeletePodWithGracePeriodByName deletes a pod by name and namespace. Resilient to the pod not existing. +func DeletePodWithGracePeriodByName(c clientset.Interface, podName, podNamespace string, grace int64) error { + e2elog.Logf("Deleting pod %q in namespace %q", podName, podNamespace) + err := c.CoreV1().Pods(podNamespace).Delete(context.TODO(), podName, *metav1.NewDeleteOptions(grace)) + if err != nil { + if apierrors.IsNotFound(err) { + return nil // assume pod was already deleted + } + return fmt.Errorf("pod Delete API error: %v", err) + } + return nil +}