@@ -8,8 +8,10 @@ import (
88 "github.com/codeready-toolchain/toolchain-common/pkg/cluster"
99 testconfig "github.com/codeready-toolchain/toolchain-common/pkg/test/config"
1010 testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space"
11+ testSpc "github.com/codeready-toolchain/toolchain-common/pkg/test/spaceprovisionerconfig"
1112 . "github.com/codeready-toolchain/toolchain-e2e/testsupport"
1213 . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space"
14+ "github.com/codeready-toolchain/toolchain-e2e/testsupport/spaceprovisionerconfig"
1315 "github.com/codeready-toolchain/toolchain-e2e/testsupport/wait"
1416
1517 "github.com/stretchr/testify/assert"
@@ -44,13 +46,8 @@ func TestAutomaticClusterAssignment(t *testing.T) {
4446
4547 t .Run ("set low max number of spaces and expect that space won't be provisioned but added on waiting list" , func (t * testing.T ) {
4648 // given
47- hostAwait .UpdateToolchainConfig (t ,
48- testconfig .CapacityThresholds ().
49- MaxNumberOfSpaces (
50- testconfig .PerMemberCluster (memberAwait1 .ClusterName , - 1 ),
51- testconfig .PerMemberCluster (memberAwait2 .ClusterName , - 1 ),
52- ),
53- )
49+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait1 .ClusterName , testSpc .Enabled (false ))
50+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait2 .ClusterName , testSpc .Enabled (false ))
5451 // some short time to get the cache populated with the change
5552 // sometimes the ToolchainConfig doesn't have the new values in the CapacityThresholds section before the creation of Spaces is issued
5653 // so Spaces were still created while Capacity was updated with the above values.
@@ -69,28 +66,17 @@ func TestAutomaticClusterAssignment(t *testing.T) {
6966
7067 t .Run ("increment the max number of spaces and expect that first space will be provisioned." , func (t * testing.T ) {
7168 // when
72- hostAwait .UpdateToolchainConfig (t ,
73- testconfig .CapacityThresholds ().
74- MaxNumberOfSpaces (
75- // increment max spaces only on member1
76- testconfig .PerMemberCluster (memberAwait1 .ClusterName , 2 ),
77- testconfig .PerMemberCluster (memberAwait2 .ClusterName , - 1 ),
78- ),
79- )
69+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait1 .ClusterName , testSpc .MaxNumberOfSpaces (2 ), testSpc .Enabled (true ))
70+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait2 .ClusterName , testSpc .Enabled (false ))
8071
8172 // then
8273 VerifyResourcesProvisionedForSpace (t , awaitilities , space1 .Name )
8374 // the second space won't be provisioned immediately
8475 waitUntilSpaceIsPendingCluster (t , hostAwait , space2 .Name )
8576 t .Run ("reset the max number and expect the second space will be provisioned as well" , func (t * testing.T ) {
8677 // when
87- hostAwait .UpdateToolchainConfig (t ,
88- testconfig .CapacityThresholds ().
89- MaxNumberOfSpaces (
90- testconfig .PerMemberCluster (memberAwait1 .ClusterName , 500 ),
91- testconfig .PerMemberCluster (memberAwait2 .ClusterName , 500 ),
92- ),
93- )
78+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait1 .ClusterName , testSpc .MaxNumberOfSpaces (500 ), testSpc .Enabled (true ))
79+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait2 .ClusterName , testSpc .MaxNumberOfSpaces (500 ), testSpc .Enabled (true ))
9480
9581 // then
9682 VerifyResourcesProvisionedForSpace (t , awaitilities , space2 .Name )
@@ -100,9 +86,8 @@ func TestAutomaticClusterAssignment(t *testing.T) {
10086
10187 t .Run ("set low capacity threshold and expect that space will have default tier, but won't have target cluster so it won't be provisioned" , func (t * testing.T ) {
10288 // given
103- hostAwait .UpdateToolchainConfig (t ,
104- testconfig .CapacityThresholds ().ResourceCapacityThreshold (1 ),
105- )
89+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait1 .ClusterName , testSpc .MaxMemoryUtilizationPercent (1 ))
90+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait2 .ClusterName , testSpc .MaxMemoryUtilizationPercent (1 ))
10691 // some short time to get the cache populated with the change
10792 time .Sleep (1 * time .Second )
10893
@@ -115,7 +100,8 @@ func TestAutomaticClusterAssignment(t *testing.T) {
115100
116101 t .Run ("reset the threshold and expect the space will be have the targetCluster set and will be also provisioned" , func (t * testing.T ) {
117102 // when
118- hostAwait .UpdateToolchainConfig (t , testconfig .CapacityThresholds ().ResourceCapacityThreshold (80 ))
103+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait1 .ClusterName , testSpc .MaxMemoryUtilizationPercent (80 ))
104+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait2 .ClusterName , testSpc .MaxMemoryUtilizationPercent (80 ))
119105
120106 // then
121107 VerifyResourcesProvisionedForSpace (t , awaitilities , space .Name )
@@ -124,21 +110,17 @@ func TestAutomaticClusterAssignment(t *testing.T) {
124110
125111 t .Run ("mark the first member cluster as full and for the second keep some capacity - expect that the space will be provisioned to the second one" , func (t * testing.T ) {
126112 // given
127- var memberLimits []testconfig.PerMemberClusterOptionInt
128113 toolchainStatus , err := hostAwait .WaitForToolchainStatus (t ,
129114 wait .UntilToolchainStatusHasConditions (wait .ToolchainStatusReadyAndUnreadyNotificationNotCreated ()... ),
130115 wait .UntilToolchainStatusUpdatedAfter (time .Now ()))
131116 require .NoError (t , err )
132117 for _ , m := range toolchainStatus .Status .Members {
133118 if memberAwait1 .ClusterName == m .ClusterName {
134- memberLimits = append ( memberLimits , testconfig . PerMemberCluster ( memberAwait1 .ClusterName , m .SpaceCount ))
119+ spaceprovisionerconfig . UpdateForCluster ( t , hostAwait . Awaitility , memberAwait1 .ClusterName , testSpc . MaxNumberOfSpaces ( uint ( m .SpaceCount ) ))
135120 } else if memberAwait2 .ClusterName == m .ClusterName {
136- memberLimits = append ( memberLimits , testconfig . PerMemberCluster ( memberAwait2 .ClusterName , m .SpaceCount + 1 ))
121+ spaceprovisionerconfig . UpdateForCluster ( t , hostAwait . Awaitility , memberAwait2 .ClusterName , testSpc . MaxNumberOfSpaces ( uint ( m .SpaceCount + 1 ) ))
137122 }
138123 }
139- require .Len (t , memberLimits , 2 )
140-
141- hostAwait .UpdateToolchainConfig (t , testconfig .CapacityThresholds ().MaxNumberOfSpaces (memberLimits ... ))
142124
143125 // when
144126 space1 , _ := CreateSpaceWithBinding (t , awaitilities , mur , testspace .WithName ("space-multimember-1" ), testspace .WithTierName ("appstudio" ))
@@ -148,16 +130,9 @@ func TestAutomaticClusterAssignment(t *testing.T) {
148130
149131 t .Run ("after both members marking as full then the new space won't be provisioned" , func (t * testing.T ) {
150132 // given
151- var memberLimits []testconfig.PerMemberClusterOptionInt
152133 for _ , m := range toolchainStatus .Status .Members {
153- if memberAwait1 .ClusterName == m .ClusterName {
154- memberLimits = append (memberLimits , testconfig .PerMemberCluster (memberAwait1 .ClusterName , m .SpaceCount ))
155- } else if memberAwait2 .ClusterName == m .ClusterName {
156- memberLimits = append (memberLimits , testconfig .PerMemberCluster (memberAwait2 .ClusterName , m .SpaceCount ))
157- }
134+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , m .ClusterName , testSpc .MaxNumberOfSpaces (uint (m .SpaceCount )))
158135 }
159- require .Len (t , memberLimits , 2 )
160- hostAwait .UpdateToolchainConfig (t , testconfig .CapacityThresholds ().MaxNumberOfSpaces (memberLimits ... ))
161136
162137 // when
163138 space2 , _ := CreateSpaceWithBinding (t , awaitilities , mur , testspace .WithName ("space-multimember-2" ), testspace .WithTierName ("appstudio" ))
@@ -178,18 +153,8 @@ func TestAutomaticClusterAssignment(t *testing.T) {
178153 t .Run ("set cluster-role label only on member2 cluster and expect it will be selected" , func (t * testing.T ) {
179154 // given
180155 // both cluster have room for more spaces ...
181- hostAwait .UpdateToolchainConfig (t , testconfig .CapacityThresholds ().MaxNumberOfSpaces (
182- testconfig .PerMemberCluster (memberAwait1 .ClusterName , 500 ),
183- testconfig .PerMemberCluster (memberAwait2 .ClusterName , 500 ),
184- ))
185- // let's add a custom cluster-role for member2
186- memberCluster2 , found , err := hostAwait .GetToolchainCluster (t , memberAwait2 .Namespace , nil )
187- require .NoError (t , err )
188- require .True (t , found )
189- _ , err = hostAwait .UpdateToolchainCluster (t , memberCluster2 .Name , func (tc * toolchainv1alpha1.ToolchainCluster ) {
190- tc .Labels [cluster .RoleLabel ("workspace" )] = "" // add a new cluster-role label, the value is blank since only key matters.
191- })
192- require .NoError (t , err )
156+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait1 .ClusterName , testSpc .MaxNumberOfSpaces (500 ))
157+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait2 .ClusterName , testSpc .MaxNumberOfSpaces (500 ), testSpc .WithPlacementRoles (testSpc .PlacementRole ("workspace" )))
193158
194159 // when
195160 space1 , _ := CreateSpaceWithBinding (t , awaitilities , mur , testspace .WithName ("space-clusterole-tenant" ),
@@ -203,18 +168,8 @@ func TestAutomaticClusterAssignment(t *testing.T) {
203168 t .Run ("set cluster-role label only on member2 cluster but mark it as full so that no cluster will be available" , func (t * testing.T ) {
204169 // given
205170 // only member1 as room for spaces
206- hostAwait .UpdateToolchainConfig (t , testconfig .CapacityThresholds ().MaxNumberOfSpaces (
207- testconfig .PerMemberCluster (memberAwait1 .ClusterName , 500 ), // member1 has more room
208- testconfig .PerMemberCluster (memberAwait2 .ClusterName , - 1 ), // member2 is full
209- ))
210- // let's add a custom cluster-role for member2
211- memberCluster2 , found , err := hostAwait .GetToolchainCluster (t , memberAwait2 .Namespace , nil )
212- require .NoError (t , err )
213- require .True (t , found )
214- _ , err = hostAwait .UpdateToolchainCluster (t , memberCluster2 .Name , func (tc * toolchainv1alpha1.ToolchainCluster ) {
215- tc .Labels [cluster .RoleLabel ("workspace" )] = "" // add a new cluster-role label, the value is blank since only key matters.
216- })
217- require .NoError (t , err )
171+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait1 .ClusterName , testSpc .MaxNumberOfSpaces (500 ))
172+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait2 .ClusterName , testSpc .Enabled (false ), testSpc .WithPlacementRoles (testSpc .PlacementRole ("workspace" )))
218173
219174 // when
220175 space1 , _ := CreateSpaceWithBinding (t , awaitilities , mur , testspace .WithName ("space-clusterole-tenant-pending" ),
@@ -227,18 +182,8 @@ func TestAutomaticClusterAssignment(t *testing.T) {
227182
228183 t .Run ("provision space on the required cluster even if it doesn't match the specified cluster-role" , func (t * testing.T ) {
229184 // given
230- hostAwait .UpdateToolchainConfig (t , testconfig .CapacityThresholds ().MaxNumberOfSpaces (
231- testconfig .PerMemberCluster (memberAwait1 .ClusterName , 500 ), // member1 has more room
232- testconfig .PerMemberCluster (memberAwait2 .ClusterName , 500 ), // member2 has more room as well
233- ))
234- // let's add a custom cluster-role for member2
235- memberCluster2 , found , err := hostAwait .GetToolchainCluster (t , memberAwait2 .Namespace , nil )
236- require .NoError (t , err )
237- require .True (t , found )
238- _ , err = hostAwait .UpdateToolchainCluster (t , memberCluster2 .Name , func (tc * toolchainv1alpha1.ToolchainCluster ) {
239- tc .Labels [cluster .RoleLabel ("workspace" )] = "" // add a new cluster-role label, the value is blank since only key matters.
240- })
241- require .NoError (t , err )
185+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait1 .ClusterName , testSpc .MaxNumberOfSpaces (500 ))
186+ spaceprovisionerconfig .UpdateForCluster (t , hostAwait .Awaitility , memberAwait2 .ClusterName , testSpc .MaxNumberOfSpaces (500 ), testSpc .WithPlacementRoles (testSpc .PlacementRole ("workspace" )))
242187
243188 // when
244189 space1 , _ := CreateSpaceWithBinding (t , awaitilities , mur ,
0 commit comments