-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Workload e2e #235
test: Workload e2e #235
Changes from 16 commits
b8d225c
d52ab19
f322f25
312d038
1c3212c
c10925f
1afb291
c9d50b4
5dda0cf
a0ee701
2ee2bb6
54cad6e
44f4ed8
5b9e598
b6707d5
a0f779d
fdaab1e
4a9cd2c
6946671
6e0a6bb
9d70cb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,98 +5,87 @@ Licensed under the MIT license. | |
package e2e | ||
|
||
import ( | ||
"context" | ||
Arvindthiru marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"golang.org/x/net/context" | ||
"go.goms.io/fleet/pkg/utils" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be with the local group There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
corev1 "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"go.goms.io/fleet/apis/v1alpha1" | ||
"go.goms.io/fleet/pkg/utils" | ||
"go.goms.io/fleet/test/e2e/framework" | ||
) | ||
|
||
var _ = Describe("Join/leave member cluster testing", func() { | ||
var mc *v1alpha1.MemberCluster | ||
var sa *corev1.ServiceAccount | ||
var memberIdentity rbacv1.Subject | ||
var memberNS *corev1.Namespace | ||
var imc *v1alpha1.InternalMemberCluster | ||
|
||
memberNS = NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName)) | ||
|
||
Context("member clusters don't share member identity", func() { | ||
BeforeEach(func() { | ||
memberIdentity = rbacv1.Subject{ | ||
Name: MemberCluster.ClusterName, | ||
Kind: "ServiceAccount", | ||
Namespace: "fleet-system", | ||
} | ||
memberNS = NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName)) | ||
By("prepare resources in member cluster") | ||
// create testing NS in member cluster | ||
framework.CreateNamespace(*MemberCluster, memberNS) | ||
framework.WaitNamespace(*MemberCluster, memberNS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider group them together? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
sa = NewServiceAccount(MemberCluster.ClusterName, memberNS.Name) | ||
framework.CreateServiceAccount(*MemberCluster, sa) | ||
|
||
By("deploy member cluster in the hub cluster") | ||
mc = NewMemberCluster(MemberCluster.ClusterName, 60, v1alpha1.ClusterStateJoin) | ||
framework.CreateMemberCluster(*HubCluster, mc) | ||
framework.WaitMemberCluster(*HubCluster, mc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
By("check if member cluster is marked as readyToJoin") | ||
framework.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterReadyToJoin, v1.ConditionTrue, 3*framework.PollTimeout) | ||
|
||
By("check if internal member cluster created in the hub cluster") | ||
imc = NewInternalMemberCluster(MemberCluster.ClusterName, memberNS.Name) | ||
framework.WaitInternalMemberCluster(*HubCluster, imc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't the order be reversed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FIxed |
||
}) | ||
|
||
It("Join flow is successful ", func() { | ||
By("Prepare resources in member cluster", func() { | ||
// create testing NS in member cluster | ||
framework.CreateNamespace(*MemberCluster, memberNS) | ||
framework.WaitNamespace(*MemberCluster, memberNS) | ||
|
||
sa = NewServiceAccount(memberIdentity.Name, memberNS.Name) | ||
framework.CreateServiceAccount(*MemberCluster, sa) | ||
}) | ||
|
||
By("deploy memberCluster in the hub cluster", func() { | ||
mc = NewMemberCluster(MemberCluster.ClusterName, 60, memberIdentity, v1alpha1.ClusterStateJoin) | ||
|
||
framework.CreateMemberCluster(*HubCluster, mc) | ||
framework.WaitMemberCluster(*HubCluster, mc) | ||
|
||
By("check if memberCluster is marked as readyToJoin") | ||
framework.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterReadyToJoin, v1.ConditionTrue, 3*framework.PollTimeout) | ||
|
||
By("check if internalmembercluster created in the hub cluster", func() { | ||
imc = NewInternalMemberCluster(MemberCluster.ClusterName, memberNS.Name) | ||
framework.WaitInternalMemberCluster(*HubCluster, imc) | ||
}) | ||
}) | ||
|
||
By("check if membercluster condition is updated to Joined", func() { | ||
framework.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoin, v1.ConditionTrue, 3*framework.PollTimeout) | ||
}) | ||
|
||
By("check if internalMemberCluster condition is updated to Joined", func() { | ||
framework.WaitConditionInternalMemberCluster(*HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionTrue, 3*framework.PollTimeout) | ||
}) | ||
By("check if internal member cluster condition is updated to Joined") | ||
framework.WaitConditionInternalMemberCluster(*HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionTrue, 3*framework.PollTimeout) | ||
|
||
By("check if member cluster condition is updated to Joined") | ||
framework.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoin, v1.ConditionTrue, 3*framework.PollTimeout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at this point, this IT has only 2 things, why not either fold it into beforeEach or merge with the leave test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
}) | ||
|
||
It("leave flow is successful ", func() { | ||
By("check if member cluster condition is updated to Joined") | ||
framework.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoin, v1.ConditionTrue, 3*framework.PollTimeout) | ||
|
||
By("update membercluster in the hub cluster", func() { | ||
framework.UpdateMemberClusterState(*HubCluster, mc, v1alpha1.ClusterStateLeave) | ||
framework.WaitMemberCluster(*HubCluster, mc) | ||
}) | ||
By("update member cluster in the hub cluster") | ||
framework.UpdateMemberClusterState(*HubCluster, mc, v1alpha1.ClusterStateLeave) | ||
framework.WaitMemberCluster(*HubCluster, mc) | ||
|
||
By("check if internalMemberCluster condition is updated to Left", func() { | ||
framework.WaitConditionInternalMemberCluster(*HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionFalse, 3*framework.PollTimeout) | ||
}) | ||
By("check if internal member cluster condition is updated to Left") | ||
framework.WaitConditionInternalMemberCluster(*HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionFalse, 3*framework.PollTimeout) | ||
|
||
By("check if memberCluster is marked as notReadyToJoin") | ||
By("check if member cluster is marked as notReadyToJoin") | ||
framework.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterReadyToJoin, v1.ConditionFalse, 3*framework.PollTimeout) | ||
|
||
By("check if membercluster condition is updated to Left") | ||
By("check if member cluster condition is updated to Left") | ||
framework.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoin, v1.ConditionFalse, 3*framework.PollTimeout) | ||
}) | ||
|
||
By("member namespace is deleted from hub cluster", func() { | ||
framework.DeleteMemberCluster(*HubCluster, mc) | ||
Eventually(func() bool { | ||
err := HubCluster.KubeClient.Get(context.TODO(), types.NamespacedName{Name: memberNS.Name, Namespace: ""}, memberNS) | ||
return apierrors.IsNotFound(err) | ||
}, framework.PollTimeout, framework.PollInterval).Should(Equal(true)) | ||
}) | ||
AfterEach(func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. normally, by convention, the AfterEach is put in the front. It's like defer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved it below BeforeEach |
||
framework.DeleteNamespace(*MemberCluster, memberNS) | ||
Eventually(func() bool { | ||
err := MemberCluster.KubeClient.Get(context.TODO(), types.NamespacedName{Name: memberNS.Name, Namespace: ""}, memberNS) | ||
return apierrors.IsNotFound(err) | ||
}, framework.PollTimeout, framework.PollInterval).Should(Equal(true)) | ||
framework.DeleteMemberCluster(*HubCluster, mc) | ||
Eventually(func() bool { | ||
err := HubCluster.KubeClient.Get(context.TODO(), types.NamespacedName{Name: memberNS.Name, Namespace: ""}, memberNS) | ||
return apierrors.IsNotFound(err) | ||
}, framework.PollTimeout, framework.PollInterval).Should(Equal(true)) | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package e2e | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
corev1 "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"go.goms.io/fleet/apis/v1alpha1" | ||
"go.goms.io/fleet/pkg/utils" | ||
"go.goms.io/fleet/test/e2e/framework" | ||
) | ||
|
||
var _ = Describe("workload orchestration testing", func() { | ||
var mc *v1alpha1.MemberCluster | ||
var sa *corev1.ServiceAccount | ||
var memberNS *corev1.Namespace | ||
var imc *v1alpha1.InternalMemberCluster | ||
var cr *rbacv1.ClusterRole | ||
var crp *v1alpha1.ClusterResourcePlacement | ||
|
||
BeforeEach(func() { | ||
memberNS = NewNamespace(fmt.Sprintf(utils.NamespaceNameFormat, MemberCluster.ClusterName)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be setup here because once we create namespace resource version gets added, this resets it once we delete between tests. |
||
By("prepare resources in member cluster") | ||
// create testing NS in member cluster | ||
framework.CreateNamespace(*MemberCluster, memberNS) | ||
framework.WaitNamespace(*MemberCluster, memberNS) | ||
sa = NewServiceAccount(MemberCluster.ClusterName, memberNS.Name) | ||
framework.CreateServiceAccount(*MemberCluster, sa) | ||
|
||
By("deploy member cluster in the hub cluster") | ||
mc = NewMemberCluster(MemberCluster.ClusterName, 60, v1alpha1.ClusterStateJoin) | ||
framework.CreateMemberCluster(*HubCluster, mc) | ||
framework.WaitMemberCluster(*HubCluster, mc) | ||
|
||
By("check if internal member cluster created in the hub cluster") | ||
imc = NewInternalMemberCluster(MemberCluster.ClusterName, memberNS.Name) | ||
framework.WaitInternalMemberCluster(*HubCluster, imc) | ||
|
||
By("check if internal member cluster condition is updated to Joined") | ||
framework.WaitConditionInternalMemberCluster(*HubCluster, imc, v1alpha1.AgentJoined, v1.ConditionTrue, 3*framework.PollTimeout) | ||
By("check if member cluster condition is updated to Joined") | ||
framework.WaitConditionMemberCluster(*HubCluster, mc, v1alpha1.ConditionTypeMemberClusterJoin, v1.ConditionTrue, 3*framework.PollTimeout) | ||
}) | ||
|
||
It("Apply CRP and check if work gets propagated", func() { | ||
workName := fmt.Sprintf(utils.WorkNameFormat, "resource-label-selector") | ||
By("create the resources to be propagated") | ||
cr = &rbacv1.ClusterRole{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
Name: "test-cluster-role", | ||
Labels: map[string]string{"fleet.azure.com/name": "test"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this label should be extract as a var as it's used by the CRP There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added labelKey and labelValue vars |
||
}, | ||
Rules: []rbacv1.PolicyRule{ | ||
{ | ||
Verbs: []string{"get", "list", "watch"}, | ||
APIGroups: []string{""}, | ||
Resources: []string{"secrets"}, | ||
}, | ||
}, | ||
} | ||
framework.CreateClusterRole(*HubCluster, cr) | ||
|
||
By("create the cluster resource placement in the hub cluster") | ||
crp = &v1alpha1.ClusterResourcePlacement{ | ||
ObjectMeta: v1.ObjectMeta{Name: "resource-label-selector"}, | ||
Spec: v1alpha1.ClusterResourcePlacementSpec{ | ||
ResourceSelectors: []v1alpha1.ClusterResourceSelector{ | ||
{ | ||
Group: "rbac.authorization.k8s.io", | ||
Version: "v1", | ||
Kind: "ClusterRole", | ||
LabelSelector: &v1.LabelSelector{ | ||
MatchLabels: map[string]string{"fleet.azure.com/name": "test"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
framework.CreateClusterResourcePlacement(*HubCluster, crp) | ||
framework.WaitClusterResourcePlacement(*HubCluster, crp) | ||
|
||
By("check if work gets created for cluster resource placement") | ||
framework.WaitWork(*HubCluster, workName, memberNS.Name) | ||
|
||
By("check if cluster resource placement is updated to Scheduled & Applied") | ||
framework.WaitConditionClusterResourcePlacement(*HubCluster, crp, string(v1alpha1.ResourcePlacementConditionTypeScheduled), v1.ConditionTrue, 3*framework.PollTimeout) | ||
framework.WaitConditionClusterResourcePlacement(*HubCluster, crp, string(v1alpha1.ResourcePlacementStatusConditionTypeApplied), v1.ConditionTrue, 3*framework.PollTimeout) | ||
|
||
By("check if resource is propagated to member cluster") | ||
framework.WaitClusterRole(*MemberCluster, cr) | ||
ryanzhang-oss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
By("delete cluster resource placement & cluster role on hub cluster") | ||
ryanzhang-oss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
framework.DeleteClusterResourcePlacement(*HubCluster, crp) | ||
Eventually(func() bool { | ||
err := HubCluster.KubeClient.Get(context.TODO(), types.NamespacedName{Name: crp.Name, Namespace: ""}, crp) | ||
return apierrors.IsNotFound(err) | ||
}, framework.PollTimeout, framework.PollInterval).Should(Equal(true)) | ||
framework.DeleteClusterRole(*HubCluster, cr) | ||
}) | ||
|
||
AfterEach(func() { | ||
framework.DeleteMemberCluster(*HubCluster, mc) | ||
ryanzhang-oss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Eventually(func() bool { | ||
err := HubCluster.KubeClient.Get(context.TODO(), types.NamespacedName{Name: memberNS.Name, Namespace: ""}, memberNS) | ||
return apierrors.IsNotFound(err) | ||
}, framework.PollTimeout, framework.PollInterval).Should(Equal(true)) | ||
ryanzhang-oss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
framework.DeleteNamespace(*MemberCluster, memberNS) | ||
Eventually(func() bool { | ||
err := MemberCluster.KubeClient.Get(context.TODO(), types.NamespacedName{Name: memberNS.Name, Namespace: ""}, memberNS) | ||
return apierrors.IsNotFound(err) | ||
}, framework.PollTimeout, framework.PollInterval).Should(Equal(true)) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is clusterRole part of the common file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to test/e2e/utils/helper.go