Skip to content

Commit

Permalink
Refactor workload orchestration E2E
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvindthiru committed Sep 14, 2022
1 parent c64bc1e commit 8d4f85b
Show file tree
Hide file tree
Showing 5 changed files with 384 additions and 187 deletions.
15 changes: 9 additions & 6 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Licensed under the MIT license.
package e2e

import (
"context"
"embed"
"fmt"
"os"
Expand Down Expand Up @@ -32,12 +33,13 @@ var (
MemberCluster = framework.NewCluster(memberClusterName, scheme)
hubURL string
scheme = runtime.NewScheme()
ctx context.Context

// This namespace will store Member cluster-related CRs, such as v1alpha1.MemberCluster
memberNamespace = testutils.NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName))
memberNamespace = testutils.NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName), nil)

// This namespace in HubCluster will store v1alpha1.Work to simulate Work-related features in Hub Cluster.
workNamespace = testutils.NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName))
workNamespace = testutils.NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName), nil)

// Used to decode an unstructured object.
genericCodecs = serializer.NewCodecFactory(scheme)
Expand All @@ -60,6 +62,7 @@ func TestE2E(t *testing.T) {
}

var _ = BeforeSuite(func() {
ctx = context.Background()
kubeconfig := os.Getenv("KUBECONFIG")
Expect(kubeconfig).ShouldNot(BeEmpty(), "Failure to retrieve kubeconfig")

Expand All @@ -74,13 +77,13 @@ var _ = BeforeSuite(func() {
MemberCluster.HubURL = hubURL
framework.GetClusterClient(MemberCluster)

testutils.CreateNamespace(*MemberCluster, memberNamespace)
testutils.CreateNamespace(ctx, *MemberCluster, memberNamespace)

testutils.CreateNamespace(*HubCluster, workNamespace)
testutils.CreateNamespace(ctx, *HubCluster, workNamespace)
})

var _ = AfterSuite(func() {
testutils.DeleteNamespace(*MemberCluster, memberNamespace)
testutils.DeleteNamespace(ctx, *MemberCluster, memberNamespace)

testutils.DeleteNamespace(*HubCluster, workNamespace)
testutils.DeleteNamespace(ctx, *HubCluster, workNamespace)
})
28 changes: 11 additions & 17 deletions test/e2e/join_leave_member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,53 @@ import (
"context"

. "github.com/onsi/ginkgo/v2"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"go.goms.io/fleet/apis/v1alpha1"
testutils "go.goms.io/fleet/test/e2e/utils"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var _ = Describe("Join/leave member cluster testing", func() {
var mc *v1alpha1.MemberCluster
var sa *corev1.ServiceAccount
var imc *v1alpha1.InternalMemberCluster
var ctx context.Context

BeforeEach(func() {
ctx = context.Background()

sa = testutils.NewServiceAccount(MemberCluster.ClusterName, memberNamespace.Name)
testutils.CreateServiceAccount(*MemberCluster, sa)

By("deploy member cluster in the hub cluster")
mc = testutils.NewMemberCluster(MemberCluster.ClusterName, 60, v1alpha1.ClusterStateJoin)
testutils.CreateMemberCluster(*HubCluster, mc)
testutils.CreateMemberCluster(ctx, *HubCluster, mc)

By("check if internal member cluster created in the hub cluster")
imc = testutils.NewInternalMemberCluster(MemberCluster.ClusterName, memberNamespace.Name)
testutils.WaitInternalMemberCluster(*HubCluster, imc)
testutils.WaitInternalMemberCluster(ctx, *HubCluster, imc)

By("check if member cluster is marked as readyToJoin")
testutils.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterReadyToJoin, v1.ConditionTrue, 3*testutils.PollTimeout)
testutils.WaitConditionMemberCluster(ctx, *HubCluster, mc, v1alpha1.ConditionTypeMemberClusterReadyToJoin, v1.ConditionTrue, 3*testutils.PollTimeout)
})

AfterEach(func() {
testutils.DeleteMemberCluster(ctx, *HubCluster, mc)
testutils.DeleteServiceAccount(*MemberCluster, sa)

})

It("Join & Leave flow is successful ", func() {
By("check if internal member cluster condition is updated to Joined")
testutils.WaitConditionInternalMemberCluster(*HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionTrue, 3*testutils.PollTimeout)
testutils.WaitConditionInternalMemberCluster(ctx, *HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionTrue, 3*testutils.PollTimeout)

By("check if member cluster condition is updated to Joined")
testutils.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoined, v1.ConditionTrue, 3*testutils.PollTimeout)
testutils.WaitConditionMemberCluster(ctx, *HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoined, v1.ConditionTrue, 3*testutils.PollTimeout)

By("update member cluster in the hub cluster")
testutils.UpdateMemberClusterState(*HubCluster, mc, v1alpha1.ClusterStateLeave)
testutils.UpdateMemberClusterState(ctx, *HubCluster, mc, v1alpha1.ClusterStateLeave)

By("check if internal member cluster condition is updated to Left")
testutils.WaitConditionInternalMemberCluster(*HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionFalse, 3*testutils.PollTimeout)
testutils.WaitConditionInternalMemberCluster(ctx, *HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionFalse, 3*testutils.PollTimeout)

By("check if member cluster is marked as notReadyToJoin")
testutils.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterReadyToJoin, v1.ConditionFalse, 3*testutils.PollTimeout)
testutils.WaitConditionMemberCluster(ctx, *HubCluster, mc, v1alpha1.ConditionTypeMemberClusterReadyToJoin, v1.ConditionFalse, 3*testutils.PollTimeout)

By("check if member cluster condition is updated to Left")
testutils.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoined, v1.ConditionFalse, 3*testutils.PollTimeout)
testutils.WaitConditionMemberCluster(ctx, *HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoined, v1.ConditionFalse, 3*testutils.PollTimeout)
})
})
Loading

0 comments on commit 8d4f85b

Please sign in to comment.