@@ -155,9 +155,9 @@ func Test_EvenDistributionOfReplicas(t *testing.T) {
155
155
},
156
156
// Test Case No.3 of even distribution of replicas
157
157
// 1. create deployment (replicas=7), weight=2:1:1:1
158
- // 2. check three member cluster replicas, can be 3:2:1:1、3:1:2:1、3:1:1:2
158
+ // 2. check four member cluster replicas, can be 3:2:1:1、3:1:2:1、3:1:1:2
159
159
// 3. update replicas from 7 to 8
160
- // 4. check three member cluster replicas, the added replica should lie in first cluster, i.e:
160
+ // 4. check four member cluster replicas, the added replica should lie in first cluster, i.e:
161
161
// * 3:2:1:1 --> 4:2:1:1
162
162
// * 3:1:2:1 --> 4:1:2:1
163
163
// * 3:1:1:2 --> 4:1:1:2
@@ -223,6 +223,76 @@ func Test_EvenDistributionOfReplicas(t *testing.T) {
223
223
},
224
224
wantErr : false ,
225
225
},
226
+ // Test Case No.4 of even distribution of replicas
227
+ // 1. create deployment (replicas=9), weight=2:1:1:1
228
+ // 2. check four member cluster replicas, can be 4:2:2:1、4:1:2:2、4:2:1:2
229
+ // 3. update replicas from 9 to 8
230
+ // 4. check four member cluster replicas, the reduced replica should be scaled down from cluster with 2 replicas previously, i.e:
231
+ // * 4:2:2:1 --> 4:2:1:1 or 4:1:2:1
232
+ // * 4:1:2:2 --> 4:1:1:2 or 4:1:2:1
233
+ // * 4:2:1:2 --> 4:1:1:2 or 4:2:1:1
234
+ {
235
+ name : "replica 9, static weighted 2:1:1:1, change replicas from 9 to 8, before change" ,
236
+ clusters : []* clusterv1alpha1.Cluster {
237
+ helper .NewCluster (ClusterMember1 ),
238
+ helper .NewCluster (ClusterMember2 ),
239
+ helper .NewCluster (ClusterMember3 ),
240
+ helper .NewCluster (ClusterMember4 ),
241
+ },
242
+ object : workv1alpha2.ResourceBindingSpec {
243
+ Replicas : 9 ,
244
+ },
245
+ placement : & policyv1alpha1.Placement {
246
+ ReplicaScheduling : & policyv1alpha1.ReplicaSchedulingStrategy {
247
+ ReplicaSchedulingType : policyv1alpha1 .ReplicaSchedulingTypeDivided ,
248
+ ReplicaDivisionPreference : policyv1alpha1 .ReplicaDivisionPreferenceWeighted ,
249
+ WeightPreference : & policyv1alpha1.ClusterPreferences {
250
+ StaticWeightList : []policyv1alpha1.StaticClusterWeight {
251
+ {TargetCluster : policyv1alpha1.ClusterAffinity {ClusterNames : []string {ClusterMember1 }}, Weight : 2 },
252
+ {TargetCluster : policyv1alpha1.ClusterAffinity {ClusterNames : []string {ClusterMember2 }}, Weight : 1 },
253
+ {TargetCluster : policyv1alpha1.ClusterAffinity {ClusterNames : []string {ClusterMember3 }}, Weight : 1 },
254
+ {TargetCluster : policyv1alpha1.ClusterAffinity {ClusterNames : []string {ClusterMember4 }}, Weight : 1 },
255
+ },
256
+ },
257
+ },
258
+ },
259
+ previousResultToNewResult : map [string ][]string {
260
+ "" : {"4:2:2:1" , "4:1:2:2" , "4:2:1:2" },
261
+ },
262
+ wantErr : false ,
263
+ },
264
+ {
265
+ name : "replica 9, static weighted 2:1:1:1, change replicas from 9 to 8, after change" ,
266
+ clusters : []* clusterv1alpha1.Cluster {
267
+ helper .NewCluster (ClusterMember1 ),
268
+ helper .NewCluster (ClusterMember2 ),
269
+ helper .NewCluster (ClusterMember3 ),
270
+ helper .NewCluster (ClusterMember4 ),
271
+ },
272
+ object : workv1alpha2.ResourceBindingSpec {
273
+ Replicas : 8 ,
274
+ },
275
+ placement : & policyv1alpha1.Placement {
276
+ ReplicaScheduling : & policyv1alpha1.ReplicaSchedulingStrategy {
277
+ ReplicaSchedulingType : policyv1alpha1 .ReplicaSchedulingTypeDivided ,
278
+ ReplicaDivisionPreference : policyv1alpha1 .ReplicaDivisionPreferenceWeighted ,
279
+ WeightPreference : & policyv1alpha1.ClusterPreferences {
280
+ StaticWeightList : []policyv1alpha1.StaticClusterWeight {
281
+ {TargetCluster : policyv1alpha1.ClusterAffinity {ClusterNames : []string {ClusterMember1 }}, Weight : 2 },
282
+ {TargetCluster : policyv1alpha1.ClusterAffinity {ClusterNames : []string {ClusterMember2 }}, Weight : 1 },
283
+ {TargetCluster : policyv1alpha1.ClusterAffinity {ClusterNames : []string {ClusterMember3 }}, Weight : 1 },
284
+ {TargetCluster : policyv1alpha1.ClusterAffinity {ClusterNames : []string {ClusterMember4 }}, Weight : 1 },
285
+ },
286
+ },
287
+ },
288
+ },
289
+ previousResultToNewResult : map [string ][]string {
290
+ "4:2:2:1" : {"4:2:1:1" , "4:1:2:1" },
291
+ "4:1:2:2" : {"4:1:1:2" , "4:1:2:1" },
292
+ "4:2:1:2" : {"4:1:1:2" , "4:2:1:1" },
293
+ },
294
+ wantErr : false ,
295
+ },
226
296
}
227
297
for _ , tt := range tests {
228
298
t .Run (tt .name , func (t * testing.T ) {
@@ -242,7 +312,7 @@ func Test_EvenDistributionOfReplicas(t *testing.T) {
242
312
return
243
313
}
244
314
245
- // 3. check if previous schedule result valid
315
+ // 3. check if schedule result got match to expected
246
316
gotResult := targetClusterToString (got )
247
317
for _ , expectResult := range expect {
248
318
if gotResult == expectResult {
0 commit comments