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
2 changed files with 17 additions and 0 deletions

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.