Skip to content

Commit

Permalink
E2E test: Create CleanupNFDObjects func
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
  • Loading branch information
ArangoGutierrez committed Apr 15, 2024
1 parent 9e312c3 commit 6b52d7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
33 changes: 20 additions & 13 deletions tests/e2e/common/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,18 @@ func CleanupNode(ctx context.Context, cs clientset.Interface) {
}
}

func CleanupNodeFeatures(ctx context.Context, cli *nfdclient.Clientset, namespace string) {
// Clean NodeFeatureRule objects
nfrs, err := cli.NfdV1alpha1().NodeFeatureRules().List(ctx, metav1.ListOptions{})
// 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())

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 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
Expand All @@ -186,18 +186,20 @@ func CleanupNodeFeatures(ctx context.Context, cli *nfdclient.Clientset, namespac
}
}
}
}

// Clean NodeFeature objects
nfs, err := cli.NfdV1alpha1().NodeFeatures(namespace).List(ctx, metav1.ListOptions{})
// cleanupNodeFeatureRules deletes all NodeFeatureRule objects
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())

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 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
Expand All @@ -208,3 +210,8 @@ func CleanupNodeFeatures(ctx context.Context, cli *nfdclient.Clientset, namespac
}
}
}

func CleanupNFDObjects(ctx context.Context, cli *nfdclient.Clientset, namespace string) {
cleanupNodeFeatureRules(ctx, cli)
cleanupNodeFeatures(ctx, cli, namespace)
}
2 changes: 1 addition & 1 deletion tests/e2e/gpu-feature-discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
Expect(err).NotTo(HaveOccurred())
// Cleanup node
common.CleanupNode(ctx, f.ClientSet)
common.CleanupNodeFeatures(ctx, nfdClient, f.Namespace.Name)
common.CleanupNFDObjects(ctx, nfdClient, f.Namespace.Name)
})

AfterAll(func(ctx context.Context) {
Expand Down

0 comments on commit 6b52d7b

Please sign in to comment.