Skip to content

Commit

Permalink
Account for unschedulable plugin result during maxreplica estimation
Browse files Browse the repository at this point in the history
Signed-off-by: mszacillo <mszacillo@bloomberg.net>
  • Loading branch information
mszacillo committed Jun 3, 2024
1 parent c181917 commit 957e50b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions pkg/estimator/server/estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func (es *AccurateSchedulerEstimatorServer) estimateReplicas(

var res int32
replicas, ret := es.estimateFramework.RunEstimateReplicasPlugins(ctx, snapshot, &requirements)

if ret.IsUnschedulable() {
return replicas, nil
}

if !ret.IsSuccess() && !ret.IsNoOperation() {
return replicas, fmt.Errorf(fmt.Sprintf("estimate replice plugins fails with %s", ret.Reasons()))
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/estimator/server/framework/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func (s *Result) IsSuccess() bool {
return s == nil || s.code == Success
}

// IsUnschedulable return true if "Result" is not nil and Code is "Unschedulable".
func (s *Result) IsUnschedulable() bool {
return s != nil && s.code == Unschedulable
}

// IsNoOperation return true if "Result" is not nil and Code is "Nooperation"
// ToDo (wengyao04): we can remove it once we include node resource estimation as the default plugin in the future
func (s *Result) IsNoOperation() bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/estimator/server/framework/runtime/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (frw *frameworkImpl) RunEstimateReplicasPlugins(ctx context.Context, snapsh
results := make(framework.PluginToResult)
for _, pl := range frw.estimateReplicasPlugins {
plReplica, ret := frw.runEstimateReplicasPlugins(ctx, pl, snapshot, replicaRequirements)
if ret.IsSuccess() && plReplica < replica {
if (ret.IsSuccess() || ret.IsUnschedulable()) && plReplica < replica {
replica = plReplica
}
results[pl.Name()] = ret
Expand Down
4 changes: 2 additions & 2 deletions pkg/estimator/server/framework/runtime/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func Test_frameworkImpl_RunEstimateReplicasPlugins(t *testing.T) {
},
},
expected: estimateReplicaResult{
replica: 1,
replica: 0,
ret: framework.NewResult(framework.Unschedulable, "plugin 2 is unschedulable"),
},
},
Expand All @@ -144,7 +144,7 @@ func Test_frameworkImpl_RunEstimateReplicasPlugins(t *testing.T) {
},
},
expected: estimateReplicaResult{
replica: math.MaxInt32,
replica: 0,
ret: framework.NewResult(framework.Unschedulable, "plugin 1 is unschedulable", "plugin 2 is no operation"),
},
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/scheduler/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ func calAvailableReplicas(clusters []*clusterv1alpha1.Cluster, spec *workv1alpha
estimators := estimatorclient.GetReplicaEstimators()
ctx := context.WithValue(context.TODO(), util.ContextKeyObject,
fmt.Sprintf("kind=%s, name=%s/%s", spec.Resource.Kind, spec.Resource.Namespace, spec.Resource.Name))
for _, estimator := range estimators {
for name, estimator := range estimators {
res, err := estimator.MaxAvailableReplicas(ctx, clusters, spec.ReplicaRequirements)
klog.V(5).Infof("MaxAvailableReplica scores calculated by estimator %s: %v", name, availableTargetClusters)
if err != nil {
klog.Errorf("Max cluster available replicas error: %v", err)
continue
Expand Down

0 comments on commit 957e50b

Please sign in to comment.