diff --git a/e2e/attachedcluster_test.go b/e2e/attachedcluster_test.go index 34606591..b29e3262 100644 --- a/e2e/attachedcluster_test.go +++ b/e2e/attachedcluster_test.go @@ -43,7 +43,7 @@ var _ = ginkgo.Describe("[AttachedClusters] AttachedClusters testing", func() { ) ginkgo.BeforeEach(func() { - namespace = "e2e-test" + namespace = resources.RandomNamespace(5) fleetname = "e2etest" memberClusterName = "kurator-member" homeDir, err := os.UserHomeDir() diff --git a/e2e/resources/namespace.go b/e2e/resources/namespace.go index ff614f84..429fc7ce 100644 --- a/e2e/resources/namespace.go +++ b/e2e/resources/namespace.go @@ -18,6 +18,8 @@ package resources import ( "context" + "math/rand" + "strings" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -25,6 +27,8 @@ import ( "k8s.io/client-go/kubernetes" ) +const chartSet = "abcdefghijklmnopqrstuvwxyz" + // NewNamespace will build a Namespace object. func NewNamespace(namespace string) *corev1.Namespace { return &corev1.Namespace{ @@ -57,3 +61,12 @@ func RemoveNamespace(client kubernetes.Interface, name string) error { } return nil } + +func RandomNamespace(nameLength int) string { + randomNS := strings.Builder{} + randomNS.Grow(nameLength) + for i := 0; i < nameLength; i++ { + randomNS.WriteByte(chartSet[rand.Intn(len(chartSet))]) + } + return randomNS.String() +}