Skip to content

Commit

Permalink
E2E test: quickly return if no object found
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
  • Loading branch information
ArangoGutierrez committed Apr 16, 2024
1 parent 6b52d7b commit e992e2a
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions tests/e2e/common/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand All @@ -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)
}

0 comments on commit e992e2a

Please sign in to comment.