mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #81015 from draveness/feature/update-normalize-score-extension-point
feat: return error when score is out of range
This commit is contained in:
commit
7a35f8c92d
@ -12,6 +12,7 @@ go_library(
|
|||||||
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1",
|
importpath = "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
|
"//pkg/scheduler/api:go_default_library",
|
||||||
"//pkg/scheduler/apis/config:go_default_library",
|
"//pkg/scheduler/apis/config:go_default_library",
|
||||||
"//pkg/scheduler/internal/cache:go_default_library",
|
"//pkg/scheduler/internal/cache:go_default_library",
|
||||||
"//pkg/scheduler/util:go_default_library",
|
"//pkg/scheduler/util:go_default_library",
|
||||||
|
@ -431,8 +431,16 @@ func (f *framework) ApplyScoreWeights(pc *PluginContext, pod *v1.Pod, scores Plu
|
|||||||
errCh.SendErrorWithCancel(err, cancel)
|
errCh.SendErrorWithCancel(err, cancel)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for i := range nodeScoreList {
|
|
||||||
nodeScoreList[i].Score = nodeScoreList[i].Score * weight
|
for i, nodeScore := range nodeScoreList {
|
||||||
|
// return error if score plugin returns invalid score.
|
||||||
|
if nodeScore.Score > MaxNodeScore || nodeScore.Score < MinNodeScore {
|
||||||
|
err := fmt.Errorf("score plugin %q returns an invalid score %q, it should in the range of [MinNodeScore, MaxNodeScore] after normalizing", pl.Name(), nodeScore.Score)
|
||||||
|
errCh.SendErrorWithCancel(err, cancel)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeScoreList[i].Score = nodeScore.Score * weight
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -604,6 +604,60 @@ func TestApplyScoreWeights(t *testing.T) {
|
|||||||
},
|
},
|
||||||
err: true,
|
err: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Score plugin return score greater than MaxNodeScore",
|
||||||
|
plugins: plugin1And2,
|
||||||
|
input: PluginToNodeScores{
|
||||||
|
scorePlugin1: {
|
||||||
|
{
|
||||||
|
Name: "node1",
|
||||||
|
Score: MaxNodeScore + 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "node2",
|
||||||
|
Score: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scorePlugin2: {
|
||||||
|
{
|
||||||
|
Name: "node1",
|
||||||
|
Score: MinNodeScore,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "node2",
|
||||||
|
Score: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Score plugin return score less than MinNodeScore",
|
||||||
|
plugins: plugin1And2,
|
||||||
|
input: PluginToNodeScores{
|
||||||
|
scorePlugin1: {
|
||||||
|
{
|
||||||
|
Name: "node1",
|
||||||
|
Score: MaxNodeScore,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "node2",
|
||||||
|
Score: 3,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
scorePlugin2: {
|
||||||
|
{
|
||||||
|
Name: "node1",
|
||||||
|
Score: MinNodeScore - 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "node2",
|
||||||
|
Score: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
err: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -61,6 +62,14 @@ const (
|
|||||||
Skip
|
Skip
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// MaxNodeScore is the maximum score a Score plugin is expected to return.
|
||||||
|
MaxNodeScore int = schedulerapi.MaxPriority
|
||||||
|
|
||||||
|
// MinNodeScore is the minimum score a Score plugin is expected to return.
|
||||||
|
MinNodeScore int = 0
|
||||||
|
)
|
||||||
|
|
||||||
// Status indicates the result of running a plugin. It consists of a code and a
|
// Status indicates the result of running a plugin. It consists of a code and a
|
||||||
// message. When the status code is not `Success`, the status message should
|
// message. When the status code is not `Success`, the status message should
|
||||||
// explain why.
|
// explain why.
|
||||||
|
@ -152,11 +152,11 @@ func (sp *ScorePlugin) Score(pc *framework.PluginContext, p *v1.Pod, nodeName st
|
|||||||
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", p.Name))
|
return 0, framework.NewStatus(framework.Error, fmt.Sprintf("injecting failure for pod %v", p.Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
score := 10
|
score := 1
|
||||||
if sp.numScoreCalled == 1 {
|
if sp.numScoreCalled == 1 {
|
||||||
// The first node is scored the highest, the rest is scored lower.
|
// The first node is scored the highest, the rest is scored lower.
|
||||||
sp.highScoreNode = nodeName
|
sp.highScoreNode = nodeName
|
||||||
score = 100
|
score = framework.MaxNodeScore
|
||||||
}
|
}
|
||||||
return score, nil
|
return score, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user