mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Revert "Move prioritizer function EqualPriority to package priorities"
This commit is contained in:
		@@ -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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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 {
 | 
			
		||||
 
 | 
			
		||||
@@ -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,
 | 
			
		||||
 
 | 
			
		||||
@@ -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",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user