From a9e3689e63956bc7fe2715cff7d16119351f5308 Mon Sep 17 00:00:00 2001 From: Swati Sehgal Date: Mon, 24 Oct 2022 16:57:30 +0100 Subject: [PATCH] node: e2e: ensure clean cluster state before e2e tests are run Signed-off-by: Swati Sehgal --- test/e2e_node/device_plugin_test.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/e2e_node/device_plugin_test.go b/test/e2e_node/device_plugin_test.go index 242d665f82b..deedc654a66 100644 --- a/test/e2e_node/device_plugin_test.go +++ b/test/e2e_node/device_plugin_test.go @@ -94,7 +94,9 @@ func testDevicePlugin(f *framework.Framework, pluginSockDir string) { // and then use the same here devsLen := int64(2) var devicePluginPod, dptemplate *v1.Pod - + var v1alphaPodResources *kubeletpodresourcesv1alpha1.ListPodResourcesResponse + var v1PodResources *kubeletpodresourcesv1.ListPodResourcesResponse + var err error ginkgo.BeforeEach(func() { ginkgo.By("Wait for node to be ready") gomega.Eventually(func() bool { @@ -103,6 +105,18 @@ func testDevicePlugin(f *framework.Framework, pluginSockDir string) { return nodes == 1 }, time.Minute, time.Second).Should(gomega.BeTrue()) + v1alphaPodResources, err = getV1alpha1NodeDevices() + framework.ExpectNoError(err) + + v1PodResources, err = getV1NodeDevices() + framework.ExpectNoError(err) + + // Before we run the device plugin test, we need to ensure + // that the cluster is in a clean state and there are no + // pods running on this node. + framework.ExpectEqual(len(v1alphaPodResources.PodResources), 0) + framework.ExpectEqual(len(v1PodResources.PodResources), 0) + ginkgo.By("Scheduling a sample device plugin pod") data, err := e2etestfiles.Read(SampleDevicePluginDSYAML) if err != nil { @@ -175,10 +189,10 @@ func testDevicePlugin(f *framework.Framework, pluginSockDir string) { devID1 := parseLog(f, pod1.Name, pod1.Name, deviceIDRE) gomega.Expect(devID1).To(gomega.Not(gomega.Equal(""))) - v1alphaPodResources, err := getV1alpha1NodeDevices() + v1alphaPodResources, err = getV1alpha1NodeDevices() framework.ExpectNoError(err) - v1PodResources, err := getV1NodeDevices() + v1PodResources, err = getV1NodeDevices() framework.ExpectNoError(err) framework.Logf("v1alphaPodResources.PodResources:%+v\n", v1alphaPodResources.PodResources)