Commit b6c25b23 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #32486 from wojtek-t/scheduler_map_reduce_2

Automatic merge from submit-queue Migrate a bunch of priority functions to map-reduce framework Ref #24246
parents 61ba82c6 ea943d82
...@@ -295,8 +295,7 @@ func TestLeastRequested(t *testing.T) { ...@@ -295,8 +295,7 @@ func TestLeastRequested(t *testing.T) {
for _, test := range tests { for _, test := range tests {
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, test.nodes) nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, test.nodes)
lrp := priorityFunction(LeastRequestedPriorityMap, nil) list, err := priorityFunction(LeastRequestedPriorityMap, nil)(test.pod, nodeNameToInfo, test.nodes)
list, err := lrp(test.pod, nodeNameToInfo, test.nodes)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -451,7 +450,7 @@ func TestMostRequested(t *testing.T) { ...@@ -451,7 +450,7 @@ func TestMostRequested(t *testing.T) {
for _, test := range tests { for _, test := range tests {
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, test.nodes) nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, test.nodes)
list, err := MostRequestedPriority(test.pod, nodeNameToInfo, test.nodes) list, err := priorityFunction(MostRequestedPriorityMap, nil)(test.pod, nodeNameToInfo, test.nodes)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -541,11 +540,8 @@ func TestNewNodeLabelPriority(t *testing.T) { ...@@ -541,11 +540,8 @@ func TestNewNodeLabelPriority(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
prioritizer := NodeLabelPrioritizer{ nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(nil, test.nodes)
label: test.label, list, err := priorityFunction(NewNodeLabelPriority(test.label, test.presence))(nil, nodeNameToInfo, test.nodes)
presence: test.presence,
}
list, err := prioritizer.CalculateNodeLabelPriority(nil, map[string]*schedulercache.NodeInfo{}, test.nodes)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -784,7 +780,7 @@ func TestBalancedResourceAllocation(t *testing.T) { ...@@ -784,7 +780,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
for _, test := range tests { for _, test := range tests {
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, test.nodes) nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, test.nodes)
list, err := BalancedResourceAllocation(test.pod, nodeNameToInfo, test.nodes) list, err := priorityFunction(BalancedResourceAllocationMap, nil)(test.pod, nodeNameToInfo, test.nodes)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -928,7 +924,7 @@ func TestImageLocalityPriority(t *testing.T) { ...@@ -928,7 +924,7 @@ func TestImageLocalityPriority(t *testing.T) {
for _, test := range tests { for _, test := range tests {
nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, test.nodes) nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(test.pods, test.nodes)
list, err := ImageLocalityPriority(test.pod, nodeNameToInfo, test.nodes) list, err := priorityFunction(ImageLocalityPriorityMap, nil)(test.pod, nodeNameToInfo, test.nodes)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
...@@ -1152,7 +1148,8 @@ func TestNodePreferAvoidPriority(t *testing.T) { ...@@ -1152,7 +1148,8 @@ func TestNodePreferAvoidPriority(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
list, err := CalculateNodePreferAvoidPodsPriority(test.pod, map[string]*schedulercache.NodeInfo{}, test.nodes) nodeNameToInfo := schedulercache.CreateNodeNameToInfoMap(nil, test.nodes)
list, err := priorityFunction(CalculateNodePreferAvoidPodsPriorityMap, nil)(test.pod, nodeNameToInfo, test.nodes)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
......
...@@ -82,7 +82,7 @@ func init() { ...@@ -82,7 +82,7 @@ func init() {
// ImageLocalityPriority prioritizes nodes based on locality of images requested by a pod. Nodes with larger size // ImageLocalityPriority prioritizes nodes based on locality of images requested by a pod. Nodes with larger size
// of already-installed packages required by the pod will be preferred over nodes with no already-installed // of already-installed packages required by the pod will be preferred over nodes with no already-installed
// packages required by the pod or a small total size of already-installed packages required by the pod. // packages required by the pod or a small total size of already-installed packages required by the pod.
factory.RegisterPriorityFunction("ImageLocalityPriority", priorities.ImageLocalityPriority, 1) factory.RegisterPriorityFunction2("ImageLocalityPriority", priorities.ImageLocalityPriorityMap, nil, 1)
// Fit is defined based on the absence of port conflicts. // Fit is defined based on the absence of port conflicts.
// This predicate is actually a default predicate, because it is invoked from // This predicate is actually a default predicate, because it is invoked from
// predicates.GeneralPredicates() // predicates.GeneralPredicates()
...@@ -98,7 +98,7 @@ func init() { ...@@ -98,7 +98,7 @@ func init() {
// Fit is determined by node selector query. // Fit is determined by node selector query.
factory.RegisterFitPredicate("MatchNodeSelector", predicates.PodSelectorMatches) factory.RegisterFitPredicate("MatchNodeSelector", predicates.PodSelectorMatches)
// Optional, cluster-autoscaler friendly priority function - give used nodes higher priority. // Optional, cluster-autoscaler friendly priority function - give used nodes higher priority.
factory.RegisterPriorityFunction("MostRequestedPriority", priorities.MostRequestedPriority, 1) factory.RegisterPriorityFunction2("MostRequestedPriority", priorities.MostRequestedPriorityMap, nil, 1)
} }
func replace(set sets.String, replaceWhat, replaceWith string) sets.String { func replace(set sets.String, replaceWhat, replaceWith string) sets.String {
...@@ -167,7 +167,7 @@ func defaultPriorities() sets.String { ...@@ -167,7 +167,7 @@ func defaultPriorities() sets.String {
// Prioritize nodes by least requested utilization. // Prioritize nodes by least requested utilization.
factory.RegisterPriorityFunction2("LeastRequestedPriority", priorities.LeastRequestedPriorityMap, nil, 1), factory.RegisterPriorityFunction2("LeastRequestedPriority", priorities.LeastRequestedPriorityMap, nil, 1),
// Prioritizes nodes to help achieve balanced resource usage // Prioritizes nodes to help achieve balanced resource usage
factory.RegisterPriorityFunction("BalancedResourceAllocation", priorities.BalancedResourceAllocation, 1), factory.RegisterPriorityFunction2("BalancedResourceAllocation", priorities.BalancedResourceAllocationMap, nil, 1),
// spreads pods by minimizing the number of pods (belonging to the same service or replication controller) on the same node. // spreads pods by minimizing the number of pods (belonging to the same service or replication controller) on the same node.
factory.RegisterPriorityConfigFactory( factory.RegisterPriorityConfigFactory(
"SelectorSpreadPriority", "SelectorSpreadPriority",
...@@ -180,7 +180,7 @@ func defaultPriorities() sets.String { ...@@ -180,7 +180,7 @@ func defaultPriorities() sets.String {
), ),
// Set this weight large enough to override all other priority functions. // Set this weight large enough to override all other priority functions.
// TODO: Figure out a better way to do this, maybe at same time as fixing #24720. // TODO: Figure out a better way to do this, maybe at same time as fixing #24720.
factory.RegisterPriorityFunction("NodePreferAvoidPodsPriority", priorities.CalculateNodePreferAvoidPodsPriority, 10000), factory.RegisterPriorityFunction2("NodePreferAvoidPodsPriority", priorities.CalculateNodePreferAvoidPodsPriorityMap, nil, 10000),
factory.RegisterPriorityFunction("NodeAffinityPriority", priorities.CalculateNodeAffinityPriority, 1), factory.RegisterPriorityFunction("NodeAffinityPriority", priorities.CalculateNodeAffinityPriority, 1),
factory.RegisterPriorityFunction("TaintTolerationPriority", priorities.ComputeTaintTolerationPriority, 1), factory.RegisterPriorityFunction("TaintTolerationPriority", priorities.ComputeTaintTolerationPriority, 1),
// pods should be placed in the same topological domain (e.g. same node, same rack, same zone, same power domain, etc.) // pods should be placed in the same topological domain (e.g. same node, same rack, same zone, same power domain, etc.)
......
...@@ -206,7 +206,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string { ...@@ -206,7 +206,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
} }
} else if policy.Argument.LabelPreference != nil { } else if policy.Argument.LabelPreference != nil {
pcf = &PriorityConfigFactory{ pcf = &PriorityConfigFactory{
Function: func(args PluginFactoryArgs) algorithm.PriorityFunction { MapReduceFunction: func(args PluginFactoryArgs) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
return priorities.NewNodeLabelPriority( return priorities.NewNodeLabelPriority(
policy.Argument.LabelPreference.Label, policy.Argument.LabelPreference.Label,
policy.Argument.LabelPreference.Presence, policy.Argument.LabelPreference.Presence,
......
...@@ -489,7 +489,7 @@ func TestZeroRequest(t *testing.T) { ...@@ -489,7 +489,7 @@ func TestZeroRequest(t *testing.T) {
// to test what's actually in production. // to test what's actually in production.
priorityConfigs := []algorithm.PriorityConfig{ priorityConfigs := []algorithm.PriorityConfig{
{Map: algorithmpriorities.LeastRequestedPriorityMap, Weight: 1}, {Map: algorithmpriorities.LeastRequestedPriorityMap, Weight: 1},
{Function: algorithmpriorities.BalancedResourceAllocation, Weight: 1}, {Map: algorithmpriorities.BalancedResourceAllocationMap, Weight: 1},
{ {
Function: algorithmpriorities.NewSelectorSpreadPriority( Function: algorithmpriorities.NewSelectorSpreadPriority(
algorithm.FakePodLister(test.pods), algorithm.FakePodLister(test.pods),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment