Skip to content

Commit

Permalink
resolve conflicts and add namespace prefix
Browse files Browse the repository at this point in the history
Signed-off-by: LiZhenCheng9527 <[email protected]>
  • Loading branch information
LiZhenCheng9527 committed Feb 6, 2024
1 parent 386cab0 commit db57331
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
21 changes: 15 additions & 6 deletions e2e/fleet_attachedcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package e2e

import (
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
Expand All @@ -27,11 +29,13 @@ import (

var _ = ginkgo.Describe("[AttachedClusters] AttachedClusters testing", func() {
var (
fleetname string
fleet *fleetv1a1.Fleet
fleetNamespace string
fleetname string
fleet *fleetv1a1.Fleet
)

ginkgo.BeforeEach(func() {
fleetNamespace = e2ePrefix + resources.RandomNamespace(4)
fleetname = "e2e"
// build fleet
clusters := []*corev1.ObjectReference{
Expand All @@ -40,11 +44,11 @@ var _ = ginkgo.Describe("[AttachedClusters] AttachedClusters testing", func() {
Kind: "AttachedCluster",
},
}
fleet = resources.NewFleet(namespace, fleetname, clusters)
fleet = resources.NewFleet(fleetNamespace, fleetname, clusters)
})

ginkgo.AfterEach(func() {
fleerRemoveErr := resources.RemoveFleet(kuratorClient, namespace, fleetname)
fleerRemoveErr := resources.RemoveFleet(kuratorClient, fleetNamespace, fleetname)
gomega.Expect(fleerRemoveErr).ShouldNot(gomega.HaveOccurred())

attachedclusterRemoveErr := resources.RemoveAttachedCluster(kuratorClient, namespace, memberClusterName)
Expand All @@ -53,15 +57,20 @@ var _ = ginkgo.Describe("[AttachedClusters] AttachedClusters testing", func() {
secretRemoveErr := resources.RemoveSecret(kubeClient, namespace, memberClusterName)
gomega.Expect(secretRemoveErr).ShouldNot(gomega.HaveOccurred())

namespaceRemoveErr := resources.RemoveNamespace(kubeClient, namespace)
namespaceRemoveErr := resources.RemoveNamespace(kubeClient, fleetNamespace)
gomega.Expect(namespaceRemoveErr).ShouldNot(gomega.HaveOccurred())
})

ginkgo.It("Create Fleet", func() {
// create a namespace for fleet e2e test
fleetNamespaceCfg := resources.NewNamespace(fleetNamespace)
createNSErr := resources.CreateNamespace(kubeClient, fleetNamespaceCfg)
gomega.Expect(createNSErr).ShouldNot(gomega.HaveOccurred())
time.Sleep(3 * time.Second)
// create fleet and checkout fleet status
fleetCreateErr := resources.CreateFleet(kuratorClient, fleet)
gomega.Expect(fleetCreateErr).ShouldNot(gomega.HaveOccurred())
resources.WaitFleetFitWith(kuratorClient, namespace, fleetname, func(fleet *fleetv1a1.Fleet) bool {
resources.WaitFleetFitWith(kuratorClient, fleetNamespace, fleetname, func(fleet *fleetv1a1.Fleet) bool {
return fleet.Status.Phase == fleetv1a1.ReadyPhase
})
})
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()
}
2 changes: 2 additions & 0 deletions e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (
kuratorContext string

namespace string
e2ePrefix string
memberClusterName string
kubeconfigPath string
secret *corev1.Secret
Expand Down Expand Up @@ -67,6 +68,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())

namespace = "e2e-test"
e2ePrefix = "e2e-"
memberClusterName = "kurator-member"
homeDir, err := os.UserHomeDir()
gomega.Expect(err).ShouldNot(gomega.HaveOccurred())
Expand Down

0 comments on commit db57331

Please sign in to comment.