Skip to content

Commit 2064272

Browse files
committed
Added pod deletion utility methods and added code to delete remaining pods in some e2e tests to try to prevent exceeding node capacity
1 parent 71277de commit 2064272

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

test/e2e/apimachinery/garbage_collector.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242
"k8s.io/kubernetes/test/e2e/framework"
4343
e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics"
4444
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
45+
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
4546
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
4647

4748
"github.com/onsi/ginkgo"
@@ -443,6 +444,9 @@ var _ = SIGDescribe("Garbage collector", func() {
443444
framework.Failf("expect %d pods, got %d pods", e, a)
444445
}
445446
gatherMetrics(f)
447+
if err = e2epod.DeletePodsWithGracePeriod(clientSet, pods.Items, 0); err != nil {
448+
framework.Logf("WARNING: failed to delete pods: %v", err)
449+
}
446450
})
447451

448452
// deleteOptions.OrphanDependents is deprecated in 1.7 and preferred to use the PropagationPolicy.
@@ -489,6 +493,9 @@ var _ = SIGDescribe("Garbage collector", func() {
489493
framework.Failf("expect %d pods, got %d pods", e, a)
490494
}
491495
gatherMetrics(f)
496+
if err = e2epod.DeletePodsWithGracePeriod(clientSet, pods.Items, 0); err != nil {
497+
framework.Logf("WARNING: failed to delete pods: %v", err)
498+
}
492499
})
493500

494501
/*
@@ -827,6 +834,9 @@ var _ = SIGDescribe("Garbage collector", func() {
827834
}
828835
}
829836
gatherMetrics(f)
837+
if err = e2epod.DeletePodsWithGracePeriod(clientSet, pods.Items, 0); err != nil {
838+
framework.Logf("WARNING: failed to delete pods: %v", err)
839+
}
830840
})
831841

832842
// TODO: should be an integration test

test/e2e/framework/pod/delete.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,31 @@ func DeletePodWithWaitByName(c clientset.Interface, podName, podNamespace string
6969
}
7070
return nil
7171
}
72+
73+
// DeletePodWithGracePeriod deletes the passed-in pod. Resilient to the pod not existing.
74+
func DeletePodWithGracePeriod(c clientset.Interface, pod *v1.Pod, grace int64) error {
75+
return DeletePodWithGracePeriodByName(c, pod.GetName(), pod.GetNamespace(), grace)
76+
}
77+
78+
// DeletePodsWithGracePeriod deletes the passed-in pods. Resilient to the pods not existing.
79+
func DeletePodsWithGracePeriod(c clientset.Interface, pods []v1.Pod, grace int64) error {
80+
for _, pod := range pods {
81+
if err := DeletePodWithGracePeriod(c, &pod, grace); err != nil {
82+
return err
83+
}
84+
}
85+
return nil
86+
}
87+
88+
// DeletePodWithGracePeriodByName deletes a pod by name and namespace. Resilient to the pod not existing.
89+
func DeletePodWithGracePeriodByName(c clientset.Interface, podName, podNamespace string, grace int64) error {
90+
e2elog.Logf("Deleting pod %q in namespace %q", podName, podNamespace)
91+
err := c.CoreV1().Pods(podNamespace).Delete(context.TODO(), podName, *metav1.NewDeleteOptions(grace))
92+
if err != nil {
93+
if apierrors.IsNotFound(err) {
94+
return nil // assume pod was already deleted
95+
}
96+
return fmt.Errorf("pod Delete API error: %v", err)
97+
}
98+
return nil
99+
}

0 commit comments

Comments
 (0)