Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrancisc authored May 30, 2024
2 parents dfc8e94 + 4b5f6c3 commit badccc3
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 96 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-20240514085958-3b5237399fe5
github.com/codeready-toolchain/toolchain-common v0.0.0-20240514101749-1ceadb6ea36b
github.com/codeready-toolchain/api v0.0.0-20240530120602-c11598ccffb7
github.com/codeready-toolchain/toolchain-common v0.0.0-20240530121312-98aad712838f
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-20240514085958-3b5237399fe5 h1:lfW7VPmj70Tt75VzgOfAdVEGKMCR5/zACugWl1BDw34=
github.com/codeready-toolchain/api v0.0.0-20240514085958-3b5237399fe5/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240514101749-1ceadb6ea36b h1:9WGqXkgAmnMOYUvYSdeIszTfE5NbuZ2hmibXchTU7r0=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240514101749-1ceadb6ea36b/go.mod h1:oG4ywphvcYpFuaxrJcAkEVrBfhXsXPPQ2ieF3Y+e/wo=
github.com/codeready-toolchain/api v0.0.0-20240530120602-c11598ccffb7 h1:o5JLcHCVS1BlZevw2mh1mH+iKwn9fLUrT1Ek8NFjvPY=
github.com/codeready-toolchain/api v0.0.0-20240530120602-c11598ccffb7/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240530121312-98aad712838f h1:2qfRfyh7wfEnnfxrUtQeQrvhzWlkBCN0B/UXv1YUMiA=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240530121312-98aad712838f/go.mod h1:cyHrUfvBYEtsf+FbqQYmR9y0AQi9QAVtM3SUWLA5bd4=
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
16 changes: 2 additions & 14 deletions setup/users/create_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/toolchain-common/pkg/condition"
"github.com/codeready-toolchain/toolchain-common/pkg/hash"
"github.com/codeready-toolchain/toolchain-common/pkg/states"
"github.com/codeready-toolchain/toolchain-e2e/setup/configuration"
"github.com/codeready-toolchain/toolchain-e2e/testsupport/wait"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8swait "k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -59,7 +59,7 @@ func getMemberClusterName(cl client.Client, hostOperatorNamespace, memberOperato
return false, err
}
for _, cluster := range clusters.Items {
if containsClusterCondition(cluster.Status.Conditions, wait.ReadyToolchainCluster) {
if condition.IsTrue(cluster.Status.Conditions, toolchainv1alpha1.ConditionReady) {
memberCluster = cluster
return true, nil
}
Expand All @@ -68,15 +68,3 @@ func getMemberClusterName(cl client.Client, hostOperatorNamespace, memberOperato
})
return memberCluster.Name, err
}

func containsClusterCondition(conditions []toolchainv1alpha1.ToolchainClusterCondition, contains *toolchainv1alpha1.ToolchainClusterCondition) bool {
if contains == nil {
return true
}
for _, c := range conditions {
if c.Type == contains.Type {
return contains.Status == c.Status
}
}
return false
}
4 changes: 2 additions & 2 deletions setup/users/create_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func TestCreate(t *testing.T) {
},
},
Status: toolchainv1alpha1.ToolchainClusterStatus{
Conditions: []toolchainv1alpha1.ToolchainClusterCondition{
Conditions: []toolchainv1alpha1.Condition{
{
Type: toolchainv1alpha1.ToolchainClusterReady,
Type: toolchainv1alpha1.ConditionReady,
Status: corev1.ConditionTrue,
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/parallel/registration_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ func assertGetSignupStatusProvisioned(t *testing.T, await wait.Awaitilities, use
assert.Equal(t, transformedUsername, mp["compliantUsername"])
assert.Equal(t, username, mp["username"])
assert.Equal(t, memberAwait.GetConsoleURL(t), mp["consoleURL"])
memberCluster, found, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, nil)
memberCluster, found, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
require.True(t, found)
assert.Equal(t, memberCluster.Spec.APIEndpoint, mp["apiEndpoint"])
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/parallel/spacerequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestCreateSpaceRequest(t *testing.T) {
hostAwait := awaitilities.Host()
memberAwait := awaitilities.Member1()
memberAwait2 := awaitilities.Member2()
memberCluster, found, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, nil)
memberCluster, found, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
require.True(t, found)

Expand Down Expand Up @@ -201,7 +201,7 @@ func TestCreateSpaceRequest(t *testing.T) {
t.Run("subSpace target cluster is different from spacerequest cluster", func(t *testing.T) {
// when
// we add a custom cluster-role for member2
memberCluster2, found, err := hostAwait.GetToolchainCluster(t, memberAwait2.Namespace, nil)
memberCluster2, found, err := hostAwait.GetToolchainCluster(t, memberAwait2.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
require.True(t, found)
spaceprovisionerconfig.UpdateForCluster(t, hostAwait.Awaitility, memberCluster2.Name, testSpc.WithPlacementRoles(cluster.RoleLabel("member-2")))
Expand Down
17 changes: 7 additions & 10 deletions test/e2e/toolchaincluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestToolchainClusterE2E(t *testing.T) {
// in the target cluster type operator
func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wait.Awaitility) {
// given
current, ok, err := await.GetToolchainCluster(t, otherAwait.Namespace, nil)
current, ok, err := await.GetToolchainCluster(t, otherAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
require.True(t, ok, "ToolchainCluster should exist")

Expand Down Expand Up @@ -70,7 +70,7 @@ func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wa
// then the ToolchainCluster should be ready
_, err = await.WaitForToolchainCluster(t,
wait.UntilToolchainClusterHasName(toolchainCluster.Name),
wait.UntilToolchainClusterHasCondition(*wait.ReadyToolchainCluster),
wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ConditionReady),
)
require.NoError(t, err)
// other ToolchainCluster should be ready, too
Expand All @@ -79,13 +79,13 @@ func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wa
client.MatchingLabels{
"namespace": otherAwait.Namespace,
},
), wait.UntilToolchainClusterHasCondition(*wait.ReadyToolchainCluster),
), wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ConditionReady),
)
require.NoError(t, err)
_, err = otherAwait.WaitForToolchainCluster(t,
wait.UntilToolchainClusterHasLabels(client.MatchingLabels{
"namespace": await.Namespace,
}), wait.UntilToolchainClusterHasCondition(*wait.ReadyToolchainCluster),
}), wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ConditionReady),
)
require.NoError(t, err)
})
Expand Down Expand Up @@ -113,10 +113,7 @@ func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wa
require.NoError(t, err)
_, err = await.WaitForToolchainCluster(t,
wait.UntilToolchainClusterHasName(toolchainCluster.Name),
wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ToolchainClusterCondition{
Type: toolchainv1alpha1.ToolchainClusterOffline,
Status: corev1.ConditionTrue,
}),
wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ToolchainClusterOffline),
)
require.NoError(t, err)
// other ToolchainCluster should be ready, too
Expand All @@ -125,13 +122,13 @@ func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wa
client.MatchingLabels{
"namespace": otherAwait.Namespace,
},
), wait.UntilToolchainClusterHasCondition(*wait.ReadyToolchainCluster),
), wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ConditionReady),
)
require.NoError(t, err)
_, err = otherAwait.WaitForToolchainCluster(t,
wait.UntilToolchainClusterHasLabels(client.MatchingLabels{
"namespace": await.Namespace,
}), wait.UntilToolchainClusterHasCondition(*wait.ReadyToolchainCluster),
}), wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ConditionReady),
)
require.NoError(t, err)
})
Expand Down
2 changes: 1 addition & 1 deletion test/migration/verify/verify_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func verifyProvisionedSubSpace(t *testing.T, awaitilities wait.Awaitilities) {
targetClusterRoles := []string{cluster.RoleLabel(cluster.Tenant)}
hostAwait := awaitilities.Host()
memberAwait := awaitilities.Member2()
memberCluster, found, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, nil)
memberCluster, found, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
require.True(t, found)
subSpaceNamespace := GetDefaultNamespace(parentSpace.Status.ProvisionedNamespaces)
Expand Down
6 changes: 3 additions & 3 deletions testsupport/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ func waitForOperators(t *testing.T) {

initMember2Await = getMemberAwaitility(t, initHostAwait, kubeconfig, memberNs2)

_, err = initMemberAwait.WaitForToolchainClusterWithCondition(t, initHostAwait.Namespace, wait.ReadyToolchainCluster)
_, err = initMemberAwait.WaitForToolchainClusterWithCondition(t, initHostAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)

_, err = initMember2Await.WaitForToolchainClusterWithCondition(t, initHostAwait.Namespace, wait.ReadyToolchainCluster)
_, err = initMember2Await.WaitForToolchainClusterWithCondition(t, initHostAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)

t.Log("all operators are ready and in running state")
Expand Down Expand Up @@ -235,7 +235,7 @@ func getMemberAwaitility(t *testing.T, hostAwait *wait.HostAwaitility, restconfi
})
require.NoError(t, err)

memberCluster, err := hostAwait.WaitForToolchainClusterWithCondition(t, namespace, wait.ReadyToolchainCluster)
memberCluster, err := hostAwait.WaitForToolchainClusterWithCondition(t, namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
clusterName := memberCluster.Name
memberAwait := wait.NewMemberAwaitility(restconfig, memberClient, namespace, clusterName)
Expand Down
2 changes: 1 addition & 1 deletion testsupport/toolchain_status_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func VerifyMemberStatus(t *testing.T, memberAwait *wait.MemberAwaitility, expect
}

func VerifyToolchainStatus(t *testing.T, hostAwait *wait.HostAwaitility, memberAwait *wait.MemberAwaitility) {
memberCluster, found, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, nil)
memberCluster, found, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
require.True(t, found)
_, err = hostAwait.WaitForToolchainStatus(t, wait.UntilToolchainStatusHasConditions(wait.ToolchainStatusReadyAndUnreadyNotificationNotCreated()...),
Expand Down
2 changes: 1 addition & 1 deletion testsupport/user_assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func verifyUserAccount(t *testing.T, awaitilities wait.Awaitilities, userSignup
}

// Get member cluster to verify that it was used to provision user accounts
memberCluster, ok, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, nil)
memberCluster, ok, err := hostAwait.GetToolchainCluster(t, memberAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
require.True(t, ok)

Expand Down
66 changes: 11 additions & 55 deletions testsupport/wait/awaitility.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1"
"github.com/codeready-toolchain/toolchain-common/pkg/cluster"
cd "github.com/codeready-toolchain/toolchain-common/pkg/condition"
"github.com/codeready-toolchain/toolchain-common/pkg/status"
"github.com/codeready-toolchain/toolchain-common/pkg/test"
"github.com/codeready-toolchain/toolchain-common/pkg/test/assertions"
Expand Down Expand Up @@ -70,12 +71,6 @@ func (a *Awaitility) copy() *Awaitility {
return result
}

// ReadyToolchainCluster is a ClusterCondition that represents cluster that is ready
var ReadyToolchainCluster = &toolchainv1alpha1.ToolchainClusterCondition{
Type: toolchainv1alpha1.ToolchainClusterReady,
Status: corev1.ConditionTrue,
}

// WithRetryOptions returns a new Awaitility with the given "RetryOption"s applied
func (a *Awaitility) WithRetryOptions(options ...RetryOption) *Awaitility {
result := a.copy()
Expand Down Expand Up @@ -159,40 +154,14 @@ func (a *Awaitility) WaitForService(t *testing.T, name string) (corev1.Service,
}

// WaitForToolchainClusterWithCondition waits until there is a ToolchainCluster representing a operator of the given type
// and running in the given expected namespace. If the given condition is not nil, then it also checks
// if the CR has the ClusterCondition
func (a *Awaitility) WaitForToolchainClusterWithCondition(t *testing.T, namespace string, condition *toolchainv1alpha1.ToolchainClusterCondition) (toolchainv1alpha1.ToolchainCluster, error) {
// and running in the given expected namespace. It also checks if the CR has the ClusterConditionType
func (a *Awaitility) WaitForToolchainClusterWithCondition(t *testing.T, namespace string, cdtype toolchainv1alpha1.ConditionType) (toolchainv1alpha1.ToolchainCluster, error) {
t.Logf("waiting for ToolchainCluster in namespace '%s'", namespace)
timeout := a.Timeout
if condition != nil {
timeout = ToolchainClusterConditionTimeout
}

var c toolchainv1alpha1.ToolchainCluster
err := wait.Poll(a.RetryInterval, timeout, func() (done bool, err error) {
err := wait.Poll(a.RetryInterval, a.Timeout, func() (done bool, err error) {
var ready bool
if c, ready, err = a.GetToolchainCluster(t, namespace, condition); ready {
return true, nil
}
return false, err
})
return c, err
}

// WaitForNamedToolchainClusterWithCondition waits until there is a ToolchainCluster with the given name
// and with the given ClusterCondition (if it the condition is nil, then it skips this check)
func (a *Awaitility) WaitForNamedToolchainClusterWithCondition(t *testing.T, name string, condition *toolchainv1alpha1.ToolchainClusterCondition) (toolchainv1alpha1.ToolchainCluster, error) {
t.Logf("waiting for ToolchainCluster '%s' in namespace '%s' to have condition '%v'", name, a.Namespace, condition)
timeout := a.Timeout
if condition != nil {
timeout = ToolchainClusterConditionTimeout
}
c := toolchainv1alpha1.ToolchainCluster{}
err := wait.Poll(a.RetryInterval, timeout, func() (done bool, err error) {
c = toolchainv1alpha1.ToolchainCluster{}
if err := a.Client.Get(context.TODO(), types.NamespacedName{Namespace: a.Namespace, Name: name}, &c); err != nil {
return false, err
}
if containsClusterCondition(c.Status.Conditions, condition) {
if c, ready, err = a.GetToolchainCluster(t, namespace, cdtype); ready {
return true, nil
}
return false, err
Expand All @@ -201,9 +170,8 @@ func (a *Awaitility) WaitForNamedToolchainClusterWithCondition(t *testing.T, nam
}

// GetToolchainCluster retrieves and returns a ToolchainCluster representing a operator of the given type
// and running in the given expected namespace. If the given condition is not nil, then it also checks
// if the CR has the ClusterCondition
func (a *Awaitility) GetToolchainCluster(t *testing.T, namespace string, condition *toolchainv1alpha1.ToolchainClusterCondition) (toolchainv1alpha1.ToolchainCluster, bool, error) {
// and running in the given expected namespace. It also checks if the CR has the ClusterConditionType
func (a *Awaitility) GetToolchainCluster(t *testing.T, namespace string, cdtype toolchainv1alpha1.ConditionType) (toolchainv1alpha1.ToolchainCluster, bool, error) {
clusters := &toolchainv1alpha1.ToolchainClusterList{}
if err := a.Client.List(context.TODO(), clusters, client.InNamespace(a.Namespace), client.MatchingLabels{
"namespace": namespace,
Expand All @@ -215,25 +183,13 @@ func (a *Awaitility) GetToolchainCluster(t *testing.T, namespace string, conditi
}
// assume there is zero or 1 match only
for _, cl := range clusters.Items {
if containsClusterCondition(cl.Status.Conditions, condition) {
if cd.IsTrue(cl.Status.Conditions, cdtype) {
return cl, true, nil
}
}
return toolchainv1alpha1.ToolchainCluster{}, false, nil
}

func containsClusterCondition(conditions []toolchainv1alpha1.ToolchainClusterCondition, contains *toolchainv1alpha1.ToolchainClusterCondition) bool {
if contains == nil {
return true
}
for _, c := range conditions {
if c.Type == contains.Type {
return contains.Status == c.Status
}
}
return false
}

// SetupRouteForService if needed, creates a route for the given service (with the same namespace/name)
// It waits until the route is available (or returns an error) by first checking the resource status
// and then making a call to the given endpoint
Expand Down Expand Up @@ -575,10 +531,10 @@ func UntilToolchainClusterHasName(expectedName string) ToolchainClusterWaitCrite
}

// UntilToolchainClusterHasCondition checks if ToolchainCluster has the given condition
func UntilToolchainClusterHasCondition(expected toolchainv1alpha1.ToolchainClusterCondition) ToolchainClusterWaitCriterion {
func UntilToolchainClusterHasCondition(expected toolchainv1alpha1.ConditionType) ToolchainClusterWaitCriterion {
return ToolchainClusterWaitCriterion{
Match: func(actual *toolchainv1alpha1.ToolchainCluster) bool {
return containsClusterCondition(actual.Status.Conditions, &expected)
return cd.IsTrue(actual.Status.Conditions, expected)
},
}
}
Expand Down

0 comments on commit badccc3

Please sign in to comment.