From 343a5db96583937ffef7750f5913f7ca94e29729 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 19 Sep 2025 18:47:21 +0200 Subject: [PATCH] DRA E2E node: fix cleanup of tests using separate registrar 8fed05c5b78ddc232819820c616d10f51d92b030 fixed the cleanup of tests which start registrar and service in a single call. But tests which first started the registrar and then the service separately still had the problem: - registrar is started with test context - pods remain running at end of test - registrar stops because of test context cancellation - pods remain pending despite deletion because the driver gets unregistered (timing dependent, so this may have flaked) The fix is to also clean up the registrar after the test, in reverse startup order. --- test/e2e_node/dra_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/e2e_node/dra_test.go b/test/e2e_node/dra_test.go index 9234558ef31..3b336f89d5f 100644 --- a/test/e2e_node/dra_test.go +++ b/test/e2e_node/dra_test.go @@ -1056,7 +1056,7 @@ func newRegistrar(ctx context.Context, clientSet kubernetes.Interface, nodeName, allOpts = append(allOpts, opts...) registrar, err := testdriver.StartPlugin( - ctx, + context.WithoutCancel(ctx), // It gets stopped during test cleanup or when requested earlier. cdiDir, driverName, clientSet, @@ -1065,6 +1065,7 @@ func newRegistrar(ctx context.Context, clientSet kubernetes.Interface, nodeName, allOpts..., ) framework.ExpectNoError(err, "start only Kubelet plugin registrar") + ginkgo.DeferCleanup(registrar.Stop) return registrar } @@ -1159,6 +1160,10 @@ func draServiceCleanup(ctx context.Context, clientSet kubernetes.Interface, driv ginkgo.By("Deleting pods and waiting for ResourceClaims to be released...") framework.ExpectNoError(clientSet.CoreV1().Pods(testNamespace).DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{})) + // Failing here is a bit more obvious than in the metric check below. + // The metrics get checked, too, because we want to be certain that those go down. + gomega.Eventually(ctx, framework.ListObjects(clientSet.CoreV1().Pods(testNamespace).List, metav1.ListOptions{})).Should(gomega.HaveField("Items", gomega.BeEmpty()), "All pods should be deleted, shut down and removed.") + // We allow for a delay because it takes a while till the kubelet fully deals with pod deletion. // Typically there is no dra_resource_claims_in_use entry for the driver (covered by gstruct.IgnoreMissing). // If there is one, it must be zero.