mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Use maxSkew in PodTopologySpread scoring as tolerance to skew
This new approach results in better spreading for small number of pods, while still giving meaning to the maxSkew parameter. Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
parent
a36b9a9922
commit
d353cc1532
@ -200,8 +200,7 @@ func (pl *PodTopologySpread) Score(ctx context.Context, cycleState *framework.Cy
|
||||
pair := topologyPair{key: c.TopologyKey, value: tpVal}
|
||||
cnt = *s.TopologyPairToPodCounts[pair]
|
||||
}
|
||||
cnt = adjustForMaxSkew(cnt, int64(c.MaxSkew))
|
||||
score += float64(cnt) * s.TopologyNormalizingWeight[i]
|
||||
score += scoreForCount(cnt, c.MaxSkew, s.TopologyNormalizingWeight[i])
|
||||
}
|
||||
}
|
||||
return int64(score), nil
|
||||
@ -287,13 +286,10 @@ func topologyNormalizingWeight(size int) float64 {
|
||||
return math.Log(float64(size + 2))
|
||||
}
|
||||
|
||||
// adjustForMaxSkew adjusts the number of matching pods in a topology domain
|
||||
// using the constraint's maxSkew.
|
||||
// Topology domains with less than maxSkew number of pods are considered to have
|
||||
// the same priority.
|
||||
func adjustForMaxSkew(cnt, maxSkew int64) int64 {
|
||||
if cnt < maxSkew {
|
||||
return maxSkew - 1
|
||||
}
|
||||
return cnt
|
||||
// scoreForCount calculates the score based on number of matching pods in a
|
||||
// topology domain, the constraint's maxSkew and the topology weight.
|
||||
// `maxSkew-1` is added to the score so that differences between topology
|
||||
// domains get watered down, controlling the tolerance of the score to skews.
|
||||
func scoreForCount(cnt int64, maxSkew int32, tpWeight float64) float64 {
|
||||
return float64(cnt)*tpWeight + float64(maxSkew-1)
|
||||
}
|
||||
|
@ -315,12 +315,11 @@ func TestPodTopologySpreadScore(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{
|
||||
// matching pods spread as 2/1/0/3.
|
||||
// With maxSkew=2, counts change internally to 2/1/1/3.
|
||||
name: "one constraint on node, all 4 nodes are candidates, maxSkew=2",
|
||||
pod: st.MakePod().Name("p").Label("foo", "").
|
||||
SpreadConstraint(2, v1.LabelHostname, v1.ScheduleAnyway, st.MakeLabelSelector().Exists("foo").Obj()).
|
||||
Obj(),
|
||||
// matching pods spread as 2/1/0/3.
|
||||
existingPods: []*v1.Pod{
|
||||
st.MakePod().Name("p-a1").Node("node-a").Label("foo", "").Obj(),
|
||||
st.MakePod().Name("p-a2").Node("node-a").Label("foo", "").Obj(),
|
||||
@ -337,20 +336,19 @@ func TestPodTopologySpreadScore(t *testing.T) {
|
||||
},
|
||||
failedNodes: []*v1.Node{},
|
||||
want: []framework.NodeScore{
|
||||
{Name: "node-a", Score: 60}, // +20, compared to maxSkew=1
|
||||
{Name: "node-b", Score: 100}, // +20, compared to maxSkew=1
|
||||
{Name: "node-a", Score: 50}, // +10, compared to maxSkew=1
|
||||
{Name: "node-b", Score: 83}, // +3, compared to maxSkew=1
|
||||
{Name: "node-c", Score: 100},
|
||||
{Name: "node-d", Score: 20}, // +20, compared to maxSkew=1
|
||||
{Name: "node-d", Score: 16}, // +16, compared to maxSkew=1
|
||||
},
|
||||
},
|
||||
{
|
||||
// matching pods spread as 4/3/2/1.
|
||||
// With maxSkew=3, counts change internally to 4/3/2/2.
|
||||
name: "one constraint on node, all 4 nodes are candidates, maxSkew=3",
|
||||
pod: st.MakePod().Name("p").Label("foo", "").
|
||||
SpreadConstraint(3, v1.LabelHostname, v1.ScheduleAnyway, st.MakeLabelSelector().Exists("foo").Obj()).
|
||||
Obj(),
|
||||
existingPods: []*v1.Pod{
|
||||
// matching pods spread as 4/3/2/1.
|
||||
st.MakePod().Name("p-a1").Node("node-a").Label("foo", "").Obj(),
|
||||
st.MakePod().Name("p-a2").Node("node-a").Label("foo", "").Obj(),
|
||||
st.MakePod().Name("p-a3").Node("node-a").Label("foo", "").Obj(),
|
||||
@ -370,9 +368,9 @@ func TestPodTopologySpreadScore(t *testing.T) {
|
||||
},
|
||||
failedNodes: []*v1.Node{},
|
||||
want: []framework.NodeScore{
|
||||
{Name: "node-a", Score: 42}, // +28 compared to maxSkew=1
|
||||
{Name: "node-b", Score: 71}, // +29 compared to maxSkew=1
|
||||
{Name: "node-c", Score: 100}, // +29 compared to maxSkew=1
|
||||
{Name: "node-a", Score: 33}, // +19 compared to maxSkew=1
|
||||
{Name: "node-b", Score: 55}, // +13 compared to maxSkew=1
|
||||
{Name: "node-c", Score: 77}, // +6 compared to maxSkew=1
|
||||
{Name: "node-d", Score: 100},
|
||||
},
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user