-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose assignReplicas function in scheduler
Signed-off-by: chaosi-zju <[email protected]>
- Loading branch information
1 parent
bf1098b
commit 4e6e1e2
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package core | ||
|
||
import ( | ||
"testing" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
||
clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1" | ||
policyv1alpha1 "github.com/karmada-io/karmada/pkg/apis/policy/v1alpha1" | ||
workv1alpha2 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha2" | ||
"github.com/karmada-io/karmada/pkg/util" | ||
"github.com/karmada-io/karmada/test/helper" | ||
) | ||
|
||
func Test_genericScheduler_AssignReplicas(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
clusters []*clusterv1alpha1.Cluster | ||
placement *policyv1alpha1.Placement | ||
object *workv1alpha2.ResourceBindingSpec | ||
want []workv1alpha2.TargetCluster | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "replica 4, dynamic weighted 1:1", | ||
clusters: []*clusterv1alpha1.Cluster{ | ||
helper.NewClusterWithResource(ClusterMember1, corev1.ResourceList{ | ||
corev1.ResourcePods: *resource.NewQuantity(4, resource.DecimalSI), | ||
}, util.EmptyResource().ResourceList(), util.EmptyResource().ResourceList()), | ||
helper.NewClusterWithResource(ClusterMember2, corev1.ResourceList{ | ||
corev1.ResourcePods: *resource.NewQuantity(4, resource.DecimalSI), | ||
}, util.EmptyResource().ResourceList(), util.EmptyResource().ResourceList()), | ||
}, | ||
object: &workv1alpha2.ResourceBindingSpec{ | ||
Replicas: 4, | ||
}, | ||
placement: &policyv1alpha1.Placement{ | ||
ReplicaScheduling: dynamicWeightStrategy, | ||
}, | ||
want: []workv1alpha2.TargetCluster{ | ||
{Name: ClusterMember1, Replicas: 2}, | ||
{Name: ClusterMember2, Replicas: 2}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
g := &genericScheduler{} | ||
got, err := g.AssignReplicas(tt.clusters, tt.placement, tt.object) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("AssignReplicas() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !helper.IsScheduleResultEqual(got, tt.want) { | ||
t.Errorf("AssignReplicas() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |