From 6e11cd6028368c1720c2ea08d39b3e173b13c27c Mon Sep 17 00:00:00 2001 From: HaiyangDING Date: Tue, 29 Sep 2015 17:44:26 +0800 Subject: [PATCH] Replace PodFitsPorts with PodFitsHostPorts --- docs/devel/scheduler_algorithm.md | 2 +- plugin/pkg/scheduler/algorithm/predicates/predicates.go | 2 +- .../pkg/scheduler/algorithm/predicates/predicates_test.go | 4 ++-- .../algorithmprovider/defaults/compatibility_test.go | 7 ++++++- .../pkg/scheduler/algorithmprovider/defaults/defaults.go | 5 ++++- plugin/pkg/scheduler/scheduler_test.go | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/devel/scheduler_algorithm.md b/docs/devel/scheduler_algorithm.md index 7964ab33994..d6a8b6c58ac 100755 --- a/docs/devel/scheduler_algorithm.md +++ b/docs/devel/scheduler_algorithm.md @@ -41,7 +41,7 @@ The purpose of filtering the nodes is to filter out the nodes that do not meet c - `NoDiskConflict`: Evaluate if a pod can fit due to the volumes it requests, and those that are already mounted. - `PodFitsResources`: Check if the free resource (CPU and Memory) meets the requirement of the Pod. The free resource is measured by the capacity minus the sum of requests of all Pods on the node. To learn more about the resource QoS in Kubernetes, please check [QoS proposal](../proposals/resource-qos.md). -- `PodFitsPorts`: Check if any HostPort required by the Pod is already occupied on the node. +- `PodFitsHostPorts`: Check if any HostPort required by the Pod is already occupied on the node. - `PodFitsHost`: Filter out all nodes except the one specified in the PodSpec's NodeName field. - `PodSelectorMatches`: Check if the labels of the node match the labels specified in the Pod's `nodeSelector` field ([Here](../user-guide/node-selection/) is an example of how to use `nodeSelector` field). - `CheckNodeLabelPresence`: Check if all the specified labels exist on a node or not, regardless of the value. diff --git a/plugin/pkg/scheduler/algorithm/predicates/predicates.go b/plugin/pkg/scheduler/algorithm/predicates/predicates.go index 735fe9ae8b6..57e324be40d 100644 --- a/plugin/pkg/scheduler/algorithm/predicates/predicates.go +++ b/plugin/pkg/scheduler/algorithm/predicates/predicates.go @@ -356,7 +356,7 @@ func (s *ServiceAffinity) CheckServiceAffinity(pod *api.Pod, existingPods []*api return affinitySelector.Matches(labels.Set(node.Labels)), nil } -func PodFitsPorts(pod *api.Pod, existingPods []*api.Pod, node string) (bool, error) { +func PodFitsHostPorts(pod *api.Pod, existingPods []*api.Pod, node string) (bool, error) { existingPorts := getUsedPorts(existingPods...) wantPorts := getUsedPorts(pod) for wport := range wantPorts { diff --git a/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go b/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go index 9e88714cd93..0942a40b99a 100644 --- a/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go +++ b/plugin/pkg/scheduler/algorithm/predicates/predicates_test.go @@ -244,7 +244,7 @@ func newPod(host string, hostPorts ...int) *api.Pod { } } -func TestPodFitsPorts(t *testing.T) { +func TestPodFitsHostPorts(t *testing.T) { tests := []struct { pod *api.Pod existingPods []*api.Pod @@ -291,7 +291,7 @@ func TestPodFitsPorts(t *testing.T) { }, } for _, test := range tests { - fits, err := PodFitsPorts(test.pod, test.existingPods, "machine") + fits, err := PodFitsHostPorts(test.pod, test.existingPods, "machine") if err != nil { t.Errorf("unexpected error: %v", err) } diff --git a/plugin/pkg/scheduler/algorithmprovider/defaults/compatibility_test.go b/plugin/pkg/scheduler/algorithmprovider/defaults/compatibility_test.go index 62918ca184e..d7ee5771754 100644 --- a/plugin/pkg/scheduler/algorithmprovider/defaults/compatibility_test.go +++ b/plugin/pkg/scheduler/algorithmprovider/defaults/compatibility_test.go @@ -69,11 +69,16 @@ func TestCompatibility_v1_Scheduler(t *testing.T) { // Do not change this JSON after 1.1 is tagged. A failure indicates backwards compatibility with 1.1 was broken. "1.1": { JSON: `{ - "priorities": [ + "predicates": [ + {"name": "PodFitsHostPorts"} + ],"priorities": [ {"name": "SelectorSpreadPriority", "weight": 2} ] }`, ExpectedPolicy: schedulerapi.Policy{ + Predicates: []schedulerapi.PredicatePolicy{ + {Name: "PodFitsHostPorts"}, + }, Priorities: []schedulerapi.PriorityPolicy{ {Name: "SelectorSpreadPriority", Weight: 2}, }, diff --git a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go index 26452365af0..c3c0e389cf7 100644 --- a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go +++ b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go @@ -46,12 +46,15 @@ func init() { Weight: 1, }, ) + // PodFitsPorts has been replaced by PodFitsHostPorts for better user understanding. + // For backwards compatibility with 1.0, PodFitsPorts is regitered as well. + factory.RegisterFitPredicate("PodFitsPorts", predicates.PodFitsHostPorts) } func defaultPredicates() sets.String { return sets.NewString( // Fit is defined based on the absence of port conflicts. - factory.RegisterFitPredicate("PodFitsPorts", predicates.PodFitsPorts), + factory.RegisterFitPredicate("PodFitsHostPorts", predicates.PodFitsHostPorts), // Fit is determined by resource availability. factory.RegisterFitPredicateFactory( "PodFitsResources", diff --git a/plugin/pkg/scheduler/scheduler_test.go b/plugin/pkg/scheduler/scheduler_test.go index de02f337d99..6449e6b4665 100644 --- a/plugin/pkg/scheduler/scheduler_test.go +++ b/plugin/pkg/scheduler/scheduler_test.go @@ -188,7 +188,7 @@ func TestSchedulerForgetAssumedPodAfterDelete(t *testing.T) { // Create the scheduler config algo := NewGenericScheduler( - map[string]algorithm.FitPredicate{"PodFitsPorts": predicates.PodFitsPorts}, + map[string]algorithm.FitPredicate{"PodFitsHostPorts": predicates.PodFitsHostPorts}, []algorithm.PriorityConfig{}, modeler.PodLister(), rand.New(rand.NewSource(time.Now().UnixNano())))