Skip to content

Commit

Permalink
Merge branch 'master' into registermember
Browse files Browse the repository at this point in the history
  • Loading branch information
MatousJobanek authored Aug 19, 2024
2 parents f8d163d + 52bba41 commit 902b727
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 53 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/codeready-toolchain/toolchain-e2e

require (
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69
github.com/codeready-toolchain/toolchain-common v0.0.0-20240802180627-14c41a99df18
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27
github.com/codeready-toolchain/toolchain-common v0.0.0-20240816011540-2184e6268b4a
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.12.0
github.com/ghodss/yaml v1.0.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69 h1:e6up2k4O7QdG6hu0iOwNGap60b932N0JXlweDmmvCAQ=
github.com/codeready-toolchain/api v0.0.0-20240802163003-cce070815e69/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240802180627-14c41a99df18 h1:ZSXXcz3BmYvYmw1BexF4xvRjlr/3W5IOKxvc1NwLjKg=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240802180627-14c41a99df18/go.mod h1:ulg9vY3W6Lsrn84/qVneCIrTvMkBC1mzmQqGfYDv7lQ=
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27 h1:uEH8HAM81QZBccuqQpGKJUoJQe28+DFSYi/mRKZDYrA=
github.com/codeready-toolchain/api v0.0.0-20240815232340-d0c164a83d27/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240816011540-2184e6268b4a h1:o18wLp3eT4HdH8TvDqtLWiC47WY/kaTp9p54exux/MU=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240816011540-2184e6268b4a/go.mod h1:aIbki5CFsykeqZn2/ZwvUb3Krx2f2Tbq58R6MGnk6H8=
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
85 changes: 49 additions & 36 deletions make/ksctl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,61 @@ endif

get-ksctl-and-install:
ifeq ($(strip $(KSCTL_REPO_PATH)),)
ifneq ($(CI),)
ifneq ($(GITHUB_ACTIONS),)
$(eval BRANCH_NAME = ${GITHUB_HEAD_REF})
$(eval AUTHOR_LINK = https://github.com/${AUTHOR})
ifneq ($(DEPLOY_LATEST),true)
ifneq ($(CI),)
ifneq ($(GITHUB_ACTIONS),)
$(eval BRANCH_NAME = ${GITHUB_HEAD_REF})
$(eval AUTHOR_LINK = https://github.com/${AUTHOR})
else
$(eval AUTHOR_LINK = $(shell jq -r '.refs[0].pulls[0].author_link' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'))
@echo "found author link ${AUTHOR_LINK}"
$(eval BRANCH_NAME := $(shell jq -r '.refs[0].pulls[0].head_ref' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'))
endif
@echo "using author link ${AUTHOR_LINK}"
@echo "detected branch ${BRANCH_NAME}"
# check if a branch with the same ref exists in the user's fork of ksctl repo
@echo "branches of ${AUTHOR_LINK}/ksctl - checking if there is a branch ${BRANCH_NAME} we could pair with."
curl ${AUTHOR_LINK}/ksctl.git/info/refs?service=git-upload-pack --output -
$(eval REMOTE_KSCTL_BRANCH := $(shell curl ${AUTHOR_LINK}/ksctl.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "refs/heads/${BRANCH_NAME}$$" | awk '{print $$2}'))
# check if the branch with the same name exists, if so then merge it with master and use the merge branch, if not then use master
@$(MAKE) clone-ksctl-and-pair REMOTE_KSCTL_BRANCH=${REMOTE_KSCTL_BRANCH} AUTHOR_LINK=${AUTHOR_LINK}
else
$(eval AUTHOR_LINK = $(shell jq -r '.refs[0].pulls[0].author_link' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'))
@echo "found author link ${AUTHOR_LINK}"
$(eval BRANCH_NAME := $(shell jq -r '.refs[0].pulls[0].head_ref' <<< $${CLONEREFS_OPTIONS} | tr -d '[:space:]'))
endif
@echo "using author link ${AUTHOR_LINK}"
@echo "detected branch ${BRANCH_NAME}"
# check if a branch with the same ref exists in the user's fork of ksctl repo
@echo "branches of ${AUTHOR_LINK}/ksctl - checking if there is a branch ${BRANCH_NAME} we could pair with."
curl ${AUTHOR_LINK}/ksctl.git/info/refs?service=git-upload-pack --output -
$(eval REMOTE_KSCTL_BRANCH := $(shell curl ${AUTHOR_LINK}/ksctl.git/info/refs?service=git-upload-pack --output - 2>/dev/null | grep -a "refs/heads/${BRANCH_NAME}$$" | awk '{print $$2}'))
@echo "branch ref of the user's fork: \"${REMOTE_KSCTL_BRANCH}\" - if empty then not found"
# check if the branch with the same name exists, if so then merge it with master and use the merge branch, if not then use master
ifneq ($(strip $(REMOTE_KSCTL_BRANCH)),)
# define temp dir
$(eval KSCTL_REPO_PATH := /tmp/ksctl)
# delete to have clear environment
rm -rf ${KSCTL_REPO_PATH}

git config --global user.email "[email protected]"
git config --global user.name "Devtools"
# clone
git clone --depth=1 https://github.com/kubesaw/ksctl.git ${KSCTL_REPO_PATH}
# add the user's fork as remote repo
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} remote add external ${AUTHOR_LINK}/ksctl.git
# fetch the branch
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} fetch external ${REMOTE_KSCTL_BRANCH}
# merge the branch with master
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} merge --allow-unrelated-histories --no-commit FETCH_HEAD
@echo "Not running in CI - no pairing"
endif
else
@echo "DEPLOY_LATEST is set to true - no pairing"
endif
else
@echo "KSCTL_REPO_PATH is set to ${KSCTL_REPO_PATH} - no pairing"
endif
@$(MAKE) install-ksctl KSCTL_REPO_PATH=${KSCTL_REPO_PATH} REMOTE_KSCTL_BRANCH=${REMOTE_KSCTL_BRANCH}

clone-ksctl-and-pair:
ifneq ($(strip $(REMOTE_KSCTL_BRANCH)),)
@echo "Branch ref of the user's fork to be used for pairing: \"${REMOTE_KSCTL_BRANCH}\""
# define temp dir
$(eval KSCTL_REPO_PATH := /tmp/ksctl)
# delete to have clear environment
rm -rf ${KSCTL_REPO_PATH}

git config --global user.email "[email protected]"
git config --global user.name "Devtools"
# clone
git clone --depth=1 https://github.com/kubesaw/ksctl.git ${KSCTL_REPO_PATH}
# add the user's fork as remote repo
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} remote add external ${AUTHOR_LINK}/ksctl.git
# fetch the branch
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} fetch external ${REMOTE_KSCTL_BRANCH}
# merge the branch with master
git --git-dir=${KSCTL_REPO_PATH}/.git --work-tree=${KSCTL_REPO_PATH} merge --allow-unrelated-histories --no-commit FETCH_HEAD
else
@echo "No branch for pairing found"
endif
@$(MAKE) install-ksctl KSCTL_REPO_PATH=${KSCTL_REPO_PATH}

install-ksctl:
ifneq ($(strip $(KSCTL_REPO_PATH)),)
@echo "Installing ksctl from directory ${KSCTL_REPO_PATH}"
$(MAKE) -C ${KSCTL_REPO_PATH} GOBIN=${BIN_DIR} install
ifneq ($(strip $(KSCTL_REPO_PATH)$(REMOTE_KSCTL_BRANCH)),)
@echo "Installing ksctl from directory $(or ${KSCTL_REPO_PATH}, /tmp/ksctl)"
$(MAKE) -C $(or ${KSCTL_REPO_PATH}, /tmp/ksctl) GOBIN=${BIN_DIR} install
else
@echo "Installing ksctl from master"
GOBIN=${BIN_DIR} CGO_ENABLED=0 go install github.com/kubesaw/ksctl/cmd/ksctl@master
Expand Down
48 changes: 37 additions & 11 deletions test/e2e/parallel/registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,13 +695,15 @@ func TestActivationCodeVerification(t *testing.T) {
t.Parallel()
await := WaitForDeployments(t)
hostAwait := await.Host()
member2Await := await.Member2()
route := hostAwait.RegistrationServiceURL

t.Run("verification successful", func(t *testing.T) {
verifySuccessful := func(t *testing.T, targetCluster string) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate80"),
testsocialevent.WithSpaceTier("base1ns6didler"))
testsocialevent.WithSpaceTier("base1ns6didler"),
testsocialevent.WithTargetCluster(targetCluster))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
userSignup, token := signup(t, hostAwait)
Expand All @@ -728,22 +730,37 @@ func TestActivationCodeVerification(t *testing.T) {
// check that the MUR and Space are configured as expected
// Wait for the UserSignup to have the desired state
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasCompliantUsername())
wait.UntilUserSignupHasCompliantUsername(),
wait.UntilUserSignupHasTargetCluster(targetCluster))
require.NoError(t, err)
mur, err := hostAwait.WaitForMasterUserRecord(t, userSignup.Status.CompliantUsername,
wait.UntilMasterUserRecordHasTierName(event.Spec.UserTier),
wait.UntilMasterUserRecordHasCondition(wait.Provisioned()))
require.NoError(t, err)
assert.Equal(t, event.Spec.UserTier, mur.Spec.TierName)
_, err = hostAwait.WaitForSpace(t, userSignup.Status.CompliantUsername,
spaceCriterion := []wait.SpaceWaitCriterion{
wait.UntilSpaceHasTier(event.Spec.SpaceTier),
wait.UntilSpaceHasConditions(wait.Provisioned()),
)
}
if targetCluster != "" {
spaceCriterion = append(spaceCriterion, wait.UntilSpaceHasStatusTargetCluster(targetCluster))
} else {
spaceCriterion = append(spaceCriterion, wait.UntilSpaceHasAnyTargetClusterSet())
}
_, err = hostAwait.WaitForSpace(t, userSignup.Status.CompliantUsername, spaceCriterion...)
require.NoError(t, err)

// also check that the SocialEvent status was updated accordingly
_, err = hostAwait.WaitForSocialEvent(t, event.Name, wait.UntilSocialEventHasActivationCount(1))
require.NoError(t, err)
}

t.Run("verification successful with no target cluster", func(t *testing.T) {
verifySuccessful(t, "")
})

t.Run("verification successful with target cluster", func(t *testing.T) {
verifySuccessful(t, member2Await.ClusterName)
})

t.Run("verification failed", func(t *testing.T) {
Expand All @@ -767,7 +784,8 @@ func TestActivationCodeVerification(t *testing.T) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithUserTier("deactivate80"),
testsocialevent.WithSpaceTier("base1ns6didler"))
testsocialevent.WithSpaceTier("base1ns6didler"),
testsocialevent.WithTargetCluster(member2Await.ClusterName))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
event, err = hostAwait.WaitForSocialEvent(t, event.Name) // need to reload event
Expand All @@ -785,14 +803,17 @@ func TestActivationCodeVerification(t *testing.T) {
// then
// ensure the UserSignup is not approved yet
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...))
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...),
wait.UntilUserSignupHasTargetCluster("")) // target cluster from the event is ignored when verification failed
require.NoError(t, err)
assert.Equal(t, "1", userSignup.Annotations[toolchainv1alpha1.UserVerificationAttemptsAnnotationKey])
})

t.Run("not opened yet", func(t *testing.T) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(), testsocialevent.WithStartTime(time.Now().Add(time.Hour))) // not open yet
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(),
testsocialevent.WithStartTime(time.Now().Add(time.Hour)), // not open yet
testsocialevent.WithTargetCluster(member2Await.ClusterName))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
userSignup, token := signup(t, hostAwait)
Expand All @@ -804,14 +825,18 @@ func TestActivationCodeVerification(t *testing.T) {
// then
// ensure the UserSignup is not approved yet
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...))
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...),
wait.UntilUserSignupHasTargetCluster("")) // target cluster from the event is ignored when verification failed
require.NoError(t, err)
assert.Equal(t, "1", userSignup.Annotations[toolchainv1alpha1.UserVerificationAttemptsAnnotationKey])
})

t.Run("already closed", func(t *testing.T) {
// given
event := testsocialevent.NewSocialEvent(hostAwait.Namespace, commonsocialevent.NewName(), testsocialevent.WithEndTime(time.Now().Add(-time.Hour))) // already closd
event := testsocialevent.NewSocialEvent(hostAwait.Namespace,
commonsocialevent.NewName(),
testsocialevent.WithEndTime(time.Now().Add(-time.Hour)), // already closd
testsocialevent.WithTargetCluster(member2Await.ClusterName))
err := hostAwait.CreateWithCleanup(t, event)
require.NoError(t, err)
userSignup, token := signup(t, hostAwait)
Expand All @@ -823,7 +848,8 @@ func TestActivationCodeVerification(t *testing.T) {
// then
// ensure the UserSignup is approved
userSignup, err = hostAwait.WaitForUserSignup(t, userSignup.Name,
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...))
wait.UntilUserSignupHasConditions(wait.ConditionSet(wait.Default(), wait.VerificationRequired())...),
wait.UntilUserSignupHasTargetCluster("")) // target cluster from the event is ignored when verification failed
require.NoError(t, err)
assert.Equal(t, "1", userSignup.Annotations[toolchainv1alpha1.UserVerificationAttemptsAnnotationKey])
})
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/parallel/socialevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestCreateSocialEvent(t *testing.T) {
testsocialevent.WithStartTime(start),
testsocialevent.WithEndTime(end),
testsocialevent.WithMaxAttendees(5),
testsocialevent.WithTargetCluster("member-1"),
)

// when
Expand All @@ -51,6 +52,7 @@ func TestCreateSocialEvent(t *testing.T) {
assert.Equal(t, start, event.Spec.StartTime.Time)
assert.Equal(t, end, event.Spec.EndTime.Time)
assert.Equal(t, 5, event.Spec.MaxAttendees)
assert.Equal(t, "member-1", event.Spec.TargetCluster)
})

t.Run("create socialevent with invalid user tier name", func(t *testing.T) {
Expand Down
13 changes: 13 additions & 0 deletions testsupport/wait/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,19 @@ func UntilUserSignupHasConditions(expected ...toolchainv1alpha1.Condition) UserS
}
}

// UntilUserSignupHasTargetCluster returns a `UserSignupWaitCriterion` which checks that the given
// UserSignup has the expected target cluster field
func UntilUserSignupHasTargetCluster(expectedTargetCluster string) UserSignupWaitCriterion {
return UserSignupWaitCriterion{
Match: func(actual *toolchainv1alpha1.UserSignup) bool {
return actual.Spec.TargetCluster == expectedTargetCluster
},
Diff: func(actual *toolchainv1alpha1.UserSignup) string {
return fmt.Sprintf("expected target cluster to match:\n%s", Diff(expectedTargetCluster, actual.Spec.TargetCluster))
},
}
}

// UntilUserSignupContainsConditions returns a `UserSignupWaitCriterion` which checks that the given
// UserSignup contains all the given status conditions
func UntilUserSignupContainsConditions(shouldContain ...toolchainv1alpha1.Condition) UserSignupWaitCriterion {
Expand Down

0 comments on commit 902b727

Please sign in to comment.