Skip to content

Commit

Permalink
Merge branch 'master' into RemoveUserSignUpApprovalAfterDeactivation
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrancisc authored Oct 11, 2023
2 parents 412ea16 + 713b901 commit 69c0537
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 68 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/codeready-toolchain/toolchain-e2e

require (
github.com/codeready-toolchain/api v0.0.0-20230918195153-739e8fb09a33
github.com/codeready-toolchain/toolchain-common v0.0.0-20231002120847-bf3a59c8351b
github.com/codeready-toolchain/toolchain-common v0.0.0-20231010071648-0735f55e8eb2
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.12.0
github.com/ghodss/yaml v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoC
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codeready-toolchain/api v0.0.0-20230918195153-739e8fb09a33 h1:hxXfcFq2JgFISVxrkISg8m9DZMzpcPWRjPspx3M3Sxo=
github.com/codeready-toolchain/api v0.0.0-20230918195153-739e8fb09a33/go.mod h1:nn3W6eKb9PFIVwSwZW7wDeLACMBOwAV+4kddGuN+ARM=
github.com/codeready-toolchain/toolchain-common v0.0.0-20231002120847-bf3a59c8351b h1:3nk69kWcILOiu6Ul9DZZTRmx4pItVit+9uOAmjrYCfM=
github.com/codeready-toolchain/toolchain-common v0.0.0-20231002120847-bf3a59c8351b/go.mod h1:o/JGPWZ/9rVh/np0tcaPRXnreZ+X743o0Gxp1eP62/w=
github.com/codeready-toolchain/toolchain-common v0.0.0-20231010071648-0735f55e8eb2 h1:uMrAMTACCipKMV5pOBauaRRsGahQOdNTQ/uo/pGTQvA=
github.com/codeready-toolchain/toolchain-common v0.0.0-20231010071648-0735f55e8eb2/go.mod h1:o/JGPWZ/9rVh/np0tcaPRXnreZ+X743o0Gxp1eP62/w=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down
13 changes: 6 additions & 7 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func TestE2EFlow(t *testing.T) {
TargetCluster(memberAwait).
EnsureMUR().
RequireConditions(wait.ConditionSet(wait.Default(), wait.ApprovedByAdmin())...).
DisableCleanup().
Execute(t).Resources()

extrajohnName := "extrajohn"
Expand Down Expand Up @@ -146,10 +145,10 @@ func TestE2EFlow(t *testing.T) {
VerifyResourcesProvisionedForSignup(t, awaitilities, targetedJohnSignup, "deactivate30", "base")
VerifyResourcesProvisionedForSignup(t, awaitilities, originalSubJohnSignup, "deactivate30", "base")

johnsmithMur, err := hostAwait.GetMasterUserRecord(johnsmithName)
johnsmithSpace, err := hostAwait.WaitForSpace(t, johnsmithName, wait.UntilSpaceHasAnyTargetClusterSet())
require.NoError(t, err)

targetedJohnMur, err := hostAwait.GetMasterUserRecord(targetedJohnName)
targetedJohnSpace, err := hostAwait.WaitForSpace(t, targetedJohnName, wait.UntilSpaceHasAnyTargetClusterSet())
require.NoError(t, err)

t.Run("try to break UserAccount", func(t *testing.T) {
Expand Down Expand Up @@ -272,8 +271,8 @@ func TestE2EFlow(t *testing.T) {
_, err := hostAwait.WaitForToolchainStatus(t, wait.UntilToolchainStatusHasConditions(
wait.ToolchainStatusReadyAndUnreadyNotificationNotCreated()...), wait.UntilToolchainStatusUpdatedAfter(time.Now()),
wait.UntilHasMurCount("external", originalMursPerDomainCount["external"]+9), // 5 multiple signups + johnSignup + johnExtraSignup + targetedJohnName + originalSubJohnSignup +
wait.UntilHasSpaceCount(johnsmithMur.Spec.UserAccounts[0].TargetCluster, originalMemberStatuses[johnsmithMur.Spec.UserAccounts[0].TargetCluster].SpaceCount+8),
wait.UntilHasSpaceCount(targetedJohnMur.Spec.UserAccounts[0].TargetCluster, originalMemberStatuses[targetedJohnMur.Spec.UserAccounts[0].TargetCluster].SpaceCount+1),
wait.UntilHasSpaceCount(johnsmithSpace.Spec.TargetCluster, originalMemberStatuses[johnsmithSpace.Spec.TargetCluster].SpaceCount+8),
wait.UntilHasSpaceCount(targetedJohnSpace.Spec.TargetCluster, originalMemberStatuses[targetedJohnSpace.Spec.TargetCluster].SpaceCount+1),
)
require.NoError(t, err)
})
Expand Down Expand Up @@ -494,8 +493,8 @@ func TestE2EFlow(t *testing.T) {
wait.UntilToolchainStatusHasConditions(wait.ToolchainStatusReadyAndUnreadyNotificationNotCreated()...),
wait.UntilToolchainStatusUpdatedAfter(time.Now()),
wait.UntilHasMurCount("external", originalMursPerDomainCount["external"]+8),
wait.UntilHasSpaceCount(johnsmithMur.Spec.UserAccounts[0].TargetCluster, originalMemberStatuses[johnsmithMur.Spec.UserAccounts[0].TargetCluster].SpaceCount+7),
wait.UntilHasSpaceCount(targetedJohnMur.Spec.UserAccounts[0].TargetCluster, originalMemberStatuses[targetedJohnMur.Spec.UserAccounts[0].TargetCluster].SpaceCount+1),
wait.UntilHasSpaceCount(johnsmithSpace.Spec.TargetCluster, originalMemberStatuses[johnsmithSpace.Spec.TargetCluster].SpaceCount+7),
wait.UntilHasSpaceCount(targetedJohnSpace.Spec.TargetCluster, originalMemberStatuses[targetedJohnSpace.Spec.TargetCluster].SpaceCount+1),
)
require.NoError(t, err)
})
Expand Down
121 changes: 121 additions & 0 deletions test/e2e/parallel/retarget_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package parallel

import (
"testing"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
. "github.com/codeready-toolchain/toolchain-e2e/testsupport"
. "github.com/codeready-toolchain/toolchain-e2e/testsupport/space"
"github.com/codeready-toolchain/toolchain-e2e/testsupport/spacebinding"
. "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait"

"github.com/stretchr/testify/require"
)

func TestRetargetUserByChangingSpaceTargetClusterWhenSpaceIsNotShared(t *testing.T) {
// given
t.Parallel()
awaitilities := WaitForDeployments(t)
hostAwait := awaitilities.Host()
member1Await := awaitilities.Member1()
member2Await := awaitilities.Member2()

userSignup, mur := NewSignupRequest(awaitilities).
ManuallyApprove().
TargetCluster(member1Await).
EnsureMUR().
RequireConditions(ConditionSet(Default(), ApprovedByAdmin())...).
Execute(t).Resources()

space, err := hostAwait.WaitForSpace(t, userSignup.Status.CompliantUsername,
UntilSpaceHasStatusTargetCluster(member1Await.ClusterName),
UntilSpaceHasAnyTierNameSet())
require.NoError(t, err)

// when
space, err = hostAwait.UpdateSpace(t, space.Name, func(s *toolchainv1alpha1.Space) {
s.Spec.TargetCluster = member2Await.ClusterName
})
require.NoError(t, err)

// then
// expect NSTemplateSet to be deleted on member-1 cluster
err = member1Await.WaitUntilNSTemplateSetDeleted(t, space.Name)
require.NoError(t, err)

// and provisioned on member-2
_, err = member2Await.WaitForNSTmplSet(t, space.Name)
require.NoError(t, err)
VerifyResourcesProvisionedForSpace(t, awaitilities, space.Name, UntilSpaceHasStatusTargetCluster(member2Await.ClusterName))
VerifyUserRelatedResources(t, awaitilities, userSignup, mur.Spec.TierName, ExpectUserAccountIn(member2Await))
}

func TestRetargetUserByChangingSpaceTargetClusterWhenSpaceIsShared(t *testing.T) {
// given
t.Parallel()
awaitilities := WaitForDeployments(t)
hostAwait := awaitilities.Host()
member1Await := awaitilities.Member1()
member2Await := awaitilities.Member2()

signupToShareWith1, murToShareWith1 := NewSignupRequest(awaitilities).
ManuallyApprove().
TargetCluster(member1Await).
WaitForMUR().
RequireConditions(ConditionSet(Default(), ApprovedByAdmin())...).
Execute(t).Resources()
signupToShareWith2, murToShareWith2 := NewSignupRequest(awaitilities).
ManuallyApprove().
TargetCluster(member2Await).
WaitForMUR().
RequireConditions(ConditionSet(Default(), ApprovedByAdmin())...).
Execute(t).Resources()

userSignup, ownerMur := NewSignupRequest(awaitilities).
ManuallyApprove().
TargetCluster(member1Await).
EnsureMUR().
RequireConditions(ConditionSet(Default(), ApprovedByAdmin())...).
Execute(t).Resources()

spaceToMove, err := hostAwait.WaitForSpace(t, userSignup.Status.CompliantUsername,
UntilSpaceHasStatusTargetCluster(member1Await.ClusterName),
UntilSpaceHasAnyTierNameSet())
require.NoError(t, err)

spacebinding.CreateSpaceBinding(t, hostAwait, murToShareWith1, spaceToMove, "admin")
spacebinding.CreateSpaceBinding(t, hostAwait, murToShareWith2, spaceToMove, "admin")

tier, err := hostAwait.WaitForNSTemplateTier(t, spaceToMove.Spec.TierName)
require.NoError(t, err)
_, err = member1Await.WaitForNSTmplSet(t, spaceToMove.Name,
UntilNSTemplateSetHasSpaceRoles(
SpaceRole(tier.Spec.SpaceRoles["admin"].TemplateRef, ownerMur.Name, murToShareWith1.Name, murToShareWith2.Name)))
require.NoError(t, err)

// when
spaceToMove, err = hostAwait.UpdateSpace(t, spaceToMove.Name, func(s *toolchainv1alpha1.Space) {
s.Spec.TargetCluster = member2Await.ClusterName
})
require.NoError(t, err)

// then
// expect NSTemplateSet to be deleted on member-1 cluster
err = member1Await.WaitUntilNSTemplateSetDeleted(t, spaceToMove.Name)
require.NoError(t, err)

// and provisioned with the set of usernames for admin role as before on member-2
_, err = member2Await.WaitForNSTmplSet(t, spaceToMove.Name,
UntilNSTemplateSetHasSpaceRoles(
SpaceRole(tier.Spec.SpaceRoles["admin"].TemplateRef, ownerMur.Name, murToShareWith1.Name, murToShareWith2.Name)))
require.NoError(t, err)
VerifyResourcesProvisionedForSpace(t, awaitilities, spaceToMove.Name, UntilSpaceHasStatusTargetCluster(member2Await.ClusterName))
VerifyUserRelatedResources(t, awaitilities, userSignup, ownerMur.Spec.TierName, ExpectUserAccountIn(member2Await))

// the move doesn't have any effect on the other signups and MURs
VerifyUserRelatedResources(t, awaitilities, signupToShareWith1, murToShareWith1.Spec.TierName, ExpectUserAccountIn(member1Await))
VerifyResourcesProvisionedForSpace(t, awaitilities, murToShareWith1.Name, UntilSpaceHasStatusTargetCluster(member1Await.ClusterName))

VerifyUserRelatedResources(t, awaitilities, signupToShareWith2, murToShareWith2.Spec.TierName, ExpectUserAccountIn(member2Await))
VerifyResourcesProvisionedForSpace(t, awaitilities, murToShareWith2.Name, UntilSpaceHasStatusTargetCluster(member2Await.ClusterName))
}
28 changes: 0 additions & 28 deletions test/e2e/parallel/space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,34 +267,6 @@ func TestPromoteSpace(t *testing.T) {
})
}

func TestRetargetSpace(t *testing.T) {
// given
t.Parallel()
// make sure everything is ready before running the actual tests
awaitilities := WaitForDeployments(t)
hostAwait := awaitilities.Host()
member1Await := awaitilities.Member1()
member2Await := awaitilities.Member2()

// when
space, _, _ := CreateSpace(t, awaitilities, testspace.WithTierName("base"), testspace.WithSpecTargetCluster(member1Await.ClusterName))
// then
// wait until Space has been provisioned on member-1
VerifyResourcesProvisionedForSpace(t, awaitilities, space.Name, UntilSpaceHasStatusTargetCluster(member1Await.ClusterName))

// when
space, err := hostAwait.UpdateSpace(t, space.Name, func(s *toolchainv1alpha1.Space) {
s.Spec.TargetCluster = member2Await.ClusterName
})
require.NoError(t, err)

// then
// wait until Space has been provisioned on member-1
space, _ = VerifyResourcesProvisionedForSpace(t, awaitilities, space.Name)
err = member1Await.WaitUntilNSTemplateSetDeleted(t, space.Name) // expect NSTemplateSet to be delete on member-1 cluster
require.NoError(t, err)
}

func TestSubSpaces(t *testing.T) {
// given
t.Parallel()
Expand Down
9 changes: 7 additions & 2 deletions test/e2e/usersignup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,12 @@ func (s *userSignupIntegrationTest) TestProvisionToOtherClusterWhenOneIsFull() {
Execute(s.T()).Resources()

// then
require.NotEqual(t, mur1.Spec.UserAccounts[0].TargetCluster, mur2.Spec.UserAccounts[0].TargetCluster)
require.NotEqual(t, mur1.Status.UserAccounts[0].Cluster.Name, mur2.Status.UserAccounts[0].Cluster.Name)
space1, err := hostAwait.WaitForSpace(t, mur1.Name, wait.UntilSpaceHasAnyTargetClusterSet())
require.NoError(t, err)
space2, err := hostAwait.WaitForSpace(t, mur2.Name, wait.UntilSpaceHasAnyTargetClusterSet())
require.NoError(t, err)
require.NotEqual(t, space1.Spec.TargetCluster, space2.Spec.TargetCluster)

t.Run("after both members are full then new signups won't be approved nor provisioned", func(t *testing.T) {
// when
Expand Down Expand Up @@ -625,7 +630,7 @@ func (s *userSignupIntegrationTest) TestTransformUsernameWithSpaceConflict() {
require.NoError(t, err)

// then
userSignup, _ = VerifyUserRelatedResources(t, s.Awaitilities, userSignup, "deactivate30")
userSignup, _ = VerifyUserRelatedResources(t, s.Awaitilities, userSignup, "deactivate30", ExpectAnyUserAccount())
VerifySpaceRelatedResources(t, s.Awaitilities, userSignup, "base")
VerifyResourcesProvisionedForSignup(t, s.Awaitilities, userSignup, "deactivate30", "base")
require.Equal(t, fmt.Sprintf("%s-3", conflictingSpace.Name), userSignup.Status.CompliantUsername)
Expand Down
7 changes: 5 additions & 2 deletions testsupport/signup_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,12 @@ func (r *SignupRequest) Execute(t *testing.T) *SignupRequest {
if hostAwait.GetToolchainConfig(t).Spec.Host.Tiers.DefaultSpaceTier != nil {
expectedSpaceTier = *hostAwait.GetToolchainConfig(t).Spec.Host.Tiers.DefaultSpaceTier
}
VerifyUserRelatedResources(t, r.awaitilities, userSignup, "deactivate30")
if !r.noSpace {
VerifySpaceRelatedResources(t, r.awaitilities, userSignup, expectedSpaceTier)
space := VerifySpaceRelatedResources(t, r.awaitilities, userSignup, expectedSpaceTier)
spaceMember := GetSpaceTargetMember(t, r.awaitilities, space)
VerifyUserRelatedResources(t, r.awaitilities, userSignup, "deactivate30", ExpectUserAccountIn(spaceMember))
} else {
VerifyUserRelatedResources(t, r.awaitilities, userSignup, "deactivate30", NoUserAccount())
}
mur, err := hostAwait.WaitForMasterUserRecord(t, userSignup.Status.CompliantUsername)
require.NoError(t, err)
Expand Down
Loading

0 comments on commit 69c0537

Please sign in to comment.