Skip to content

Commit

Permalink
add function about create random namespace
Browse files Browse the repository at this point in the history
Signed-off-by: LiZhenCheng9527 <[email protected]>
  • Loading branch information
LiZhenCheng9527 committed Feb 5, 2024
1 parent fbb0ef7 commit e1add05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion e2e/attachedcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions e2e/resources/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ package resources

import (
"context"
"math/rand"
"strings"

corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)

const chartSet = "abcdefghijklmnopqrstuvwxyz"

// NewNamespace will build a Namespace object.
func NewNamespace(namespace string) *corev1.Namespace {
return &corev1.Namespace{
Expand Down Expand Up @@ -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()
}

0 comments on commit e1add05

Please sign in to comment.