Added pod deletion utility methods and added code to delete remaining pods in some e2e tests to try to prevent exceeding node capacity

This commit is contained in:
Brian Pursley 2020-05-15 21:21:37 -04:00
parent 71277de4d6
commit 20642720c6
2 changed files with 38 additions and 0 deletions

View File

@ -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

View File

@ -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
}