From d6dab28b96ef177cb3a4080b15afce6f2dda907b Mon Sep 17 00:00:00 2001 From: Jerzy Szczepkowski Date: Fri, 7 Aug 2015 15:51:26 +0200 Subject: [PATCH] Revert "Move prioritizer function EqualPriority to package priorities" --- .../algorithm/priorities/priorities.go | 18 ---------------- .../algorithmprovider/defaults/defaults.go | 3 ++- plugin/pkg/scheduler/generic_scheduler.go | 21 +++++++++++++++++-- .../pkg/scheduler/generic_scheduler_test.go | 7 +++---- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/plugin/pkg/scheduler/algorithm/priorities/priorities.go b/plugin/pkg/scheduler/algorithm/priorities/priorities.go index 68a61f7cd75..58c61055146 100644 --- a/plugin/pkg/scheduler/algorithm/priorities/priorities.go +++ b/plugin/pkg/scheduler/algorithm/priorities/priorities.go @@ -245,21 +245,3 @@ func fractionOfCapacity(requested, capacity int64) float64 { } return float64(requested) / float64(capacity) } - -// EqualPriority is a prioritizer function that gives an equal score of one to all nodes -func EqualPriority(_ *api.Pod, podLister algorithm.PodLister, minionLister algorithm.MinionLister) (algorithm.HostPriorityList, error) { - nodes, err := minionLister.List() - if err != nil { - glog.Errorf("failed to list nodes: %v", err) - return []algorithm.HostPriority{}, err - } - - result := []algorithm.HostPriority{} - for _, minion := range nodes.Items { - result = append(result, algorithm.HostPriority{ - Host: minion.Name, - Score: 1, - }) - } - return result, nil -} diff --git a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go index 50d475e4781..30b3300576b 100644 --- a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go +++ b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go @@ -19,6 +19,7 @@ package defaults import ( "k8s.io/kubernetes/pkg/util" + "k8s.io/kubernetes/plugin/pkg/scheduler" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/predicates" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities" @@ -30,7 +31,7 @@ func init() { // EqualPriority is a prioritizer function that gives an equal weight of one to all minions // Register the priority function so that its available // but do not include it as part of the default priorities - factory.RegisterPriorityFunction("EqualPriority", priorities.EqualPriority, 1) + factory.RegisterPriorityFunction("EqualPriority", scheduler.EqualPriority, 1) } func defaultPredicates() util.StringSet { diff --git a/plugin/pkg/scheduler/generic_scheduler.go b/plugin/pkg/scheduler/generic_scheduler.go index 9b26f65bfe8..cf0eb213d26 100644 --- a/plugin/pkg/scheduler/generic_scheduler.go +++ b/plugin/pkg/scheduler/generic_scheduler.go @@ -28,7 +28,6 @@ import ( "k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/predicates" - "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities" ) type FailedPredicateMap map[string]util.StringSet @@ -149,7 +148,7 @@ func PrioritizeNodes(pod *api.Pod, podLister algorithm.PodLister, priorityConfig // If no priority configs are provided, then the EqualPriority function is applied // This is required to generate the priority list in the required format if len(priorityConfigs) == 0 { - return priorities.EqualPriority(pod, podLister, minionLister) + return EqualPriority(pod, podLister, minionLister) } combinedScores := map[string]int{} @@ -187,6 +186,24 @@ func getBestHosts(list algorithm.HostPriorityList) []string { return result } +// EqualPriority is a prioritizer function that gives an equal weight of one to all nodes +func EqualPriority(_ *api.Pod, podLister algorithm.PodLister, minionLister algorithm.MinionLister) (algorithm.HostPriorityList, error) { + nodes, err := minionLister.List() + if err != nil { + glog.Errorf("failed to list nodes: %v", err) + return []algorithm.HostPriority{}, err + } + + result := []algorithm.HostPriority{} + for _, minion := range nodes.Items { + result = append(result, algorithm.HostPriority{ + Host: minion.Name, + Score: 1, + }) + } + return result, nil +} + func NewGenericScheduler(predicates map[string]algorithm.FitPredicate, prioritizers []algorithm.PriorityConfig, pods algorithm.PodLister, random *rand.Rand) algorithm.ScheduleAlgorithm { return &genericScheduler{ predicates: predicates, diff --git a/plugin/pkg/scheduler/generic_scheduler_test.go b/plugin/pkg/scheduler/generic_scheduler_test.go index 9044e9fa306..37b95483454 100644 --- a/plugin/pkg/scheduler/generic_scheduler_test.go +++ b/plugin/pkg/scheduler/generic_scheduler_test.go @@ -26,7 +26,6 @@ import ( "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/util" "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm" - "k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities" ) func falsePredicate(pod *api.Pod, existingPods []*api.Pod, node string) (bool, error) { @@ -177,14 +176,14 @@ func TestGenericScheduler(t *testing.T) { }{ { predicates: map[string]algorithm.FitPredicate{"false": falsePredicate}, - prioritizers: []algorithm.PriorityConfig{{Function: priorities.EqualPriority, Weight: 1}}, + prioritizers: []algorithm.PriorityConfig{{Function: EqualPriority, Weight: 1}}, nodes: []string{"machine1", "machine2"}, expectsErr: true, name: "test 1", }, { predicates: map[string]algorithm.FitPredicate{"true": truePredicate}, - prioritizers: []algorithm.PriorityConfig{{Function: priorities.EqualPriority, Weight: 1}}, + prioritizers: []algorithm.PriorityConfig{{Function: EqualPriority, Weight: 1}}, nodes: []string{"machine1", "machine2"}, // Random choice between both, the rand seeded above with zero, chooses "machine1" expectedHost: "machine1", @@ -193,7 +192,7 @@ func TestGenericScheduler(t *testing.T) { { // Fits on a machine where the pod ID matches the machine name predicates: map[string]algorithm.FitPredicate{"matches": matchesPredicate}, - prioritizers: []algorithm.PriorityConfig{{Function: priorities.EqualPriority, Weight: 1}}, + prioritizers: []algorithm.PriorityConfig{{Function: EqualPriority, Weight: 1}}, nodes: []string{"machine1", "machine2"}, pod: &api.Pod{ObjectMeta: api.ObjectMeta{Name: "machine2"}}, expectedHost: "machine2",