Skip to content

Commit 1cd8b0b

Browse files
committed
adjust the Priority of General and Accurate Estimator of Karmada Scheduler
Signed-off-by: chaosi-zju <[email protected]>
1 parent 3482ee8 commit 1cd8b0b

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

pkg/estimator/client/accurate.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func (se *SchedulerEstimator) MaxAvailableReplicas(
6767
})
6868
}
6969

70+
func (se *SchedulerEstimator) GetPriority() EstimatorPriority {
71+
return High
72+
}
73+
7074
// GetUnschedulableReplicas gets the unschedulable replicas which belong to a specified workload by calling karmada-scheduler-estimator.
7175
func (se *SchedulerEstimator) GetUnschedulableReplicas(
7276
parentCtx context.Context,

pkg/estimator/client/general.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func (ge *GeneralEstimator) MaxAvailableReplicas(_ context.Context, clusters []*
5353
return availableTargetClusters, nil
5454
}
5555

56+
func (ge *GeneralEstimator) GetPriority() EstimatorPriority {
57+
return Middle
58+
}
59+
5660
func (ge *GeneralEstimator) maxAvailableReplicas(cluster *clusterv1alpha1.Cluster, replicaRequirements *workv1alpha2.ReplicaRequirements) int32 {
5761
resourceSummary := cluster.Status.ResourceSummary
5862
if resourceSummary == nil {

pkg/estimator/client/interface.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ var (
3737
// ReplicaEstimator is an estimator which estimates the maximum replicas that can be applied to the target cluster.
3838
type ReplicaEstimator interface {
3939
MaxAvailableReplicas(ctx context.Context, clusters []*clusterv1alpha1.Cluster, replicaRequirements *workv1alpha2.ReplicaRequirements) ([]workv1alpha2.TargetCluster, error)
40+
GetPriority() EstimatorPriority
4041
}
4142

4243
// UnschedulableReplicaEstimator is an estimator which estimates the unschedulable replicas which belong to a specified workload.
@@ -53,3 +54,16 @@ func GetReplicaEstimators() map[string]ReplicaEstimator {
5354
func GetUnschedulableReplicaEstimators() map[string]UnschedulableReplicaEstimator {
5455
return unschedulableReplicaEstimators
5556
}
57+
58+
// EstimatorPriority
59+
// 1. Higher-priority estimator can directly override the result given by lower-priority estimator
60+
// 2. Lower replicas estimated will be chosen if the priority of estimator are same
61+
// 3. Lower-priority estimator would be ignored if the result was already given by higher-priority estimator
62+
type EstimatorPriority int
63+
64+
const (
65+
Undefined EstimatorPriority = iota
66+
Low
67+
Middle
68+
High
69+
)

pkg/scheduler/core/util.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,22 @@ func getDefaultWeightPreference(clusters []*clusterv1alpha1.Cluster) *policyv1al
5353

5454
func calAvailableReplicas(clusters []*clusterv1alpha1.Cluster, spec *workv1alpha2.ResourceBindingSpec) []workv1alpha2.TargetCluster {
5555
availableTargetClusters := make([]workv1alpha2.TargetCluster, len(clusters))
56+
// availableResultPriority indicates which priority Estimator gives the scheduling result for each cluster, respectively
57+
// 1. Higher-priority estimator can directly override the result given by lower-priority estimator
58+
// 2. Lower replicas estimated will be chosen if the priority of estimator are same
59+
// 3. Lower-priority estimator would be ignored if the result was already given by higher-priority estimator
60+
availableResultPriority := make([]estimatorclient.EstimatorPriority, len(clusters))
5661

5762
// Set the boundary.
5863
for i := range availableTargetClusters {
5964
availableTargetClusters[i].Name = clusters[i].Name
6065
availableTargetClusters[i].Replicas = math.MaxInt32
6166
}
6267

68+
for i := range availableResultPriority {
69+
availableResultPriority[i] = estimatorclient.Undefined
70+
}
71+
6372
// For non-workload, like ServiceAccount, ConfigMap, Secret and etc, it's unnecessary to calculate available replicas in member clusters.
6473
// See issue: https://github.com/karmada-io/karmada/issues/3743.
6574
if spec.Replicas == 0 {
@@ -79,11 +88,21 @@ func calAvailableReplicas(clusters []*clusterv1alpha1.Cluster, spec *workv1alpha
7988
continue
8089
}
8190
for i := range res {
91+
if res[i].Name != availableTargetClusters[i].Name {
92+
continue
93+
}
8294
if res[i].Replicas == estimatorclient.UnauthenticReplica {
8395
continue
8496
}
85-
if availableTargetClusters[i].Name == res[i].Name && availableTargetClusters[i].Replicas > res[i].Replicas {
97+
// means there are already replicas calculated by higher-priority estimator
98+
if estimator.GetPriority() < availableResultPriority[i] {
99+
continue
100+
}
101+
// override if current estimator has higher priority and take lower replicas is estimator priority are same
102+
if (estimator.GetPriority() == availableResultPriority[i] && res[i].Replicas < availableTargetClusters[i].Replicas) ||
103+
estimator.GetPriority() > availableResultPriority[i] {
86104
availableTargetClusters[i].Replicas = res[i].Replicas
105+
availableResultPriority[i] = estimator.GetPriority()
87106
}
88107
}
89108
}

0 commit comments

Comments
 (0)