From e992e2a8f44247b1eb131c7476414cd9fbdba343 Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Arango Gutierrez Date: Mon, 15 Apr 2024 18:36:19 +0200 Subject: [PATCH] E2E test: quickly return if no object found Signed-off-by: Carlos Eduardo Arango Gutierrez --- tests/e2e/common/kubernetes.go | 56 ++++++++++++++++------------------ 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/tests/e2e/common/kubernetes.go b/tests/e2e/common/kubernetes.go index 3a5594205..2631042d1 100644 --- a/tests/e2e/common/kubernetes.go +++ b/tests/e2e/common/kubernetes.go @@ -165,25 +165,29 @@ func CleanupNode(ctx context.Context, cs clientset.Interface) { } } +func CleanupNFDObjects(ctx context.Context, cli *nfdclient.Clientset, namespace string) { + cleanupNodeFeatureRules(ctx, cli) + cleanupNodeFeatures(ctx, cli, namespace) +} + // cleanupNodeFeatures deletes all NodeFeature objects in the given namespace func cleanupNodeFeatures(ctx context.Context, cli *nfdclient.Clientset, namespace string) { nfs, err := cli.NfdV1alpha1().NodeFeatures(namespace).List(ctx, metav1.ListOptions{}) if errors.IsNotFound(err) { // Omitted error, nothing to do. - } else { - Expect(err).NotTo(HaveOccurred()) + return + } + Expect(err).NotTo(HaveOccurred()) - if len(nfs.Items) != 0 { - By("Deleting NodeFeature objects from namespace " + namespace) - for _, nf := range nfs.Items { - err = cli.NfdV1alpha1().NodeFeatures(namespace).Delete(ctx, nf.Name, metav1.DeleteOptions{}) - if errors.IsNotFound(err) { - // Omitted error - continue - } else { - Expect(err).NotTo(HaveOccurred()) - } + if len(nfs.Items) != 0 { + By("Deleting NodeFeature objects from namespace " + namespace) + for _, nf := range nfs.Items { + err = cli.NfdV1alpha1().NodeFeatures(namespace).Delete(ctx, nf.Name, metav1.DeleteOptions{}) + if errors.IsNotFound(err) { + // Omitted error + continue } + Expect(err).NotTo(HaveOccurred()) } } } @@ -193,25 +197,19 @@ func cleanupNodeFeatureRules(ctx context.Context, cli *nfdclient.Clientset) { nfrs, err := cli.NfdV1alpha1().NodeFeatureRules().List(ctx, metav1.ListOptions{}) if errors.IsNotFound(err) { // Omitted error, nothing to do. - } else { - Expect(err).NotTo(HaveOccurred()) + return + } + Expect(err).NotTo(HaveOccurred()) - if len(nfrs.Items) != 0 { - By("Deleting NodeFeatureRule objects from the cluster") - for _, nfr := range nfrs.Items { - err = cli.NfdV1alpha1().NodeFeatureRules().Delete(ctx, nfr.Name, metav1.DeleteOptions{}) - if errors.IsNotFound(err) { - // Omitted error - continue - } else { - Expect(err).NotTo(HaveOccurred()) - } + if len(nfrs.Items) != 0 { + By("Deleting NodeFeatureRule objects from the cluster") + for _, nfr := range nfrs.Items { + err = cli.NfdV1alpha1().NodeFeatureRules().Delete(ctx, nfr.Name, metav1.DeleteOptions{}) + if errors.IsNotFound(err) { + // Omitted error + continue } + Expect(err).NotTo(HaveOccurred()) } } } - -func CleanupNFDObjects(ctx context.Context, cli *nfdclient.Clientset, namespace string) { - cleanupNodeFeatureRules(ctx, cli) - cleanupNodeFeatures(ctx, cli, namespace) -}