...
1
16
17 package volumebinding
18
19 import (
20 "math"
21
22 "k8s.io/kubernetes/pkg/scheduler/framework/plugins/helper"
23 )
24
25
26 type classResourceMap map[string]*StorageResource
27
28
29 type volumeCapacityScorer func(classResourceMap) int64
30
31
32 func buildScorerFunction(scoringFunctionShape helper.FunctionShape) volumeCapacityScorer {
33 rawScoringFunction := helper.BuildBrokenLinearFunction(scoringFunctionShape)
34 f := func(requested, capacity int64) int64 {
35 if capacity == 0 || requested > capacity {
36 return rawScoringFunction(maxUtilization)
37 }
38
39 return rawScoringFunction(requested * maxUtilization / capacity)
40 }
41 return func(classResources classResourceMap) int64 {
42 var nodeScore int64
43
44 weightSum := len(classResources)
45 if weightSum == 0 {
46 return 0
47 }
48 for _, resource := range classResources {
49 classScore := f(resource.Requested, resource.Capacity)
50 nodeScore += classScore
51 }
52 return int64(math.Round(float64(nodeScore) / float64(weightSum)))
53 }
54 }
55
View as plain text