Skip to content

Commit e9851ae

Browse files
committed
test of even distribution of replicas for removing cluster scenario
Signed-off-by: chaosi-zju <[email protected]>
1 parent 1833c86 commit e9851ae

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

pkg/scheduler/core/generic_scheduler_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,74 @@ func Test_EvenDistributionOfReplicas(t *testing.T) {
431431
},
432432
wantErr: false,
433433
},
434+
// Test Case No.7 of even distribution of replicas: ensure as much inertia as possible in removing cluster scenarios
435+
// 1. create deployment (replicas=6), weight=1:1:1:1
436+
// 2. check four member cluster replicas, can be 2:2:1:1、2:1:2:1、2:1:1:2、1:2:2:1、1:2:1:2、1:1:2:2
437+
// 3. delete the member4 cluster in case of only one replica has been allocated to the member4 cluster
438+
// 4. check three left member cluster replicas, the original replica in member4 cluster will be scaled to another cluster with one replica, just like:
439+
// * 2:2:1:1 --> 2:2:2
440+
// * 2:1:2:1 --> 2:2:2
441+
// * 1:2:2:1 --> 2:2:2
442+
{
443+
name: "replica 6, static weighted 1:1:1:1, remove a cluster and change static weight to 1:1:1, before change",
444+
clusters: []*clusterv1alpha1.Cluster{
445+
helper.NewCluster(ClusterMember1),
446+
helper.NewCluster(ClusterMember2),
447+
helper.NewCluster(ClusterMember3),
448+
helper.NewCluster(ClusterMember4),
449+
},
450+
object: workv1alpha2.ResourceBindingSpec{
451+
Replicas: 6,
452+
},
453+
placement: &policyv1alpha1.Placement{
454+
ReplicaScheduling: &policyv1alpha1.ReplicaSchedulingStrategy{
455+
ReplicaSchedulingType: policyv1alpha1.ReplicaSchedulingTypeDivided,
456+
ReplicaDivisionPreference: policyv1alpha1.ReplicaDivisionPreferenceWeighted,
457+
WeightPreference: &policyv1alpha1.ClusterPreferences{
458+
StaticWeightList: []policyv1alpha1.StaticClusterWeight{
459+
{TargetCluster: policyv1alpha1.ClusterAffinity{ClusterNames: []string{ClusterMember1}}, Weight: 1},
460+
{TargetCluster: policyv1alpha1.ClusterAffinity{ClusterNames: []string{ClusterMember2}}, Weight: 1},
461+
{TargetCluster: policyv1alpha1.ClusterAffinity{ClusterNames: []string{ClusterMember3}}, Weight: 1},
462+
{TargetCluster: policyv1alpha1.ClusterAffinity{ClusterNames: []string{ClusterMember4}}, Weight: 1},
463+
},
464+
},
465+
},
466+
},
467+
previousResultToNewResult: map[string][]string{
468+
"": {"2:2:1:1", "2:1:2:1", "2:1:1:2", "1:2:2:1", "1:2:1:2", "1:1:2:2"},
469+
},
470+
wantErr: false,
471+
},
472+
{
473+
name: "replica 6, static weighted 1:1:1:1, remove a cluster and change static weight to 1:1:1, after change",
474+
clusters: []*clusterv1alpha1.Cluster{
475+
helper.NewCluster(ClusterMember1),
476+
helper.NewCluster(ClusterMember2),
477+
helper.NewCluster(ClusterMember3),
478+
},
479+
object: workv1alpha2.ResourceBindingSpec{
480+
Replicas: 6,
481+
},
482+
placement: &policyv1alpha1.Placement{
483+
ReplicaScheduling: &policyv1alpha1.ReplicaSchedulingStrategy{
484+
ReplicaSchedulingType: policyv1alpha1.ReplicaSchedulingTypeDivided,
485+
ReplicaDivisionPreference: policyv1alpha1.ReplicaDivisionPreferenceWeighted,
486+
WeightPreference: &policyv1alpha1.ClusterPreferences{
487+
StaticWeightList: []policyv1alpha1.StaticClusterWeight{
488+
{TargetCluster: policyv1alpha1.ClusterAffinity{ClusterNames: []string{ClusterMember1}}, Weight: 1},
489+
{TargetCluster: policyv1alpha1.ClusterAffinity{ClusterNames: []string{ClusterMember2}}, Weight: 1},
490+
{TargetCluster: policyv1alpha1.ClusterAffinity{ClusterNames: []string{ClusterMember3}}, Weight: 1},
491+
},
492+
},
493+
},
494+
},
495+
previousResultToNewResult: map[string][]string{
496+
"2:2:1:1": {"2:2:2"},
497+
"2:1:2:1": {"2:2:2"},
498+
"1:2:2:1": {"2:2:2"},
499+
},
500+
wantErr: false,
501+
},
434502
}
435503
for _, tt := range tests {
436504
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)