From aa1a0385e27df4e0a9dc1d8ae2aa9d5145504ef6 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Wed, 22 Feb 2023 13:45:33 +0100 Subject: [PATCH] e2e: node: podresources: internal cleanup rename getPodResources for clarity. Allow to return error (and not use ginkgo expectations), so it can actually be used as intended inside `Eventually` blocks without blow up at the first failure. Signed-off-by: Francesco Romani --- test/e2e_node/podresources_test.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/test/e2e_node/podresources_test.go b/test/e2e_node/podresources_test.go index 0625995dcad..70bbeac2c17 100644 --- a/test/e2e_node/podresources_test.go +++ b/test/e2e_node/podresources_test.go @@ -136,9 +136,11 @@ func logPodResources(podIdx int, pr *kubeletpodresourcesv1.PodResources) { type podResMap map[string]map[string]kubeletpodresourcesv1.ContainerResources -func getPodResources(ctx context.Context, cli kubeletpodresourcesv1.PodResourcesListerClient) podResMap { +func getPodResourcesValues(ctx context.Context, cli kubeletpodresourcesv1.PodResourcesListerClient) (podResMap, error) { resp, err := cli.List(ctx, &kubeletpodresourcesv1.ListPodResourcesRequest{}) - framework.ExpectNoError(err) + if err != nil { + return nil, err + } res := make(map[string]map[string]kubeletpodresourcesv1.ContainerResources) for idx, podResource := range resp.GetPodResources() { @@ -151,7 +153,7 @@ func getPodResources(ctx context.Context, cli kubeletpodresourcesv1.PodResources } res[podResource.GetName()] = cnts } - return res + return res, nil } type testPodData struct { @@ -252,7 +254,10 @@ func matchPodDescWithResources(expected []podDesc, found podResMap) error { func expectPodResources(ctx context.Context, offset int, cli kubeletpodresourcesv1.PodResourcesListerClient, expected []podDesc) { gomega.EventuallyWithOffset(1+offset, ctx, func(ctx context.Context) error { - found := getPodResources(ctx, cli) + found, err := getPodResourcesValues(ctx, cli) + if err != nil { + return err + } return matchPodDescWithResources(expected, found) }, time.Minute, 10*time.Second).Should(gomega.Succeed()) } @@ -280,8 +285,10 @@ func podresourcesListTests(ctx context.Context, f *framework.Framework, cli kube expectedBasePods = 1 // sriovdp } + var err error ginkgo.By("checking the output when no pods are present") - found = getPodResources(ctx, cli) + found, err = getPodResourcesValues(ctx, cli) + framework.ExpectNoError(err) gomega.ExpectWithOffset(1, found).To(gomega.HaveLen(expectedBasePods), "base pod expectation mismatch") tpd = newTestPodData()