mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
feat(scheduler): return error when score is out of range
This commit is contained in:
parent
34791349d6
commit
9fb0df5096
@ -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 {
|
||||||
|
@ -61,6 +61,14 @@ const (
|
|||||||
Skip
|
Skip
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// MaxNodeScore is the maximum score a Score plugin is expected to return.
|
||||||
|
MaxNodeScore int = 10
|
||||||
|
|
||||||
|
// 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