...
1
16
17 package noderesources
18
19 import (
20 "math"
21
22 "k8s.io/kubernetes/pkg/scheduler/apis/config"
23 "k8s.io/kubernetes/pkg/scheduler/framework"
24 "k8s.io/kubernetes/pkg/scheduler/framework/plugins/helper"
25 )
26
27 const maxUtilization = 100
28
29
30
31 func buildRequestedToCapacityRatioScorerFunction(scoringFunctionShape helper.FunctionShape, resources []config.ResourceSpec) func([]int64, []int64) int64 {
32 rawScoringFunction := helper.BuildBrokenLinearFunction(scoringFunctionShape)
33 resourceScoringFunction := func(requested, capacity int64) int64 {
34 if capacity == 0 || requested > capacity {
35 return rawScoringFunction(maxUtilization)
36 }
37
38 return rawScoringFunction(requested * maxUtilization / capacity)
39 }
40 return func(requested, allocable []int64) int64 {
41 var nodeScore, weightSum int64
42 for i := range requested {
43 if allocable[i] == 0 {
44 continue
45 }
46 weight := resources[i].Weight
47 resourceScore := resourceScoringFunction(requested[i], allocable[i])
48 if resourceScore > 0 {
49 nodeScore += resourceScore * weight
50 weightSum += weight
51 }
52 }
53 if weightSum == 0 {
54 return 0
55 }
56 return int64(math.Round(float64(nodeScore) / float64(weightSum)))
57 }
58 }
59
60 func requestedToCapacityRatioScorer(resources []config.ResourceSpec, shape []config.UtilizationShapePoint) func([]int64, []int64) int64 {
61 shapes := make([]helper.FunctionShapePoint, 0, len(shape))
62 for _, point := range shape {
63 shapes = append(shapes, helper.FunctionShapePoint{
64 Utilization: int64(point.Utilization),
65
66
67
68 Score: int64(point.Score) * (framework.MaxNodeScore / config.MaxCustomPriorityScore),
69 })
70 }
71
72 return buildRequestedToCapacityRatioScorerFunction(shapes, resources)
73 }
74
View as plain text