Skip to content

Commit

Permalink
Merge pull request #649 from ArangoGutierrez/fix_642
Browse files Browse the repository at this point in the history
E2E test: Ommit error ifNotFound during NFD cleanup
  • Loading branch information
elezar authored Apr 16, 2024
2 parents 6d9218f + e992e2a commit 83e141e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
49 changes: 37 additions & 12 deletions tests/e2e/common/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1"
Expand Down Expand Up @@ -164,26 +165,50 @@ func CleanupNode(ctx context.Context, cs clientset.Interface) {
}
}

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

// 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.
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
}
Expect(err).NotTo(HaveOccurred())
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/gpu-feature-discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
// Delete Helm release
err := helmClient.UninstallReleaseByName(helmReleaseName)
Expect(err).NotTo(HaveOccurred())
// cleanup node
// Cleanup node
common.CleanupNode(ctx, f.ClientSet)
common.CleanupNodeFeatureRules(ctx, nfdClient, f.Namespace.Name)
common.CleanupNFDObjects(ctx, nfdClient, f.Namespace.Name)
})

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

0 comments on commit 83e141e

Please sign in to comment.