Skip to content

Commit

Permalink
E2E test: fix object names
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 24, 2024
1 parent b4d56f1 commit 806a562
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 15 deletions.
4 changes: 2 additions & 2 deletions tests/e2e/device-plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = NVDescribe("GPU Device Plugin", func() {
"nodes",
"namespaces",
"deployments",
"demonsets",
"daemonsets",
"jobs",
}

Expand Down Expand Up @@ -148,7 +148,7 @@ var _ = NVDescribe("GPU Device Plugin", func() {
Expect(err).NotTo(HaveOccurred())

targetNodeName := nodes[0].Name
Expect(targetNodeName).ToNot(BeEmpty())
Expect(targetNodeName).ToNot(BeEmpty(), "No suitable worker node found")

By("Checking the node capacity")
capacityChecker := map[string]k8sLabels{
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package e2e

import "github.com/onsi/ginkgo/v2"
import (
"github.com/onsi/ginkgo/v2"
)

// NVDescribe annotates the test with the NVIDIA label.
func NVDescribe(text string, body func()) bool {
Expand Down
38 changes: 30 additions & 8 deletions tests/e2e/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ package framework

import (
"context"
"errors"
"fmt"
"log"
"math/rand"
"os"
"path/filepath"
"time"

helm "github.com/mittwald/go-helm-client"
Expand Down Expand Up @@ -146,6 +148,30 @@ func (f *Framework) BeforeEach(ctx context.Context) {
// not guaranteed to be unique, but very likely
f.UniqueName = fmt.Sprintf("%s-%08x", f.BaseName, rand.Int31())
}

// Create a Helm client
ginkgo.By("Creating a Helm client")

err = os.MkdirAll(filepath.Dir(TestContext.HelmLogFile), 0755)
gomega.Expect(err).To(gomega.BeNil())

f.HelmLogFile, err = os.OpenFile(TestContext.HelmLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
gomega.Expect(err).To(gomega.BeNil())

f.HelmLogger = log.New(f.HelmLogFile, fmt.Sprintf("%s\t", f.UniqueName), log.Ldate|log.Ltime)
helmRestConf := &helm.RestConfClientOptions{
Options: &helm.Options{
Namespace: f.Namespace.Name,
RepositoryCache: "/tmp/.helmcache",
RepositoryConfig: "/tmp/.helmrepo",
Debug: true,
DebugLog: f.HelmLogger.Printf,
},
RestConfig: config,
}

f.HelmClient, err = helm.NewClientFromRestConf(helmRestConf)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

// AfterEach deletes the namespace, after reading its events.
Expand All @@ -157,7 +183,7 @@ func (f *Framework) AfterEach(ctx context.Context) {
// DeleteNamespace at the very end in defer, to avoid any
// expectation failures preventing deleting the namespace.
defer func() {
nsDeletionErrors := []string{}
var nsDeletionErrors error
// Whether to delete namespace is determined by 3 factors: delete-namespace flag, delete-namespace-on-failure flag and the test result
// if delete-namespace set to false, namespace will always be preserved.
// if delete-namespace is true and delete-namespace-on-failure is false, namespace will be preserved if test failed.
Expand All @@ -166,7 +192,7 @@ func (f *Framework) AfterEach(ctx context.Context) {
ginkgo.By(fmt.Sprintf("[Cleanup]\tDeleting testing namespace %q.", ns.Name))
if err := f.ClientSet.CoreV1().Namespaces().Delete(ctx, ns.Name, metav1.DeleteOptions{}); err != nil {
if !apierrors.IsNotFound(err) {
nsDeletionErrors = append(nsDeletionErrors, ns.Name)
nsDeletionErrors = errors.Join(nsDeletionErrors, fmt.Errorf("error deleting %v: %w", ns.Name, err))
}
}
// remove the namespace from the list of namespaces to delete
Expand All @@ -183,9 +209,7 @@ func (f *Framework) AfterEach(ctx context.Context) {
f.ClientSet = nil

// if we had errors deleting, report them now.
if len(nsDeletionErrors) != 0 {
gomega.Expect(nsDeletionErrors).To(gomega.BeEmpty(), fmt.Sprintf("Error deleting namespaces: %v", nsDeletionErrors))
}
gomega.Expect(nsDeletionErrors).NotTo(gomega.HaveOccurred())
}()

// Close helm log file
Expand Down Expand Up @@ -227,9 +251,7 @@ func (f *Framework) DeleteNamespace(ctx context.Context, name string) {
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
err = WaitForNamespacesDeleted(ctx, f.ClientSet, []string{name}, DefaultNamespaceDeletionTimeout)
if err != nil {
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}
gomega.Expect(err).NotTo(gomega.HaveOccurred())
}()
}

Expand Down
3 changes: 0 additions & 3 deletions tests/e2e/framework/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -122,8 +121,6 @@ func CreateTestingNS(ctx context.Context, baseName string, c clientset.Interface
if apierrors.IsAlreadyExists(err) {
// regenerate on conflict
namespaceObj.Name = fmt.Sprintf("%v-%v", baseName, RandomSuffix())
} else {
gomega.Expect(err).NotTo(gomega.HaveOccurred(), "Failed to create namespace %s", namespaceObj.Name)
}
return false, nil
}
Expand Down
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 @@ -68,7 +68,7 @@ var _ = NVDescribe("GPU Feature Discovery", func() {
"namespaces",
"deployments",
"demonsets",
"nodefeatures",
"nodeFeature",
}

Context("When deploying GFD", Ordered, func() {
Expand Down

0 comments on commit 806a562

Please sign in to comment.