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) -}