From 3cbd7d528d259424014cbf54ffa941a8ec3f8d74 Mon Sep 17 00:00:00 2001 From: draveness Date: Mon, 19 Aug 2019 14:37:34 +0800 Subject: [PATCH] fix: reword score section in the scheduling framework --- .../20180409-scheduling-framework.md | 52 +++++-------------- 1 file changed, 12 insertions(+), 40 deletions(-) diff --git a/keps/sig-scheduling/20180409-scheduling-framework.md b/keps/sig-scheduling/20180409-scheduling-framework.md index 94d067529bbc..8fe45ad77f54 100644 --- a/keps/sig-scheduling/20180409-scheduling-framework.md +++ b/keps/sig-scheduling/20180409-scheduling-framework.md @@ -206,9 +206,12 @@ each node. the scheduler computes a final ranking of Nodes, and each score plugin receives scores given by the same plugin to all nodes in "normalize scoring" phase. `NormalizeScore` is called once per plugin per scheduling cycle right after -"score" phase. After the "normalize scoring" phase, it will return a well defined -range of integers `[0, 100]`, the scheduler will combine node scores from all -plugins according to the configured plugin weights. +"score" phase. + +The output of a score plugin must be an integer in range of +**[NodeScoreMin, NodeScoreMax]**. if not, the scheduling cycle is aborted. +This is the output after running the optional NormalizeScore function of the +plugin. If NormalizeScore is not provided, the output of Score must be in this range For example, suppose a plugin `BlinkingLightScorer` ranks Nodes based on how many blinking lights they have. @@ -223,50 +226,19 @@ However, the maximum count of blinking lights may be small compared to `NodeScoreMax`. To fix this, `BlinkingLightScorer` should also implement `NormalizeScore`. ```go -func (*BlinkingLightScorer) NormalizeScore(pc *PluginContext, _ *v1.Pod, scores NodeScoreList) *Status { +func (*BlinkingLightScorer) NormalizeScore(pc *PluginContext, _ *v1.Pod, nodeScores NodeScoreList) *Status { highest := 0 - for _, score := range scores { - highest = max(highest, score) + for _, nodeScore := range nodeScores { + highest = max(highest, nodeScore.Score) } - for node, score := range scores { - scores[node] = score*NodeScoreMax/highest + for i, nodeScore := range nodeScores { + nodeScores[i].Score = nodeScore.Score*NodeScoreMax/highest } return nil } ``` -If `NormalizeScore` returns an error, the scheduling cycle is aborted. The -scheduler would use a default normalize score strategy if the user does not -provide one. - -```go -func DefaultNormalizeScore(pc *PluginContext, scores NodeScoreList) { - minScore := math.MinInt - maxScore := math.MaxInt - - for _, score := range scores { - if minScore > score { - minScore = score - } - - if maxScore < score { - maxScore = score - } - } - - diff := maxScore - minScore - if diff == 0 { - for i := range scores { - scores[i] = 0 - } - return - } - - for i, score := range scores { - scores[i] = 100 * (score-minScore) / diff - } -} -``` +If `NormalizeScore` returns an error, the scheduling cycle is aborted. **Note:** Plugins wishing to perform "pre-reserve" work should use the `NormalizeScore` in the scoring extension point.