Cleanup pods at the end in Pod conditions e2e node test

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
Davanum Srinivas 2023-06-27 09:36:00 -04:00
parent 16fe4a4cce
commit 6c587b43e9
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59
2 changed files with 17 additions and 0 deletions

View File

@ -57,6 +57,7 @@ var _ = SIGDescribe("Pod conditions managed by Kubelet", func() {
ginkgo.It("a pod with init containers should report all conditions set in expected order after the pod is up", runPodReadyConditionsTest(f, true, true))
ginkgo.It("a pod failing to mount volumes and without init containers should report scheduled and initialized conditions set", runPodFailingConditionsTest(f, false, true))
ginkgo.It("a pod failing to mount volumes and with init containers should report just the scheduled condition set", runPodFailingConditionsTest(f, true, true))
cleanupPods(f)
})
ginkgo.Context("without PodReadyToStartContainersCondition condition", func() {
@ -64,6 +65,7 @@ var _ = SIGDescribe("Pod conditions managed by Kubelet", func() {
ginkgo.It("a pod with init containers should report all conditions set in expected order after the pod is up", runPodReadyConditionsTest(f, true, false))
ginkgo.It("a pod failing to mount volumes and without init containers should report scheduled and initialized conditions set", runPodFailingConditionsTest(f, false, false))
ginkgo.It("a pod failing to mount volumes and with init containers should report just the scheduled condition set", runPodFailingConditionsTest(f, true, false))
cleanupPods(f)
})
})

View File

@ -170,6 +170,21 @@ func getCurrentKubeletConfig(ctx context.Context) (*kubeletconfig.KubeletConfigu
return e2enodekubelet.GetCurrentKubeletConfig(ctx, framework.TestContext.NodeName, "", false, framework.TestContext.StandaloneMode)
}
func cleanupPods(f *framework.Framework) {
ginkgo.AfterEach(func(ctx context.Context) {
ginkgo.By("Deleting any Pods created by the test in namespace: " + f.Namespace.Name)
l, err := e2epod.NewPodClient(f).List(ctx, metav1.ListOptions{})
framework.ExpectNoError(err)
for _, p := range l.Items {
if p.Namespace != f.Namespace.Name {
continue
}
framework.Logf("Deleting pod: %s", p.Name)
e2epod.NewPodClient(f).DeleteSync(ctx, p.Name, metav1.DeleteOptions{}, 2*time.Minute)
}
})
}
// Must be called within a Context. Allows the function to modify the KubeletConfiguration during the BeforeEach of the context.
// The change is reverted in the AfterEach of the context.
// Returns true on success.