Skip to content

Commit 69cd5e3

Browse files
committed
add unit test
Signed-off-by: LivingCcj <[email protected]>
1 parent c978771 commit 69cd5e3

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

pkg/scheduler/core/assignment_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,40 @@ func Test_dynamicScale(t *testing.T) {
416416
},
417417
wantErr: false,
418418
},
419+
{
420+
name: "replica 12 -> 24, dynamic weighted 10:10(unhealthy cluster):10",
421+
candidates: []spreadconstraint.ClusterDetailInfo{
422+
{Name: ClusterMember1, Cluster: helper.NewClusterWithResource(ClusterMember1, corev1.ResourceList{
423+
corev1.ResourcePods: *resource.NewQuantity(10, resource.DecimalSI),
424+
}, util.EmptyResource().ResourceList(), util.EmptyResource().ResourceList()), AllocatableReplicas: 10},
425+
{Name: ClusterMember2, Cluster: helper.NewClusterWithUnhealthyStatus(ClusterMember2, corev1.ResourceList{
426+
corev1.ResourcePods: *resource.NewQuantity(10, resource.DecimalSI),
427+
}, util.EmptyResource().ResourceList(), util.EmptyResource().ResourceList()), AllocatableReplicas: 10},
428+
{Name: ClusterMember3, Cluster: helper.NewClusterWithResource(ClusterMember3, corev1.ResourceList{
429+
corev1.ResourcePods: *resource.NewQuantity(10, resource.DecimalSI),
430+
}, util.EmptyResource().ResourceList(), util.EmptyResource().ResourceList()), AllocatableReplicas: 10},
431+
},
432+
object: &workv1alpha2.ResourceBindingSpec{
433+
ReplicaRequirements: &workv1alpha2.ReplicaRequirements{
434+
ResourceRequest: util.EmptyResource().ResourceList(),
435+
},
436+
Replicas: 24,
437+
Clusters: []workv1alpha2.TargetCluster{
438+
{Name: ClusterMember1, Replicas: 2},
439+
{Name: ClusterMember2, Replicas: 4},
440+
{Name: ClusterMember3, Replicas: 6},
441+
},
442+
Placement: &policyv1alpha1.Placement{
443+
ReplicaScheduling: dynamicWeightStrategy,
444+
},
445+
},
446+
want: []workv1alpha2.TargetCluster{
447+
{Name: ClusterMember1, Replicas: 8},
448+
{Name: ClusterMember2, Replicas: 4},
449+
{Name: ClusterMember3, Replicas: 12},
450+
},
451+
wantErr: false,
452+
},
419453
{
420454
name: "replica 12 -> 24, dynamic weighted 1:1:1",
421455
candidates: []spreadconstraint.ClusterDetailInfo{

test/helper/resource.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,17 @@ func MakeNodeWithTaints(node string, milliCPU, memory, pods, ephemeralStorage in
679679
func NewCluster(name string) *clusterv1alpha1.Cluster {
680680
return &clusterv1alpha1.Cluster{
681681
ObjectMeta: metav1.ObjectMeta{Name: name},
682+
Status: clusterv1alpha1.ClusterStatus{
683+
Conditions: []metav1.Condition{
684+
{
685+
Type: clusterv1alpha1.ClusterConditionReady,
686+
Status: metav1.ConditionTrue,
687+
Reason: "ClusterReady",
688+
Message: "cluster is healthy and ready to accept workloads",
689+
LastTransitionTime: metav1.Now(),
690+
},
691+
},
692+
},
682693
}
683694
}
684695

@@ -692,6 +703,38 @@ func NewClusterWithResource(name string, allocatable, allocating, allocated core
692703
Allocating: allocating,
693704
Allocated: allocated,
694705
},
706+
Conditions: []metav1.Condition{
707+
{
708+
Type: clusterv1alpha1.ClusterConditionReady,
709+
Status: metav1.ConditionTrue,
710+
Reason: "ClusterReady",
711+
Message: "cluster is healthy and ready to accept workloads",
712+
LastTransitionTime: metav1.Now(),
713+
},
714+
},
715+
},
716+
}
717+
}
718+
719+
// NewClusterWithUnhealthyStatus will build a Cluster with resource.
720+
func NewClusterWithUnhealthyStatus(name string, allocatable, allocating, allocated corev1.ResourceList) *clusterv1alpha1.Cluster {
721+
return &clusterv1alpha1.Cluster{
722+
ObjectMeta: metav1.ObjectMeta{Name: name},
723+
Status: clusterv1alpha1.ClusterStatus{
724+
ResourceSummary: &clusterv1alpha1.ResourceSummary{
725+
Allocatable: allocatable,
726+
Allocating: allocating,
727+
Allocated: allocated,
728+
},
729+
Conditions: []metav1.Condition{
730+
{
731+
Type: clusterv1alpha1.ClusterConditionReady,
732+
Status: metav1.ConditionFalse,
733+
Reason: "ClusterNotReachable",
734+
Message: "cluster is not reachable",
735+
LastTransitionTime: metav1.Now(),
736+
},
737+
},
695738
},
696739
}
697740
}

0 commit comments

Comments
 (0)