Skip to content

Commit

Permalink
Merge branch 'master' into sbapi2
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
mfrancisc committed Oct 11, 2023
2 parents 188b9a7 + 713b901 commit 92ed19a
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 @@ -122,4 +122,4 @@ require (

go 1.19

replace github.com/codeready-toolchain/toolchain-common => github.com/mfrancisc/toolchain-common v0.0.0-20231002145157-94054ae52f2e
replace github.com/codeready-toolchain/toolchain-common => github.com/mfrancisc/toolchain-common v0.0.0-20231011125252-0299bfd1dcf5
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/mfrancisc/toolchain-common v0.0.0-20231002145157-94054ae52f2e h1:P4C77qKcRLx9BJ8vnYaX6MC84SUCrz6EldhhiIazHHA=
github.com/mfrancisc/toolchain-common v0.0.0-20231002145157-94054ae52f2e/go.mod h1:o/JGPWZ/9rVh/np0tcaPRXnreZ+X743o0Gxp1eP62/w=
github.com/mfrancisc/toolchain-common v0.0.0-20231011125252-0299bfd1dcf5 h1:RMCxWiA0wmFdp4K83M1Etomi5IIHcwL+XpDOaYiwKaw=
github.com/mfrancisc/toolchain-common v0.0.0-20231011125252-0299bfd1dcf5/go.mod h1:o/JGPWZ/9rVh/np0tcaPRXnreZ+X743o0Gxp1eP62/w=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/migueleliasweb/go-github-mock v0.0.18 h1:0lWt9MYmZQGnQE2rFtjlft/YtD6hzxuN6JJRFpujzEI=
github.com/migueleliasweb/go-github-mock v0.0.18/go.mod h1:CcgXcbMoRnf3rRVHqGssuBquZDIcaplxL2W6G+xs7kM=
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 92ed19a

Please sign in to comment.