mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #84948 from zouyee/PriorityFunction
clean up PriorityFunction
This commit is contained in:
commit
82600c2b0e
@ -409,9 +409,8 @@ func TestBalancedResourceAllocation(t *testing.T) {
|
|||||||
info.TransientInfo.TransNodeInfo.RequestedVolumes = len(test.pod.Spec.Volumes)
|
info.TransientInfo.TransNodeInfo.RequestedVolumes = len(test.pod.Spec.Volumes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function := priorityFunction(BalancedResourceAllocationMap, nil, nil)
|
|
||||||
|
|
||||||
list, err := function(test.pod, snapshot, test.nodes)
|
list, err := runMapReducePriority(BalancedResourceAllocationMap, nil, nil, test.pod, snapshot, test.nodes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -185,7 +185,7 @@ func TestImageLocalityPriority(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
|
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
|
||||||
list, err := priorityFunction(ImageLocalityPriorityMap, nil, &priorityMetadata{totalNumNodes: len(test.nodes)})(test.pod, snapshot, test.nodes)
|
list, err := runMapReducePriority(ImageLocalityPriorityMap, nil, &priorityMetadata{totalNumNodes: len(test.nodes)}, test.pod, snapshot, test.nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ func TestLeastRequested(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
|
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
|
||||||
list, err := priorityFunction(LeastRequestedPriorityMap, nil, nil)(test.pod, snapshot, test.nodes)
|
list, err := runMapReducePriority(LeastRequestedPriorityMap, nil, nil, test.pod, snapshot, test.nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ func TestMostRequested(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
|
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
|
||||||
list, err := priorityFunction(MostRequestedPriorityMap, nil, nil)(test.pod, snapshot, test.nodes)
|
list, err := runMapReducePriority(MostRequestedPriorityMap, nil, nil, test.pod, snapshot, test.nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -168,8 +168,7 @@ func TestNodeAffinityPriority(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
snapshot := nodeinfosnapshot.NewSnapshot(nil, test.nodes)
|
snapshot := nodeinfosnapshot.NewSnapshot(nil, test.nodes)
|
||||||
nap := priorityFunction(CalculateNodeAffinityPriorityMap, CalculateNodeAffinityPriorityReduce, nil)
|
list, err := runMapReducePriority(CalculateNodeAffinityPriorityMap, CalculateNodeAffinityPriorityReduce, nil, test.pod, snapshot, test.nodes)
|
||||||
list, err := nap(test.pod, snapshot, test.nodes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func TestNodePreferAvoidPriority(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
snapshot := nodeinfosnapshot.NewSnapshot(nil, test.nodes)
|
snapshot := nodeinfosnapshot.NewSnapshot(nil, test.nodes)
|
||||||
list, err := priorityFunction(CalculateNodePreferAvoidPodsPriorityMap, nil, nil)(test.pod, snapshot, test.nodes)
|
list, err := runMapReducePriority(CalculateNodePreferAvoidPodsPriorityMap, nil, nil, test.pod, snapshot, test.nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ func TestRequestedToCapacityRatio(t *testing.T) {
|
|||||||
newPod := buildResourcesPod("", test.requested)
|
newPod := buildResourcesPod("", test.requested)
|
||||||
|
|
||||||
snapshot := nodeinfosnapshot.NewSnapshot(scheduledPods, nodes)
|
snapshot := nodeinfosnapshot.NewSnapshot(scheduledPods, nodes)
|
||||||
list, err := priorityFunction(RequestedToCapacityRatioResourceAllocationPriorityDefault().PriorityMap, nil, nil)(newPod, snapshot, nodes)
|
list, err := runMapReducePriority(RequestedToCapacityRatioResourceAllocationPriorityDefault().PriorityMap, nil, nil, newPod, snapshot, nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -390,7 +390,7 @@ func TestResourceBinPackingSingleExtended(t *testing.T) {
|
|||||||
functionShape, _ := NewFunctionShape([]FunctionShapePoint{{0, 0}, {100, 10}})
|
functionShape, _ := NewFunctionShape([]FunctionShapePoint{{0, 0}, {100, 10}})
|
||||||
resourceToWeightMap := ResourceToWeightMap{v1.ResourceName("intel.com/foo"): 1}
|
resourceToWeightMap := ResourceToWeightMap{v1.ResourceName("intel.com/foo"): 1}
|
||||||
prior := RequestedToCapacityRatioResourceAllocationPriority(functionShape, resourceToWeightMap)
|
prior := RequestedToCapacityRatioResourceAllocationPriority(functionShape, resourceToWeightMap)
|
||||||
list, err := priorityFunction(prior.PriorityMap, nil, nil)(test.pod, snapshot, test.nodes)
|
list, err := runMapReducePriority(prior.PriorityMap, nil, nil, test.pod, snapshot, test.nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -615,7 +615,7 @@ func TestResourceBinPackingMultipleExtended(t *testing.T) {
|
|||||||
functionShape, _ := NewFunctionShape([]FunctionShapePoint{{0, 0}, {100, 10}})
|
functionShape, _ := NewFunctionShape([]FunctionShapePoint{{0, 0}, {100, 10}})
|
||||||
resourceToWeightMap := ResourceToWeightMap{v1.ResourceName("intel.com/foo"): 3, v1.ResourceName("intel.com/bar"): 5}
|
resourceToWeightMap := ResourceToWeightMap{v1.ResourceName("intel.com/foo"): 3, v1.ResourceName("intel.com/bar"): 5}
|
||||||
prior := RequestedToCapacityRatioResourceAllocationPriority(functionShape, resourceToWeightMap)
|
prior := RequestedToCapacityRatioResourceAllocationPriority(functionShape, resourceToWeightMap)
|
||||||
list, err := priorityFunction(prior.PriorityMap, nil, nil)(test.pod, snapshot, test.nodes)
|
list, err := runMapReducePriority(prior.PriorityMap, nil, nil, test.pod, snapshot, test.nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ package priorities
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ func ResourceLimitsPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *schedule
|
|||||||
|
|
||||||
// compute pod limits
|
// compute pod limits
|
||||||
var podLimits *schedulernodeinfo.Resource
|
var podLimits *schedulernodeinfo.Resource
|
||||||
if priorityMeta, ok := meta.(*priorityMetadata); ok {
|
if priorityMeta, ok := meta.(*priorityMetadata); ok && priorityMeta != nil {
|
||||||
// We were able to parse metadata, use podLimits from there.
|
// We were able to parse metadata, use podLimits from there.
|
||||||
podLimits = priorityMeta.podLimits
|
podLimits = priorityMeta.podLimits
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
nodeinfosnapshot "k8s.io/kubernetes/pkg/scheduler/nodeinfo/snapshot"
|
nodeinfosnapshot "k8s.io/kubernetes/pkg/scheduler/nodeinfo/snapshot"
|
||||||
@ -144,14 +144,12 @@ func TestResourceLimitsPriority(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, hasMeta := range []bool{true, false} {
|
for _, hasMeta := range []bool{true, false} {
|
||||||
var function PriorityFunction
|
meta := metadata
|
||||||
if hasMeta {
|
if !hasMeta {
|
||||||
function = priorityFunction(ResourceLimitsPriorityMap, nil, metadata)
|
meta = nil
|
||||||
} else {
|
|
||||||
function = priorityFunction(ResourceLimitsPriorityMap, nil, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := function(test.pod, snapshot, test.nodes)
|
list, err := runMapReducePriority(ResourceLimitsPriorityMap, nil, meta, test.pod, snapshot, test.nodes)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
|
@ -355,8 +355,7 @@ func TestSelectorSpreadPriority(t *testing.T) {
|
|||||||
)
|
)
|
||||||
metaData := metaDataProducer(test.pod, nodes, snapshot)
|
metaData := metaDataProducer(test.pod, nodes, snapshot)
|
||||||
|
|
||||||
ttp := priorityFunction(selectorSpread.CalculateSpreadPriorityMap, selectorSpread.CalculateSpreadPriorityReduce, metaData)
|
list, err := runMapReducePriority(selectorSpread.CalculateSpreadPriorityMap, selectorSpread.CalculateSpreadPriorityReduce, metaData, test.pod, snapshot, makeNodeList(test.nodes))
|
||||||
list, err := ttp(test.pod, snapshot, makeNodeList(test.nodes))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v \n", err)
|
t.Errorf("unexpected error: %v \n", err)
|
||||||
}
|
}
|
||||||
@ -593,8 +592,7 @@ func TestZoneSelectorSpreadPriority(t *testing.T) {
|
|||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
metaData := metaDataProducer(test.pod, nodes, snapshot)
|
metaData := metaDataProducer(test.pod, nodes, snapshot)
|
||||||
ttp := priorityFunction(selectorSpread.CalculateSpreadPriorityMap, selectorSpread.CalculateSpreadPriorityReduce, metaData)
|
list, err := runMapReducePriority(selectorSpread.CalculateSpreadPriorityMap, selectorSpread.CalculateSpreadPriorityReduce, metaData, test.pod, snapshot, makeLabeledNodeList(labeledNodes))
|
||||||
list, err := ttp(test.pod, snapshot, makeLabeledNodeList(labeledNodes))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
@ -783,8 +781,7 @@ func TestZoneSpreadPriority(t *testing.T) {
|
|||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
metaData := metaDataProducer(test.pod, nodes, snapshot)
|
metaData := metaDataProducer(test.pod, nodes, snapshot)
|
||||||
ttp := priorityFunction(zoneSpread.CalculateAntiAffinityPriorityMap, zoneSpread.CalculateAntiAffinityPriorityReduce, metaData)
|
list, err := runMapReducePriority(zoneSpread.CalculateAntiAffinityPriorityMap, zoneSpread.CalculateAntiAffinityPriorityReduce, metaData, test.pod, snapshot, makeLabeledNodeList(test.nodes))
|
||||||
list, err := ttp(test.pod, snapshot, makeLabeledNodeList(test.nodes))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,7 @@ func BenchmarkTestSelectorSpreadPriority(b *testing.B) {
|
|||||||
meta := &priorityMetadata{
|
meta := &priorityMetadata{
|
||||||
podSelectors: getSelectors(pod, ss.serviceLister, ss.controllerLister, ss.replicaSetLister, ss.statefulSetLister),
|
podSelectors: getSelectors(pod, ss.serviceLister, ss.controllerLister, ss.replicaSetLister, ss.statefulSetLister),
|
||||||
}
|
}
|
||||||
ttp := priorityFunction(ss.CalculateSpreadPriorityMap, ss.CalculateSpreadPriorityReduce, meta)
|
_, err := runMapReducePriority(ss.CalculateSpreadPriorityMap, ss.CalculateSpreadPriorityReduce, meta, pod, snapshot, filteredNodes)
|
||||||
_, err := ttp(pod, snapshot, filteredNodes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -228,8 +228,7 @@ func TestTaintAndToleration(t *testing.T) {
|
|||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(test.name, func(t *testing.T) {
|
||||||
snapshot := nodeinfosnapshot.NewSnapshot(nil, test.nodes)
|
snapshot := nodeinfosnapshot.NewSnapshot(nil, test.nodes)
|
||||||
ttp := priorityFunction(ComputeTaintTolerationPriorityMap, ComputeTaintTolerationPriorityReduce, nil)
|
list, err := runMapReducePriority(ComputeTaintTolerationPriorityMap, ComputeTaintTolerationPriorityReduce, nil, test.pod, snapshot, test.nodes)
|
||||||
list, err := ttp(test.pod, snapshot, test.nodes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ package priorities
|
|||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
@ -58,27 +58,25 @@ func makeNodeWithExtendedResource(node string, milliCPU, memory int64, extendedR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func priorityFunction(mapFn PriorityMapFunction, reduceFn PriorityReduceFunction, metaData interface{}) PriorityFunction {
|
func runMapReducePriority(mapFn PriorityMapFunction, reduceFn PriorityReduceFunction, metaData interface{}, pod *v1.Pod, sharedLister schedulerlisters.SharedLister, nodes []*v1.Node) (framework.NodeScoreList, error) {
|
||||||
return func(pod *v1.Pod, sharedLister schedulerlisters.SharedLister, nodes []*v1.Node) (framework.NodeScoreList, error) {
|
result := make(framework.NodeScoreList, 0, len(nodes))
|
||||||
result := make(framework.NodeScoreList, 0, len(nodes))
|
for i := range nodes {
|
||||||
for i := range nodes {
|
nodeInfo, err := sharedLister.NodeInfos().Get(nodes[i].Name)
|
||||||
nodeInfo, err := sharedLister.NodeInfos().Get(nodes[i].Name)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
hostResult, err := mapFn(pod, metaData, nodeInfo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result = append(result, hostResult)
|
|
||||||
}
|
}
|
||||||
if reduceFn != nil {
|
hostResult, err := mapFn(pod, metaData, nodeInfo)
|
||||||
if err := reduceFn(pod, metaData, sharedLister, result); err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result, nil
|
result = append(result, hostResult)
|
||||||
}
|
}
|
||||||
|
if reduceFn != nil {
|
||||||
|
if err := reduceFn(pod, metaData, sharedLister, result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortNodeScoreList(out framework.NodeScoreList) {
|
func sortNodeScoreList(out framework.NodeScoreList) {
|
||||||
|
@ -38,11 +38,6 @@ type PriorityReduceFunction func(pod *v1.Pod, meta interface{}, sharedLister sch
|
|||||||
// is now used for only for priority functions. For predicates please use PredicateMetadataProducer.
|
// is now used for only for priority functions. For predicates please use PredicateMetadataProducer.
|
||||||
type PriorityMetadataProducer func(pod *v1.Pod, filteredNodes []*v1.Node, sharedLister schedulerlisters.SharedLister) interface{}
|
type PriorityMetadataProducer func(pod *v1.Pod, filteredNodes []*v1.Node, sharedLister schedulerlisters.SharedLister) interface{}
|
||||||
|
|
||||||
// PriorityFunction is a function that computes scores for all nodes.
|
|
||||||
// DEPRECATED
|
|
||||||
// Use Map-Reduce pattern for priority functions.
|
|
||||||
type PriorityFunction func(pod *v1.Pod, sharedLister schedulerlisters.SharedLister, nodes []*v1.Node) (framework.NodeScoreList, error)
|
|
||||||
|
|
||||||
// PriorityConfig is a config used for a priority function.
|
// PriorityConfig is a config used for a priority function.
|
||||||
type PriorityConfig struct {
|
type PriorityConfig struct {
|
||||||
Name string
|
Name string
|
||||||
|
@ -70,19 +70,13 @@ type PredicateMetadataProducerFactory func(PluginFactoryArgs) predicates.Predica
|
|||||||
// FitPredicateFactory produces a FitPredicate from the given args.
|
// FitPredicateFactory produces a FitPredicate from the given args.
|
||||||
type FitPredicateFactory func(PluginFactoryArgs) predicates.FitPredicate
|
type FitPredicateFactory func(PluginFactoryArgs) predicates.FitPredicate
|
||||||
|
|
||||||
// PriorityFunctionFactory produces a PriorityConfig from the given args.
|
// PriorityFunctionFactory produces map & reduce priority functions
|
||||||
// DEPRECATED
|
|
||||||
// Use Map-Reduce pattern for priority functions.
|
|
||||||
type PriorityFunctionFactory func(PluginFactoryArgs) priorities.PriorityFunction
|
|
||||||
|
|
||||||
// PriorityFunctionFactory2 produces map & reduce priority functions
|
|
||||||
// from a given args.
|
// from a given args.
|
||||||
// FIXME: Rename to PriorityFunctionFactory.
|
type PriorityFunctionFactory func(PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction)
|
||||||
type PriorityFunctionFactory2 func(PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction)
|
|
||||||
|
|
||||||
// PriorityConfigFactory produces a PriorityConfig from the given function and weight
|
// PriorityConfigFactory produces a PriorityConfig from the given function and weight
|
||||||
type PriorityConfigFactory struct {
|
type PriorityConfigFactory struct {
|
||||||
MapReduceFunction PriorityFunctionFactory2
|
MapReduceFunction PriorityFunctionFactory
|
||||||
Weight int64
|
Weight int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user