Merge pull request #101822 from yuzhiquan/NodeResourcesFit-score

Add score func for NodeResourcesFit plugin
This commit is contained in:
Kubernetes Prow Robot
2021-06-29 13:42:20 -07:00
committed by GitHub
32 changed files with 1107 additions and 537 deletions

View File

@@ -19,6 +19,7 @@ package noderesources
import (
v1 "k8s.io/api/core/v1"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework"
schedutil "k8s.io/kubernetes/pkg/scheduler/util"
)
@@ -26,6 +27,9 @@ import (
// resourceToWeightMap contains resource name and weight.
type resourceToWeightMap map[v1.ResourceName]int64
// scorer is decorator for resourceAllocationScorer
type scorer func(args *config.NodeResourcesFitArgs) *resourceAllocationScorer
// defaultRequestedRatioResources is used to set default requestToWeight map for CPU and memory
var defaultRequestedRatioResources = resourceToWeightMap{v1.ResourceMemory: 1, v1.ResourceCPU: 1}
@@ -132,3 +136,12 @@ func calculatePodResourceRequest(pod *v1.Pod, resource v1.ResourceName, enablePo
return podRequest
}
// resourcesToWeightMap make weightmap from resources spec
func resourcesToWeightMap(resources []config.ResourceSpec) resourceToWeightMap {
resourceToWeightMap := make(resourceToWeightMap)
for _, resource := range resources {
resourceToWeightMap[v1.ResourceName(resource.Name)] = resource.Weight
}
return resourceToWeightMap
}