Skip to content

Commit

Permalink
KUBESAW-100: Refactoring toolchaincluster controller-Pair Host operat…
Browse files Browse the repository at this point in the history
…or (#1005)

* KUBESAW-100: Refactoring toolchaincluster controller

Signed-off-by: Feny Mehta <[email protected]>

* updateaftercleanup

Signed-off-by: Feny Mehta <[email protected]>

* 1

Signed-off-by: Feny Mehta <[email protected]>

* adding reason check

Signed-off-by: Feny Mehta <[email protected]>

* removing replace

Signed-off-by: Feny Mehta <[email protected]>

---------

Signed-off-by: Feny Mehta <[email protected]>
  • Loading branch information
fbm3307 authored Jul 16, 2024
1 parent e1d2b6c commit 2d2c21e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 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-20240530120602-c11598ccffb7
github.com/codeready-toolchain/toolchain-common v0.0.0-20240530121312-98aad712838f
github.com/codeready-toolchain/api v0.0.0-20240708122235-0af5a9a178bb
github.com/codeready-toolchain/toolchain-common v0.0.0-20240716065433-8604fe46b96a
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-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/codeready-toolchain/api v0.0.0-20240708122235-0af5a9a178bb h1:Wc9CMsv0ODZv9dM5qF3OI0mFDO95YNIXV/8oRvoz8aE=
github.com/codeready-toolchain/api v0.0.0-20240708122235-0af5a9a178bb/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240716065433-8604fe46b96a h1:HcaJtZCLfYkWZCxIa3iTvq3zgn711JGqPLkunBTfGSc=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240716065433-8604fe46b96a/go.mod h1:8M9k7w2VSyRKSK6P08Jo2ddW3uyGgxCcSitnYa3HK9o=
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
30 changes: 20 additions & 10 deletions test/e2e/toolchaincluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func TestToolchainClusterE2E(t *testing.T) {
memberAwait := awaitilities.Member1()
memberAwait.WaitForToolchainClusterResources(t)

verifyToolchainCluster(t, hostAwait.Awaitility, memberAwait.Awaitility)
verifyToolchainCluster(t, memberAwait.Awaitility, hostAwait.Awaitility)
verifyToolchainCluster(t, hostAwait.Awaitility, memberAwait.Awaitility, true)
verifyToolchainCluster(t, memberAwait.Awaitility, hostAwait.Awaitility, false)
}

// verifyToolchainCluster verifies existence and correct conditions of ToolchainCluster CRD
// in the target cluster type operator
func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wait.Awaitility) {
func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wait.Awaitility, singleCondition bool) {
// given
current, ok, err := await.GetToolchainCluster(t, otherAwait.Namespace, toolchainv1alpha1.ConditionReady)
require.NoError(t, err)
Expand Down Expand Up @@ -103,7 +103,7 @@ func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wa
require.NoError(t, err)
})

t.Run(fmt.Sprintf("create new ToolchainCluster based on '%s' with incorrect data and expect to be offline", current.Name), func(t *testing.T) {
t.Run(fmt.Sprintf("create new ToolchainCluster based on '%s' with incorrect data and expect to be Not Ready", current.Name), func(t *testing.T) {
// given
name := generateNewName("new-offline-", current.Name)
secretCopy := &corev1.Secret{}
Expand All @@ -126,13 +126,22 @@ func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wa
// wait for toolchaincontroller to reconcile
time.Sleep(1 * time.Second)

// then the ToolchainCluster should be offline
require.NoError(t, err)
_, err = await.WaitForToolchainCluster(t,
wait.UntilToolchainClusterHasName(toolchainCluster.Name),
wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ToolchainClusterOffline),
)
// then the ToolchainCluster should be Not Ready
require.NoError(t, err)
if singleCondition {
_, err = await.WaitForToolchainCluster(t,
wait.UntilToolchainClusterHasName(toolchainCluster.Name),
wait.UntilToolchainClusterHasConditionFalseStatusAndReason(toolchainv1alpha1.ConditionReady, toolchainv1alpha1.ToolchainClusterClusterNotReachableReason),
)
require.NoError(t, err)
} else {
// then the ToolchainCluster should be offline
_, err = await.WaitForToolchainCluster(t,
wait.UntilToolchainClusterHasName(toolchainCluster.Name),
wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ToolchainClusterOffline),
)
require.NoError(t, err)
}
// other ToolchainCluster should be ready, too
_, err = await.WaitForToolchainCluster(t,
wait.UntilToolchainClusterHasLabels(
Expand All @@ -148,6 +157,7 @@ func verifyToolchainCluster(t *testing.T, await *wait.Awaitility, otherAwait *wa
}), wait.UntilToolchainClusterHasCondition(toolchainv1alpha1.ConditionReady),
)
require.NoError(t, err)

})
}

Expand Down
9 changes: 9 additions & 0 deletions testsupport/wait/awaitility.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,15 @@ func UntilToolchainClusterHasCondition(expected toolchainv1alpha1.ConditionType)
}
}

// UntilToolchainClusterHasCondition checks if ToolchainCluster has the given condition and False Status
func UntilToolchainClusterHasConditionFalseStatusAndReason(expected toolchainv1alpha1.ConditionType, reason string) ToolchainClusterWaitCriterion {
return ToolchainClusterWaitCriterion{
Match: func(actual *toolchainv1alpha1.ToolchainCluster) bool {
return cd.IsFalseWithReason(actual.Status.Conditions, expected, reason)
},
}
}

// UntilToolchainClusterHasLabels checks if ToolchainCluster has the given labels
func UntilToolchainClusterHasLabels(expected client.MatchingLabels) ToolchainClusterWaitCriterion {
return ToolchainClusterWaitCriterion{
Expand Down

0 comments on commit 2d2c21e

Please sign in to comment.