mirror of https://github.com/k3s-io/k3s
refactor(scheduler): Move priority types to priorities package
This moves the priority types from the algorithm package to priorities package. Idea is to move the type to the packages where it is implemented. This will ease the future refactor process.pull/564/head
parent
cc67ccfd7f
commit
1fe7ce21bc
|
@ -46,6 +46,7 @@ go_test(
|
||||||
"//pkg/controller/volume/persistentvolume:go_default_library",
|
"//pkg/controller/volume/persistentvolume:go_default_library",
|
||||||
"//pkg/scheduler/algorithm:go_default_library",
|
"//pkg/scheduler/algorithm:go_default_library",
|
||||||
"//pkg/scheduler/algorithm/predicates:go_default_library",
|
"//pkg/scheduler/algorithm/predicates:go_default_library",
|
||||||
|
"//pkg/scheduler/algorithm/priorities:go_default_library",
|
||||||
"//pkg/scheduler/api:go_default_library",
|
"//pkg/scheduler/api:go_default_library",
|
||||||
"//pkg/scheduler/apis/config:go_default_library",
|
"//pkg/scheduler/apis/config:go_default_library",
|
||||||
"//pkg/scheduler/core:go_default_library",
|
"//pkg/scheduler/core:go_default_library",
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
load(
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
"@io_bazel_rules_go//go:def.bzl",
|
|
||||||
"go_library",
|
|
||||||
"go_test",
|
|
||||||
)
|
|
||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
|
@ -24,17 +20,6 @@ go_library(
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
go_test(
|
|
||||||
name = "go_default_test",
|
|
||||||
srcs = ["types_test.go"],
|
|
||||||
embed = [":go_default_library"],
|
|
||||||
deps = [
|
|
||||||
"//pkg/scheduler/nodeinfo:go_default_library",
|
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "package-srcs",
|
name = "package-srcs",
|
||||||
srcs = glob(["**"]),
|
srcs = glob(["**"]),
|
||||||
|
|
|
@ -26,6 +26,7 @@ go_library(
|
||||||
"selector_spreading.go",
|
"selector_spreading.go",
|
||||||
"taint_toleration.go",
|
"taint_toleration.go",
|
||||||
"test_util.go",
|
"test_util.go",
|
||||||
|
"types.go",
|
||||||
],
|
],
|
||||||
importpath = "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities",
|
importpath = "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities",
|
||||||
deps = [
|
deps = [
|
||||||
|
@ -65,11 +66,13 @@ go_test(
|
||||||
"resource_limits_test.go",
|
"resource_limits_test.go",
|
||||||
"selector_spreading_test.go",
|
"selector_spreading_test.go",
|
||||||
"taint_toleration_test.go",
|
"taint_toleration_test.go",
|
||||||
|
"types_test.go",
|
||||||
],
|
],
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/features:go_default_library",
|
"//pkg/features:go_default_library",
|
||||||
"//pkg/kubelet/apis:go_default_library",
|
"//pkg/kubelet/apis:go_default_library",
|
||||||
|
"//pkg/scheduler/algorithm:go_default_library",
|
||||||
"//pkg/scheduler/algorithm/priorities/util:go_default_library",
|
"//pkg/scheduler/algorithm/priorities/util:go_default_library",
|
||||||
"//pkg/scheduler/api:go_default_library",
|
"//pkg/scheduler/api:go_default_library",
|
||||||
"//pkg/scheduler/nodeinfo:go_default_library",
|
"//pkg/scheduler/nodeinfo:go_default_library",
|
||||||
|
@ -79,6 +82,7 @@ go_test(
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
|
||||||
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
|
"//staging/src/k8s.io/apiserver/pkg/util/feature/testing:go_default_library",
|
||||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||||
|
|
|
@ -46,7 +46,7 @@ func NewInterPodAffinityPriority(
|
||||||
info predicates.NodeInfo,
|
info predicates.NodeInfo,
|
||||||
nodeLister algorithm.NodeLister,
|
nodeLister algorithm.NodeLister,
|
||||||
podLister algorithm.PodLister,
|
podLister algorithm.PodLister,
|
||||||
hardPodAffinityWeight int32) algorithm.PriorityFunction {
|
hardPodAffinityWeight int32) PriorityFunction {
|
||||||
interPodAffinity := &InterPodAffinity{
|
interPodAffinity := &InterPodAffinity{
|
||||||
info: info,
|
info: info,
|
||||||
nodeLister: nodeLister,
|
nodeLister: nodeLister,
|
||||||
|
|
|
@ -33,7 +33,7 @@ type PriorityMetadataFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPriorityMetadataFactory creates a PriorityMetadataFactory.
|
// NewPriorityMetadataFactory creates a PriorityMetadataFactory.
|
||||||
func NewPriorityMetadataFactory(serviceLister algorithm.ServiceLister, controllerLister algorithm.ControllerLister, replicaSetLister algorithm.ReplicaSetLister, statefulSetLister algorithm.StatefulSetLister) algorithm.PriorityMetadataProducer {
|
func NewPriorityMetadataFactory(serviceLister algorithm.ServiceLister, controllerLister algorithm.ControllerLister, replicaSetLister algorithm.ReplicaSetLister, statefulSetLister algorithm.StatefulSetLister) PriorityMetadataProducer {
|
||||||
factory := &PriorityMetadataFactory{
|
factory := &PriorityMetadataFactory{
|
||||||
serviceLister: serviceLister,
|
serviceLister: serviceLister,
|
||||||
controllerLister: controllerLister,
|
controllerLister: controllerLister,
|
||||||
|
|
|
@ -21,7 +21,6 @@ import (
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
)
|
)
|
||||||
|
@ -33,7 +32,7 @@ type NodeLabelPrioritizer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNodeLabelPriority creates a NodeLabelPrioritizer.
|
// NewNodeLabelPriority creates a NodeLabelPrioritizer.
|
||||||
func NewNodeLabelPriority(label string, presence bool) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
func NewNodeLabelPriority(label string, presence bool) (PriorityMapFunction, PriorityReduceFunction) {
|
||||||
labelPrioritizer := &NodeLabelPrioritizer{
|
labelPrioritizer := &NodeLabelPrioritizer{
|
||||||
label: label,
|
label: label,
|
||||||
presence: presence,
|
presence: presence,
|
||||||
|
|
|
@ -18,7 +18,6 @@ package priorities
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
)
|
)
|
||||||
|
@ -26,7 +25,7 @@ import (
|
||||||
// NormalizeReduce generates a PriorityReduceFunction that can normalize the result
|
// NormalizeReduce generates a PriorityReduceFunction that can normalize the result
|
||||||
// scores to [0, maxPriority]. If reverse is set to true, it reverses the scores by
|
// scores to [0, maxPriority]. If reverse is set to true, it reverses the scores by
|
||||||
// subtracting it from maxPriority.
|
// subtracting it from maxPriority.
|
||||||
func NormalizeReduce(maxPriority int, reverse bool) algorithm.PriorityReduceFunction {
|
func NormalizeReduce(maxPriority int, reverse bool) PriorityReduceFunction {
|
||||||
return func(
|
return func(
|
||||||
_ *v1.Pod,
|
_ *v1.Pod,
|
||||||
_ interface{},
|
_ interface{},
|
||||||
|
|
|
@ -46,7 +46,7 @@ func NewSelectorSpreadPriority(
|
||||||
serviceLister algorithm.ServiceLister,
|
serviceLister algorithm.ServiceLister,
|
||||||
controllerLister algorithm.ControllerLister,
|
controllerLister algorithm.ControllerLister,
|
||||||
replicaSetLister algorithm.ReplicaSetLister,
|
replicaSetLister algorithm.ReplicaSetLister,
|
||||||
statefulSetLister algorithm.StatefulSetLister) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
statefulSetLister algorithm.StatefulSetLister) (PriorityMapFunction, PriorityReduceFunction) {
|
||||||
selectorSpread := &SelectorSpread{
|
selectorSpread := &SelectorSpread{
|
||||||
serviceLister: serviceLister,
|
serviceLister: serviceLister,
|
||||||
controllerLister: controllerLister,
|
controllerLister: controllerLister,
|
||||||
|
@ -177,7 +177,7 @@ type ServiceAntiAffinity struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServiceAntiAffinityPriority creates a ServiceAntiAffinity.
|
// NewServiceAntiAffinityPriority creates a ServiceAntiAffinity.
|
||||||
func NewServiceAntiAffinityPriority(podLister algorithm.PodLister, serviceLister algorithm.ServiceLister, label string) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
func NewServiceAntiAffinityPriority(podLister algorithm.PodLister, serviceLister algorithm.ServiceLister, label string) (PriorityMapFunction, PriorityReduceFunction) {
|
||||||
antiAffinity := &ServiceAntiAffinity{
|
antiAffinity := &ServiceAntiAffinity{
|
||||||
podLister: podLister,
|
podLister: podLister,
|
||||||
serviceLister: serviceLister,
|
serviceLister: serviceLister,
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"k8s.io/api/core/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"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
)
|
)
|
||||||
|
@ -41,7 +40,7 @@ func makeNode(node string, milliCPU, memory int64) *v1.Node {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func priorityFunction(mapFn algorithm.PriorityMapFunction, reduceFn algorithm.PriorityReduceFunction, metaData interface{}) algorithm.PriorityFunction {
|
func priorityFunction(mapFn PriorityMapFunction, reduceFn PriorityReduceFunction, metaData interface{}) PriorityFunction {
|
||||||
return func(pod *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo, nodes []*v1.Node) (schedulerapi.HostPriorityList, error) {
|
return func(pod *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo, nodes []*v1.Node) (schedulerapi.HostPriorityList, error) {
|
||||||
result := make(schedulerapi.HostPriorityList, 0, len(nodes))
|
result := make(schedulerapi.HostPriorityList, 0, len(nodes))
|
||||||
for i := range nodes {
|
for i := range nodes {
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package priorities
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/api/core/v1"
|
||||||
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PriorityMapFunction is a function that computes per-node results for a given node.
|
||||||
|
// TODO: Figure out the exact API of this method.
|
||||||
|
// TODO: Change interface{} to a specific type.
|
||||||
|
type PriorityMapFunction func(pod *v1.Pod, meta interface{}, nodeInfo *schedulernodeinfo.NodeInfo) (schedulerapi.HostPriority, error)
|
||||||
|
|
||||||
|
// PriorityReduceFunction is a function that aggregated per-node results and computes
|
||||||
|
// final scores for all nodes.
|
||||||
|
// TODO: Figure out the exact API of this method.
|
||||||
|
// TODO: Change interface{} to a specific type.
|
||||||
|
type PriorityReduceFunction func(pod *v1.Pod, meta interface{}, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo, result schedulerapi.HostPriorityList) error
|
||||||
|
|
||||||
|
// PriorityMetadataProducer is a function that computes metadata for a given pod. This
|
||||||
|
// is now used for only for priority functions. For predicates please use PredicateMetadataProducer.
|
||||||
|
type PriorityMetadataProducer func(pod *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo) 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, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo, nodes []*v1.Node) (schedulerapi.HostPriorityList, error)
|
||||||
|
|
||||||
|
// PriorityConfig is a config used for a priority function.
|
||||||
|
type PriorityConfig struct {
|
||||||
|
Name string
|
||||||
|
Map PriorityMapFunction
|
||||||
|
Reduce PriorityReduceFunction
|
||||||
|
// TODO: Remove it after migrating all functions to
|
||||||
|
// Map-Reduce pattern.
|
||||||
|
Function PriorityFunction
|
||||||
|
Weight int
|
||||||
|
}
|
||||||
|
|
||||||
|
// EmptyPriorityMetadataProducer returns a no-op PriorityMetadataProducer type.
|
||||||
|
func EmptyPriorityMetadataProducer(pod *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo) interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -14,13 +14,14 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package algorithm
|
package priorities
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ func TestEmptyPriorityMetadataProducer(t *testing.T) {
|
||||||
t.Errorf("failed to produce empty metadata: got %v, expected nil", metadata)
|
t.Errorf("failed to produce empty metadata: got %v, expected nil", metadata)
|
||||||
}
|
}
|
||||||
// Test EmptyControllerLister should return nill
|
// Test EmptyControllerLister should return nill
|
||||||
controllerLister := EmptyControllerLister{}
|
controllerLister := algorithm.EmptyControllerLister{}
|
||||||
nilController, nilError := controllerLister.List(fakeLabelSelector)
|
nilController, nilError := controllerLister.List(fakeLabelSelector)
|
||||||
if nilController != nil || nilError != nil {
|
if nilController != nil || nilError != nil {
|
||||||
t.Errorf("failed to produce empty controller lister: got %v, expected nil", nilController)
|
t.Errorf("failed to produce empty controller lister: got %v, expected nil", nilController)
|
||||||
|
@ -50,14 +51,14 @@ func TestEmptyPriorityMetadataProducer(t *testing.T) {
|
||||||
t.Errorf("failed to produce empty controller lister: got %v, expected nil", nilController)
|
t.Errorf("failed to produce empty controller lister: got %v, expected nil", nilController)
|
||||||
}
|
}
|
||||||
// Test GetPodReplicaSets on empty replica sets should return nill
|
// Test GetPodReplicaSets on empty replica sets should return nill
|
||||||
replicaSetLister := EmptyReplicaSetLister{}
|
replicaSetLister := algorithm.EmptyReplicaSetLister{}
|
||||||
nilRss, nilErrRss := replicaSetLister.GetPodReplicaSets(fakePod)
|
nilRss, nilErrRss := replicaSetLister.GetPodReplicaSets(fakePod)
|
||||||
if nilRss != nil || nilErrRss != nil {
|
if nilRss != nil || nilErrRss != nil {
|
||||||
t.Errorf("failed to produce empty replicaSetLister: got %v, expected nil", nilRss)
|
t.Errorf("failed to produce empty replicaSetLister: got %v, expected nil", nilRss)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test GetPodStatefulSets on empty replica sets should return nill
|
// Test GetPodStatefulSets on empty replica sets should return nill
|
||||||
statefulSetLister := EmptyStatefulSetLister{}
|
statefulSetLister := algorithm.EmptyStatefulSetLister{}
|
||||||
nilSSL, nilErrSSL := statefulSetLister.GetPodStatefulSets(fakePod)
|
nilSSL, nilErrSSL := statefulSetLister.GetPodStatefulSets(fakePod)
|
||||||
if nilSSL != nil || nilErrSSL != nil {
|
if nilSSL != nil || nilErrSSL != nil {
|
||||||
t.Errorf("failed to produce empty statefulSetLister: got %v, expected nil", nilSSL)
|
t.Errorf("failed to produce empty statefulSetLister: got %v, expected nil", nilSSL)
|
|
@ -22,7 +22,6 @@ import (
|
||||||
policyv1beta1 "k8s.io/api/policy/v1beta1"
|
policyv1beta1 "k8s.io/api/policy/v1beta1"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NodeFieldSelectorKeys is a map that: the key are node field selector keys; the values are
|
// NodeFieldSelectorKeys is a map that: the key are node field selector keys; the values are
|
||||||
|
@ -31,42 +30,6 @@ var NodeFieldSelectorKeys = map[string]func(*v1.Node) string{
|
||||||
schedulerapi.NodeFieldSelectorKeyNodeName: func(n *v1.Node) string { return n.Name },
|
schedulerapi.NodeFieldSelectorKeyNodeName: func(n *v1.Node) string { return n.Name },
|
||||||
}
|
}
|
||||||
|
|
||||||
// PriorityMapFunction is a function that computes per-node results for a given node.
|
|
||||||
// TODO: Figure out the exact API of this method.
|
|
||||||
// TODO: Change interface{} to a specific type.
|
|
||||||
type PriorityMapFunction func(pod *v1.Pod, meta interface{}, nodeInfo *schedulernodeinfo.NodeInfo) (schedulerapi.HostPriority, error)
|
|
||||||
|
|
||||||
// PriorityReduceFunction is a function that aggregated per-node results and computes
|
|
||||||
// final scores for all nodes.
|
|
||||||
// TODO: Figure out the exact API of this method.
|
|
||||||
// TODO: Change interface{} to a specific type.
|
|
||||||
type PriorityReduceFunction func(pod *v1.Pod, meta interface{}, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo, result schedulerapi.HostPriorityList) error
|
|
||||||
|
|
||||||
// PriorityMetadataProducer is a function that computes metadata for a given pod. This
|
|
||||||
// is now used for only for priority functions. For predicates please use PredicateMetadataProducer.
|
|
||||||
type PriorityMetadataProducer func(pod *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo) 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, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo, nodes []*v1.Node) (schedulerapi.HostPriorityList, error)
|
|
||||||
|
|
||||||
// PriorityConfig is a config used for a priority function.
|
|
||||||
type PriorityConfig struct {
|
|
||||||
Name string
|
|
||||||
Map PriorityMapFunction
|
|
||||||
Reduce PriorityReduceFunction
|
|
||||||
// TODO: Remove it after migrating all functions to
|
|
||||||
// Map-Reduce pattern.
|
|
||||||
Function PriorityFunction
|
|
||||||
Weight int
|
|
||||||
}
|
|
||||||
|
|
||||||
// EmptyPriorityMetadataProducer returns a no-op PriorityMetadataProducer type.
|
|
||||||
func EmptyPriorityMetadataProducer(pod *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo) interface{} {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NodeLister interface represents anything that can list nodes for a scheduler.
|
// NodeLister interface represents anything that can list nodes for a scheduler.
|
||||||
type NodeLister interface {
|
type NodeLister interface {
|
||||||
// We explicitly return []*v1.Node, instead of v1.NodeList, to avoid
|
// We explicitly return []*v1.Node, instead of v1.NodeList, to avoid
|
||||||
|
|
|
@ -26,7 +26,7 @@ import (
|
||||||
func init() {
|
func init() {
|
||||||
// Register functions that extract metadata used by priorities computations.
|
// Register functions that extract metadata used by priorities computations.
|
||||||
factory.RegisterPriorityMetadataProducerFactory(
|
factory.RegisterPriorityMetadataProducerFactory(
|
||||||
func(args factory.PluginFactoryArgs) algorithm.PriorityMetadataProducer {
|
func(args factory.PluginFactoryArgs) priorities.PriorityMetadataProducer {
|
||||||
return priorities.NewPriorityMetadataFactory(args.ServiceLister, args.ControllerLister, args.ReplicaSetLister, args.StatefulSetLister)
|
return priorities.NewPriorityMetadataFactory(args.ServiceLister, args.ControllerLister, args.ReplicaSetLister, args.StatefulSetLister)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func init() {
|
||||||
factory.RegisterPriorityConfigFactory(
|
factory.RegisterPriorityConfigFactory(
|
||||||
priorities.ServiceSpreadingPriority,
|
priorities.ServiceSpreadingPriority,
|
||||||
factory.PriorityConfigFactory{
|
factory.PriorityConfigFactory{
|
||||||
MapReduceFunction: func(args factory.PluginFactoryArgs) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
MapReduceFunction: func(args factory.PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction) {
|
||||||
return priorities.NewSelectorSpreadPriority(args.ServiceLister, algorithm.EmptyControllerLister{}, algorithm.EmptyReplicaSetLister{}, algorithm.EmptyStatefulSetLister{})
|
return priorities.NewSelectorSpreadPriority(args.ServiceLister, algorithm.EmptyControllerLister{}, algorithm.EmptyReplicaSetLister{}, algorithm.EmptyStatefulSetLister{})
|
||||||
},
|
},
|
||||||
Weight: 1,
|
Weight: 1,
|
||||||
|
@ -58,7 +58,7 @@ func init() {
|
||||||
factory.RegisterPriorityConfigFactory(
|
factory.RegisterPriorityConfigFactory(
|
||||||
priorities.SelectorSpreadPriority,
|
priorities.SelectorSpreadPriority,
|
||||||
factory.PriorityConfigFactory{
|
factory.PriorityConfigFactory{
|
||||||
MapReduceFunction: func(args factory.PluginFactoryArgs) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
MapReduceFunction: func(args factory.PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction) {
|
||||||
return priorities.NewSelectorSpreadPriority(args.ServiceLister, args.ControllerLister, args.ReplicaSetLister, args.StatefulSetLister)
|
return priorities.NewSelectorSpreadPriority(args.ServiceLister, args.ControllerLister, args.ReplicaSetLister, args.StatefulSetLister)
|
||||||
},
|
},
|
||||||
Weight: 1,
|
Weight: 1,
|
||||||
|
@ -69,7 +69,7 @@ func init() {
|
||||||
factory.RegisterPriorityConfigFactory(
|
factory.RegisterPriorityConfigFactory(
|
||||||
priorities.InterPodAffinityPriority,
|
priorities.InterPodAffinityPriority,
|
||||||
factory.PriorityConfigFactory{
|
factory.PriorityConfigFactory{
|
||||||
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
Function: func(args factory.PluginFactoryArgs) priorities.PriorityFunction {
|
||||||
return priorities.NewInterPodAffinityPriority(args.NodeInfo, args.NodeLister, args.PodLister, args.HardPodAffinitySymmetricWeight)
|
return priorities.NewInterPodAffinityPriority(args.NodeInfo, args.NodeLister, args.PodLister, args.HardPodAffinitySymmetricWeight)
|
||||||
},
|
},
|
||||||
Weight: 1,
|
Weight: 1,
|
||||||
|
|
|
@ -11,6 +11,7 @@ go_library(
|
||||||
deps = [
|
deps = [
|
||||||
"//pkg/scheduler/algorithm:go_default_library",
|
"//pkg/scheduler/algorithm:go_default_library",
|
||||||
"//pkg/scheduler/algorithm/predicates:go_default_library",
|
"//pkg/scheduler/algorithm/predicates:go_default_library",
|
||||||
|
"//pkg/scheduler/algorithm/priorities:go_default_library",
|
||||||
"//pkg/scheduler/api:go_default_library",
|
"//pkg/scheduler/api:go_default_library",
|
||||||
"//pkg/scheduler/internal/cache:go_default_library",
|
"//pkg/scheduler/internal/cache:go_default_library",
|
||||||
"//pkg/scheduler/internal/queue:go_default_library",
|
"//pkg/scheduler/internal/queue:go_default_library",
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||||
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
|
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
|
||||||
|
@ -340,7 +341,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
predicates map[string]predicates.FitPredicate
|
predicates map[string]predicates.FitPredicate
|
||||||
prioritizers []algorithm.PriorityConfig
|
prioritizers []priorities.PriorityConfig
|
||||||
extenders []FakeExtender
|
extenders []FakeExtender
|
||||||
nodes []string
|
nodes []string
|
||||||
expectedResult ScheduleResult
|
expectedResult ScheduleResult
|
||||||
|
@ -348,7 +349,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{truePredicateExtender},
|
predicates: []fitPredicate{truePredicateExtender},
|
||||||
|
@ -363,7 +364,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{truePredicateExtender},
|
predicates: []fitPredicate{truePredicateExtender},
|
||||||
|
@ -378,7 +379,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{truePredicateExtender},
|
predicates: []fitPredicate{truePredicateExtender},
|
||||||
|
@ -397,7 +398,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{machine2PredicateExtender},
|
predicates: []fitPredicate{machine2PredicateExtender},
|
||||||
|
@ -412,7 +413,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{truePredicateExtender},
|
predicates: []fitPredicate{truePredicateExtender},
|
||||||
|
@ -430,7 +431,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{truePredicateExtender},
|
predicates: []fitPredicate{truePredicateExtender},
|
||||||
|
@ -453,7 +454,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Function: machine2Prioritizer, Weight: 20}},
|
prioritizers: []priorities.PriorityConfig{{Function: machine2Prioritizer, Weight: 20}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{truePredicateExtender},
|
predicates: []fitPredicate{truePredicateExtender},
|
||||||
|
@ -478,7 +479,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
// because of the errors from errorPredicateExtender and/or
|
// because of the errors from errorPredicateExtender and/or
|
||||||
// errorPrioritizerExtender.
|
// errorPrioritizerExtender.
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Function: machine2Prioritizer, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Function: machine2Prioritizer, Weight: 1}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{errorPredicateExtender},
|
predicates: []fitPredicate{errorPredicateExtender},
|
||||||
|
@ -502,7 +503,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
// If scheduler did not ignore the extender, the test would fail
|
// If scheduler did not ignore the extender, the test would fail
|
||||||
// because of the errors from errorPredicateExtender.
|
// because of the errors from errorPredicateExtender.
|
||||||
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
extenders: []FakeExtender{
|
extenders: []FakeExtender{
|
||||||
{
|
{
|
||||||
predicates: []fitPredicate{errorPredicateExtender},
|
predicates: []fitPredicate{errorPredicateExtender},
|
||||||
|
@ -540,7 +541,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
|
||||||
test.predicates,
|
test.predicates,
|
||||||
predicates.EmptyPredicateMetadataProducer,
|
predicates.EmptyPredicateMetadataProducer,
|
||||||
test.prioritizers,
|
test.prioritizers,
|
||||||
algorithm.EmptyPriorityMetadataProducer,
|
priorities.EmptyPriorityMetadataProducer,
|
||||||
emptyPluginSet,
|
emptyPluginSet,
|
||||||
extenders,
|
extenders,
|
||||||
nil,
|
nil,
|
||||||
|
|
|
@ -38,6 +38,7 @@ import (
|
||||||
"k8s.io/client-go/util/workqueue"
|
"k8s.io/client-go/util/workqueue"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||||
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
|
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
|
||||||
|
@ -115,7 +116,7 @@ type ScheduleAlgorithm interface {
|
||||||
Predicates() map[string]predicates.FitPredicate
|
Predicates() map[string]predicates.FitPredicate
|
||||||
// Prioritizers returns a slice of priority config. This is exposed for
|
// Prioritizers returns a slice of priority config. This is exposed for
|
||||||
// testing.
|
// testing.
|
||||||
Prioritizers() []algorithm.PriorityConfig
|
Prioritizers() []priorities.PriorityConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// ScheduleResult represents the result of one pod scheduled. It will contain
|
// ScheduleResult represents the result of one pod scheduled. It will contain
|
||||||
|
@ -133,9 +134,9 @@ type genericScheduler struct {
|
||||||
cache schedulerinternalcache.Cache
|
cache schedulerinternalcache.Cache
|
||||||
schedulingQueue internalqueue.SchedulingQueue
|
schedulingQueue internalqueue.SchedulingQueue
|
||||||
predicates map[string]predicates.FitPredicate
|
predicates map[string]predicates.FitPredicate
|
||||||
priorityMetaProducer algorithm.PriorityMetadataProducer
|
priorityMetaProducer priorities.PriorityMetadataProducer
|
||||||
predicateMetaProducer predicates.PredicateMetadataProducer
|
predicateMetaProducer predicates.PredicateMetadataProducer
|
||||||
prioritizers []algorithm.PriorityConfig
|
prioritizers []priorities.PriorityConfig
|
||||||
pluginSet pluginsv1alpha1.PluginSet
|
pluginSet pluginsv1alpha1.PluginSet
|
||||||
extenders []algorithm.SchedulerExtender
|
extenders []algorithm.SchedulerExtender
|
||||||
lastNodeIndex uint64
|
lastNodeIndex uint64
|
||||||
|
@ -227,7 +228,7 @@ func (g *genericScheduler) Schedule(pod *v1.Pod, nodeLister algorithm.NodeLister
|
||||||
|
|
||||||
// Prioritizers returns a slice containing all the scheduler's priority
|
// Prioritizers returns a slice containing all the scheduler's priority
|
||||||
// functions and their config. It is exposed for testing only.
|
// functions and their config. It is exposed for testing only.
|
||||||
func (g *genericScheduler) Prioritizers() []algorithm.PriorityConfig {
|
func (g *genericScheduler) Prioritizers() []priorities.PriorityConfig {
|
||||||
return g.prioritizers
|
return g.prioritizers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,7 +638,7 @@ func PrioritizeNodes(
|
||||||
pod *v1.Pod,
|
pod *v1.Pod,
|
||||||
nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo,
|
nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo,
|
||||||
meta interface{},
|
meta interface{},
|
||||||
priorityConfigs []algorithm.PriorityConfig,
|
priorityConfigs []priorities.PriorityConfig,
|
||||||
nodes []*v1.Node,
|
nodes []*v1.Node,
|
||||||
extenders []algorithm.SchedulerExtender,
|
extenders []algorithm.SchedulerExtender,
|
||||||
) (schedulerapi.HostPriorityList, error) {
|
) (schedulerapi.HostPriorityList, error) {
|
||||||
|
@ -1165,8 +1166,8 @@ func NewGenericScheduler(
|
||||||
podQueue internalqueue.SchedulingQueue,
|
podQueue internalqueue.SchedulingQueue,
|
||||||
predicates map[string]predicates.FitPredicate,
|
predicates map[string]predicates.FitPredicate,
|
||||||
predicateMetaProducer predicates.PredicateMetadataProducer,
|
predicateMetaProducer predicates.PredicateMetadataProducer,
|
||||||
prioritizers []algorithm.PriorityConfig,
|
prioritizers []priorities.PriorityConfig,
|
||||||
priorityMetaProducer algorithm.PriorityMetadataProducer,
|
priorityMetaProducer priorities.PriorityMetadataProducer,
|
||||||
pluginSet pluginsv1alpha1.PluginSet,
|
pluginSet pluginsv1alpha1.PluginSet,
|
||||||
extenders []algorithm.SchedulerExtender,
|
extenders []algorithm.SchedulerExtender,
|
||||||
volumeBinder *volumebinder.VolumeBinder,
|
volumeBinder *volumebinder.VolumeBinder,
|
||||||
|
|
|
@ -35,7 +35,7 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
||||||
algorithmpredicates "k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
algorithmpredicates "k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
||||||
algorithmpriorities "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
||||||
priorityutil "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities/util"
|
priorityutil "k8s.io/kubernetes/pkg/scheduler/algorithm/priorities/util"
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||||
|
@ -239,7 +239,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
predicates map[string]algorithmpredicates.FitPredicate
|
predicates map[string]algorithmpredicates.FitPredicate
|
||||||
prioritizers []algorithm.PriorityConfig
|
prioritizers []priorities.PriorityConfig
|
||||||
alwaysCheckAllPredicates bool
|
alwaysCheckAllPredicates bool
|
||||||
nodes []string
|
nodes []string
|
||||||
pvcs []*v1.PersistentVolumeClaim
|
pvcs []*v1.PersistentVolumeClaim
|
||||||
|
@ -251,7 +251,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"false": falsePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"false": falsePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
nodes: []string{"machine1", "machine2"},
|
nodes: []string{"machine1", "machine2"},
|
||||||
expectsErr: true,
|
expectsErr: true,
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
||||||
|
@ -266,7 +266,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
nodes: []string{"machine1", "machine2"},
|
nodes: []string{"machine1", "machine2"},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "ignore", UID: types.UID("ignore")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "ignore", UID: types.UID("ignore")}},
|
||||||
expectedHosts: sets.NewString("machine1", "machine2"),
|
expectedHosts: sets.NewString("machine1", "machine2"),
|
||||||
|
@ -276,7 +276,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
{
|
{
|
||||||
// Fits on a machine where the pod ID matches the machine name
|
// Fits on a machine where the pod ID matches the machine name
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"matches": matchesPredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"matches": matchesPredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
nodes: []string{"machine1", "machine2"},
|
nodes: []string{"machine1", "machine2"},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "machine2", UID: types.UID("machine2")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "machine2", UID: types.UID("machine2")}},
|
||||||
expectedHosts: sets.NewString("machine2"),
|
expectedHosts: sets.NewString("machine2"),
|
||||||
|
@ -285,7 +285,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
||||||
nodes: []string{"3", "2", "1"},
|
nodes: []string{"3", "2", "1"},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "ignore", UID: types.UID("ignore")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "ignore", UID: types.UID("ignore")}},
|
||||||
expectedHosts: sets.NewString("3"),
|
expectedHosts: sets.NewString("3"),
|
||||||
|
@ -294,7 +294,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"matches": matchesPredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"matches": matchesPredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
||||||
nodes: []string{"3", "2", "1"},
|
nodes: []string{"3", "2", "1"},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
||||||
expectedHosts: sets.NewString("2"),
|
expectedHosts: sets.NewString("2"),
|
||||||
|
@ -303,7 +303,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}, {Function: reverseNumericPriority, Weight: 2}},
|
prioritizers: []priorities.PriorityConfig{{Function: numericPriority, Weight: 1}, {Function: reverseNumericPriority, Weight: 2}},
|
||||||
nodes: []string{"3", "2", "1"},
|
nodes: []string{"3", "2", "1"},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
||||||
expectedHosts: sets.NewString("1"),
|
expectedHosts: sets.NewString("1"),
|
||||||
|
@ -312,7 +312,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "false": falsePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "false": falsePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
||||||
nodes: []string{"3", "2", "1"},
|
nodes: []string{"3", "2", "1"},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
||||||
expectsErr: true,
|
expectsErr: true,
|
||||||
|
@ -344,7 +344,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
||||||
nodes: []string{"1", "2"},
|
nodes: []string{"1", "2"},
|
||||||
expectsErr: true,
|
expectsErr: true,
|
||||||
name: "test 8",
|
name: "test 8",
|
||||||
|
@ -360,7 +360,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
{
|
{
|
||||||
// Pod with existing PVC
|
// Pod with existing PVC
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
nodes: []string{"machine1", "machine2"},
|
nodes: []string{"machine1", "machine2"},
|
||||||
pvcs: []*v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "existingPVC"}}},
|
pvcs: []*v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "existingPVC"}}},
|
||||||
pod: &v1.Pod{
|
pod: &v1.Pod{
|
||||||
|
@ -384,7 +384,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
{
|
{
|
||||||
// Pod with non existing PVC
|
// Pod with non existing PVC
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
nodes: []string{"machine1", "machine2"},
|
nodes: []string{"machine1", "machine2"},
|
||||||
pod: &v1.Pod{
|
pod: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: "ignore", UID: types.UID("ignore")},
|
ObjectMeta: metav1.ObjectMeta{Name: "ignore", UID: types.UID("ignore")},
|
||||||
|
@ -407,7 +407,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
{
|
{
|
||||||
// Pod with deleting PVC
|
// Pod with deleting PVC
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
nodes: []string{"machine1", "machine2"},
|
nodes: []string{"machine1", "machine2"},
|
||||||
pvcs: []*v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "existingPVC", DeletionTimestamp: &metav1.Time{}}}},
|
pvcs: []*v1.PersistentVolumeClaim{{ObjectMeta: metav1.ObjectMeta{Name: "existingPVC", DeletionTimestamp: &metav1.Time{}}}},
|
||||||
pod: &v1.Pod{
|
pod: &v1.Pod{
|
||||||
|
@ -431,7 +431,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
{
|
{
|
||||||
// alwaysCheckAllPredicates is true
|
// alwaysCheckAllPredicates is true
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "matches": matchesPredicate, "false": falsePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "matches": matchesPredicate, "false": falsePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
||||||
alwaysCheckAllPredicates: true,
|
alwaysCheckAllPredicates: true,
|
||||||
nodes: []string{"1"},
|
nodes: []string{"1"},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
|
||||||
|
@ -446,7 +446,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate},
|
||||||
prioritizers: []algorithm.PriorityConfig{{Map: falseMapPriority, Weight: 1}, {Map: trueMapPriority, Reduce: getNodeReducePriority, Weight: 2}},
|
prioritizers: []priorities.PriorityConfig{{Map: falseMapPriority, Weight: 1}, {Map: trueMapPriority, Reduce: getNodeReducePriority, Weight: 2}},
|
||||||
nodes: []string{"2", "1"},
|
nodes: []string{"2", "1"},
|
||||||
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
|
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2"}},
|
||||||
name: "test error with priority map",
|
name: "test error with priority map",
|
||||||
|
@ -473,7 +473,7 @@ func TestGenericScheduler(t *testing.T) {
|
||||||
test.predicates,
|
test.predicates,
|
||||||
algorithmpredicates.EmptyPredicateMetadataProducer,
|
algorithmpredicates.EmptyPredicateMetadataProducer,
|
||||||
test.prioritizers,
|
test.prioritizers,
|
||||||
algorithm.EmptyPriorityMetadataProducer,
|
priorities.EmptyPriorityMetadataProducer,
|
||||||
emptyPluginSet,
|
emptyPluginSet,
|
||||||
[]algorithm.SchedulerExtender{},
|
[]algorithm.SchedulerExtender{},
|
||||||
nil,
|
nil,
|
||||||
|
@ -501,7 +501,7 @@ func makeScheduler(predicates map[string]algorithmpredicates.FitPredicate, nodes
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
cache.AddNode(n)
|
cache.AddNode(n)
|
||||||
}
|
}
|
||||||
prioritizers := []algorithm.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}}
|
prioritizers := []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}}
|
||||||
|
|
||||||
s := NewGenericScheduler(
|
s := NewGenericScheduler(
|
||||||
cache,
|
cache,
|
||||||
|
@ -509,7 +509,7 @@ func makeScheduler(predicates map[string]algorithmpredicates.FitPredicate, nodes
|
||||||
predicates,
|
predicates,
|
||||||
algorithmpredicates.EmptyPredicateMetadataProducer,
|
algorithmpredicates.EmptyPredicateMetadataProducer,
|
||||||
prioritizers,
|
prioritizers,
|
||||||
algorithm.EmptyPriorityMetadataProducer,
|
priorities.EmptyPriorityMetadataProducer,
|
||||||
emptyPluginSet,
|
emptyPluginSet,
|
||||||
nil, nil, nil, nil, false, false,
|
nil, nil, nil, nil, false, false,
|
||||||
schedulerapi.DefaultPercentageOfNodesToScore)
|
schedulerapi.DefaultPercentageOfNodesToScore)
|
||||||
|
@ -713,21 +713,21 @@ func TestZeroRequest(t *testing.T) {
|
||||||
// This should match the configuration in defaultPriorities() in
|
// This should match the configuration in defaultPriorities() in
|
||||||
// pkg/scheduler/algorithmprovider/defaults/defaults.go if you want
|
// pkg/scheduler/algorithmprovider/defaults/defaults.go if you want
|
||||||
// to test what's actually in production.
|
// to test what's actually in production.
|
||||||
priorityConfigs := []algorithm.PriorityConfig{
|
priorityConfigs := []priorities.PriorityConfig{
|
||||||
{Map: algorithmpriorities.LeastRequestedPriorityMap, Weight: 1},
|
{Map: priorities.LeastRequestedPriorityMap, Weight: 1},
|
||||||
{Map: algorithmpriorities.BalancedResourceAllocationMap, Weight: 1},
|
{Map: priorities.BalancedResourceAllocationMap, Weight: 1},
|
||||||
}
|
}
|
||||||
selectorSpreadPriorityMap, selectorSpreadPriorityReduce := algorithmpriorities.NewSelectorSpreadPriority(
|
selectorSpreadPriorityMap, selectorSpreadPriorityReduce := priorities.NewSelectorSpreadPriority(
|
||||||
schedulertesting.FakeServiceLister([]*v1.Service{}),
|
schedulertesting.FakeServiceLister([]*v1.Service{}),
|
||||||
schedulertesting.FakeControllerLister([]*v1.ReplicationController{}),
|
schedulertesting.FakeControllerLister([]*v1.ReplicationController{}),
|
||||||
schedulertesting.FakeReplicaSetLister([]*apps.ReplicaSet{}),
|
schedulertesting.FakeReplicaSetLister([]*apps.ReplicaSet{}),
|
||||||
schedulertesting.FakeStatefulSetLister([]*apps.StatefulSet{}))
|
schedulertesting.FakeStatefulSetLister([]*apps.StatefulSet{}))
|
||||||
pc := algorithm.PriorityConfig{Map: selectorSpreadPriorityMap, Reduce: selectorSpreadPriorityReduce, Weight: 1}
|
pc := priorities.PriorityConfig{Map: selectorSpreadPriorityMap, Reduce: selectorSpreadPriorityReduce, Weight: 1}
|
||||||
priorityConfigs = append(priorityConfigs, pc)
|
priorityConfigs = append(priorityConfigs, pc)
|
||||||
|
|
||||||
nodeNameToInfo := schedulernodeinfo.CreateNodeNameToInfoMap(test.pods, test.nodes)
|
nodeNameToInfo := schedulernodeinfo.CreateNodeNameToInfoMap(test.pods, test.nodes)
|
||||||
|
|
||||||
metaDataProducer := algorithmpriorities.NewPriorityMetadataFactory(
|
metaDataProducer := priorities.NewPriorityMetadataFactory(
|
||||||
schedulertesting.FakeServiceLister([]*v1.Service{}),
|
schedulertesting.FakeServiceLister([]*v1.Service{}),
|
||||||
schedulertesting.FakeControllerLister([]*v1.ReplicationController{}),
|
schedulertesting.FakeControllerLister([]*v1.ReplicationController{}),
|
||||||
schedulertesting.FakeReplicaSetLister([]*apps.ReplicaSet{}),
|
schedulertesting.FakeReplicaSetLister([]*apps.ReplicaSet{}),
|
||||||
|
@ -1433,8 +1433,8 @@ func TestPreempt(t *testing.T) {
|
||||||
internalqueue.NewSchedulingQueue(nil),
|
internalqueue.NewSchedulingQueue(nil),
|
||||||
map[string]algorithmpredicates.FitPredicate{"matches": algorithmpredicates.PodFitsResources},
|
map[string]algorithmpredicates.FitPredicate{"matches": algorithmpredicates.PodFitsResources},
|
||||||
algorithmpredicates.EmptyPredicateMetadataProducer,
|
algorithmpredicates.EmptyPredicateMetadataProducer,
|
||||||
[]algorithm.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
[]priorities.PriorityConfig{{Function: numericPriority, Weight: 1}},
|
||||||
algorithm.EmptyPriorityMetadataProducer,
|
priorities.EmptyPriorityMetadataProducer,
|
||||||
emptyPluginSet,
|
emptyPluginSet,
|
||||||
extenders,
|
extenders,
|
||||||
nil,
|
nil,
|
||||||
|
|
|
@ -50,6 +50,7 @@ import (
|
||||||
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/api/validation"
|
"k8s.io/kubernetes/pkg/scheduler/api/validation"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/core"
|
"k8s.io/kubernetes/pkg/scheduler/core"
|
||||||
|
@ -918,7 +919,7 @@ func (n *nodeLister) List() ([]*v1.Node, error) {
|
||||||
return n.NodeLister.List(labels.Everything())
|
return n.NodeLister.List(labels.Everything())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configFactory) GetPriorityFunctionConfigs(priorityKeys sets.String) ([]algorithm.PriorityConfig, error) {
|
func (c *configFactory) GetPriorityFunctionConfigs(priorityKeys sets.String) ([]priorities.PriorityConfig, error) {
|
||||||
pluginArgs, err := c.getPluginArgs()
|
pluginArgs, err := c.getPluginArgs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -927,7 +928,7 @@ func (c *configFactory) GetPriorityFunctionConfigs(priorityKeys sets.String) ([]
|
||||||
return getPriorityFunctionConfigs(priorityKeys, *pluginArgs)
|
return getPriorityFunctionConfigs(priorityKeys, *pluginArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *configFactory) GetPriorityMetadataProducer() (algorithm.PriorityMetadataProducer, error) {
|
func (c *configFactory) GetPriorityMetadataProducer() (priorities.PriorityMetadataProducer, error) {
|
||||||
pluginArgs, err := c.getPluginArgs()
|
pluginArgs, err := c.getPluginArgs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -51,7 +51,7 @@ type PluginFactoryArgs struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// PriorityMetadataProducerFactory produces PriorityMetadataProducer from the given args.
|
// PriorityMetadataProducerFactory produces PriorityMetadataProducer from the given args.
|
||||||
type PriorityMetadataProducerFactory func(PluginFactoryArgs) algorithm.PriorityMetadataProducer
|
type PriorityMetadataProducerFactory func(PluginFactoryArgs) priorities.PriorityMetadataProducer
|
||||||
|
|
||||||
// PredicateMetadataProducerFactory produces PredicateMetadataProducer from the given args.
|
// PredicateMetadataProducerFactory produces PredicateMetadataProducer from the given args.
|
||||||
type PredicateMetadataProducerFactory func(PluginFactoryArgs) predicates.PredicateMetadataProducer
|
type PredicateMetadataProducerFactory func(PluginFactoryArgs) predicates.PredicateMetadataProducer
|
||||||
|
@ -62,12 +62,12 @@ type FitPredicateFactory func(PluginFactoryArgs) predicates.FitPredicate
|
||||||
// PriorityFunctionFactory produces a PriorityConfig from the given args.
|
// PriorityFunctionFactory produces a PriorityConfig from the given args.
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
// Use Map-Reduce pattern for priority functions.
|
// Use Map-Reduce pattern for priority functions.
|
||||||
type PriorityFunctionFactory func(PluginFactoryArgs) algorithm.PriorityFunction
|
type PriorityFunctionFactory func(PluginFactoryArgs) priorities.PriorityFunction
|
||||||
|
|
||||||
// PriorityFunctionFactory2 produces map & reduce priority functions
|
// PriorityFunctionFactory2 produces map & reduce priority functions
|
||||||
// from a given args.
|
// from a given args.
|
||||||
// FIXME: Rename to PriorityFunctionFactory.
|
// FIXME: Rename to PriorityFunctionFactory.
|
||||||
type PriorityFunctionFactory2 func(PluginFactoryArgs) (algorithm.PriorityMapFunction, algorithm.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 {
|
||||||
|
@ -270,9 +270,9 @@ func RegisterPredicateMetadataProducerFactory(factory PredicateMetadataProducerF
|
||||||
// with which the function was registered.
|
// with which the function was registered.
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
// Use Map-Reduce pattern for priority functions.
|
// Use Map-Reduce pattern for priority functions.
|
||||||
func RegisterPriorityFunction(name string, function algorithm.PriorityFunction, weight int) string {
|
func RegisterPriorityFunction(name string, function priorities.PriorityFunction, weight int) string {
|
||||||
return RegisterPriorityConfigFactory(name, PriorityConfigFactory{
|
return RegisterPriorityConfigFactory(name, PriorityConfigFactory{
|
||||||
Function: func(PluginFactoryArgs) algorithm.PriorityFunction {
|
Function: func(PluginFactoryArgs) priorities.PriorityFunction {
|
||||||
return function
|
return function
|
||||||
},
|
},
|
||||||
Weight: weight,
|
Weight: weight,
|
||||||
|
@ -284,11 +284,11 @@ func RegisterPriorityFunction(name string, function algorithm.PriorityFunction,
|
||||||
// FIXME: Rename to PriorityFunctionFactory.
|
// FIXME: Rename to PriorityFunctionFactory.
|
||||||
func RegisterPriorityFunction2(
|
func RegisterPriorityFunction2(
|
||||||
name string,
|
name string,
|
||||||
mapFunction algorithm.PriorityMapFunction,
|
mapFunction priorities.PriorityMapFunction,
|
||||||
reduceFunction algorithm.PriorityReduceFunction,
|
reduceFunction priorities.PriorityReduceFunction,
|
||||||
weight int) string {
|
weight int) string {
|
||||||
return RegisterPriorityConfigFactory(name, PriorityConfigFactory{
|
return RegisterPriorityConfigFactory(name, PriorityConfigFactory{
|
||||||
MapReduceFunction: func(PluginFactoryArgs) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
MapReduceFunction: func(PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction) {
|
||||||
return mapFunction, reduceFunction
|
return mapFunction, reduceFunction
|
||||||
},
|
},
|
||||||
Weight: weight,
|
Weight: weight,
|
||||||
|
@ -315,7 +315,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
|
||||||
if policy.Argument != nil {
|
if policy.Argument != nil {
|
||||||
if policy.Argument.ServiceAntiAffinity != nil {
|
if policy.Argument.ServiceAntiAffinity != nil {
|
||||||
pcf = &PriorityConfigFactory{
|
pcf = &PriorityConfigFactory{
|
||||||
MapReduceFunction: func(args PluginFactoryArgs) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
MapReduceFunction: func(args PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction) {
|
||||||
return priorities.NewServiceAntiAffinityPriority(
|
return priorities.NewServiceAntiAffinityPriority(
|
||||||
args.PodLister,
|
args.PodLister,
|
||||||
args.ServiceLister,
|
args.ServiceLister,
|
||||||
|
@ -326,7 +326,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
|
||||||
}
|
}
|
||||||
} else if policy.Argument.LabelPreference != nil {
|
} else if policy.Argument.LabelPreference != nil {
|
||||||
pcf = &PriorityConfigFactory{
|
pcf = &PriorityConfigFactory{
|
||||||
MapReduceFunction: func(args PluginFactoryArgs) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
MapReduceFunction: func(args PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction) {
|
||||||
return priorities.NewNodeLabelPriority(
|
return priorities.NewNodeLabelPriority(
|
||||||
policy.Argument.LabelPreference.Label,
|
policy.Argument.LabelPreference.Label,
|
||||||
policy.Argument.LabelPreference.Presence,
|
policy.Argument.LabelPreference.Presence,
|
||||||
|
@ -336,7 +336,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
|
||||||
}
|
}
|
||||||
} else if policy.Argument.RequestedToCapacityRatioArguments != nil {
|
} else if policy.Argument.RequestedToCapacityRatioArguments != nil {
|
||||||
pcf = &PriorityConfigFactory{
|
pcf = &PriorityConfigFactory{
|
||||||
MapReduceFunction: func(args PluginFactoryArgs) (algorithm.PriorityMapFunction, algorithm.PriorityReduceFunction) {
|
MapReduceFunction: func(args PluginFactoryArgs) (priorities.PriorityMapFunction, priorities.PriorityReduceFunction) {
|
||||||
scoringFunctionShape := buildScoringFunctionShapeFromRequestedToCapacityRatioArguments(policy.Argument.RequestedToCapacityRatioArguments)
|
scoringFunctionShape := buildScoringFunctionShapeFromRequestedToCapacityRatioArguments(policy.Argument.RequestedToCapacityRatioArguments)
|
||||||
p := priorities.RequestedToCapacityRatioResourceAllocationPriority(scoringFunctionShape)
|
p := priorities.RequestedToCapacityRatioResourceAllocationPriority(scoringFunctionShape)
|
||||||
return p.PriorityMap, nil
|
return p.PriorityMap, nil
|
||||||
|
@ -431,12 +431,12 @@ func getFitPredicateFunctions(names sets.String, args PluginFactoryArgs) (map[st
|
||||||
return predicates, nil
|
return predicates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPriorityMetadataProducer(args PluginFactoryArgs) (algorithm.PriorityMetadataProducer, error) {
|
func getPriorityMetadataProducer(args PluginFactoryArgs) (priorities.PriorityMetadataProducer, error) {
|
||||||
schedulerFactoryMutex.Lock()
|
schedulerFactoryMutex.Lock()
|
||||||
defer schedulerFactoryMutex.Unlock()
|
defer schedulerFactoryMutex.Unlock()
|
||||||
|
|
||||||
if priorityMetadataProducer == nil {
|
if priorityMetadataProducer == nil {
|
||||||
return algorithm.EmptyPriorityMetadataProducer, nil
|
return priorities.EmptyPriorityMetadataProducer, nil
|
||||||
}
|
}
|
||||||
return priorityMetadataProducer(args), nil
|
return priorityMetadataProducer(args), nil
|
||||||
}
|
}
|
||||||
|
@ -451,25 +451,25 @@ func getPredicateMetadataProducer(args PluginFactoryArgs) (predicates.PredicateM
|
||||||
return predicateMetadataProducer(args), nil
|
return predicateMetadataProducer(args), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPriorityFunctionConfigs(names sets.String, args PluginFactoryArgs) ([]algorithm.PriorityConfig, error) {
|
func getPriorityFunctionConfigs(names sets.String, args PluginFactoryArgs) ([]priorities.PriorityConfig, error) {
|
||||||
schedulerFactoryMutex.Lock()
|
schedulerFactoryMutex.Lock()
|
||||||
defer schedulerFactoryMutex.Unlock()
|
defer schedulerFactoryMutex.Unlock()
|
||||||
|
|
||||||
configs := []algorithm.PriorityConfig{}
|
configs := []priorities.PriorityConfig{}
|
||||||
for _, name := range names.List() {
|
for _, name := range names.List() {
|
||||||
factory, ok := priorityFunctionMap[name]
|
factory, ok := priorityFunctionMap[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("Invalid priority name %s specified - no corresponding function found", name)
|
return nil, fmt.Errorf("Invalid priority name %s specified - no corresponding function found", name)
|
||||||
}
|
}
|
||||||
if factory.Function != nil {
|
if factory.Function != nil {
|
||||||
configs = append(configs, algorithm.PriorityConfig{
|
configs = append(configs, priorities.PriorityConfig{
|
||||||
Name: name,
|
Name: name,
|
||||||
Function: factory.Function(args),
|
Function: factory.Function(args),
|
||||||
Weight: factory.Weight,
|
Weight: factory.Weight,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
mapFunction, reduceFunction := factory.MapReduceFunction(args)
|
mapFunction, reduceFunction := factory.MapReduceFunction(args)
|
||||||
configs = append(configs, algorithm.PriorityConfig{
|
configs = append(configs, priorities.PriorityConfig{
|
||||||
Name: name,
|
Name: name,
|
||||||
Map: mapFunction,
|
Map: mapFunction,
|
||||||
Reduce: reduceFunction,
|
Reduce: reduceFunction,
|
||||||
|
@ -484,7 +484,7 @@ func getPriorityFunctionConfigs(names sets.String, args PluginFactoryArgs) ([]al
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateSelectedConfigs validates the config weights to avoid the overflow.
|
// validateSelectedConfigs validates the config weights to avoid the overflow.
|
||||||
func validateSelectedConfigs(configs []algorithm.PriorityConfig) error {
|
func validateSelectedConfigs(configs []priorities.PriorityConfig) error {
|
||||||
var totalPriority int
|
var totalPriority int
|
||||||
for _, config := range configs {
|
for _, config := range configs {
|
||||||
// Checks totalPriority against MaxTotalPriority to avoid overflow
|
// Checks totalPriority against MaxTotalPriority to avoid overflow
|
||||||
|
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/api"
|
"k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
)
|
)
|
||||||
|
@ -54,22 +53,22 @@ func TestAlgorithmNameValidation(t *testing.T) {
|
||||||
func TestValidatePriorityConfigOverFlow(t *testing.T) {
|
func TestValidatePriorityConfigOverFlow(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
description string
|
description string
|
||||||
configs []algorithm.PriorityConfig
|
configs []priorities.PriorityConfig
|
||||||
expected bool
|
expected bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
description: "one of the weights is MaxInt",
|
description: "one of the weights is MaxInt",
|
||||||
configs: []algorithm.PriorityConfig{{Weight: api.MaxInt}, {Weight: 5}},
|
configs: []priorities.PriorityConfig{{Weight: api.MaxInt}, {Weight: 5}},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "after multiplication with MaxPriority the weight is larger than MaxWeight",
|
description: "after multiplication with MaxPriority the weight is larger than MaxWeight",
|
||||||
configs: []algorithm.PriorityConfig{{Weight: api.MaxInt/api.MaxPriority + api.MaxPriority}, {Weight: 5}},
|
configs: []priorities.PriorityConfig{{Weight: api.MaxInt/api.MaxPriority + api.MaxPriority}, {Weight: 5}},
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "normal weights",
|
description: "normal weights",
|
||||||
configs: []algorithm.PriorityConfig{{Weight: 10000}, {Weight: 5}},
|
configs: []priorities.PriorityConfig{{Weight: 10000}, {Weight: 5}},
|
||||||
expected: false,
|
expected: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import (
|
||||||
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
|
"k8s.io/kubernetes/pkg/controller/volume/persistentvolume"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/api"
|
"k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/core"
|
"k8s.io/kubernetes/pkg/scheduler/core"
|
||||||
|
@ -153,7 +154,7 @@ func (es mockScheduler) Schedule(pod *v1.Pod, ml algorithm.NodeLister) (core.Sch
|
||||||
func (es mockScheduler) Predicates() map[string]predicates.FitPredicate {
|
func (es mockScheduler) Predicates() map[string]predicates.FitPredicate {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (es mockScheduler) Prioritizers() []algorithm.PriorityConfig {
|
func (es mockScheduler) Prioritizers() []priorities.PriorityConfig {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,8 +639,8 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache schedulerintern
|
||||||
nil,
|
nil,
|
||||||
predicateMap,
|
predicateMap,
|
||||||
predicates.EmptyPredicateMetadataProducer,
|
predicates.EmptyPredicateMetadataProducer,
|
||||||
[]algorithm.PriorityConfig{},
|
[]priorities.PriorityConfig{},
|
||||||
algorithm.EmptyPriorityMetadataProducer,
|
priorities.EmptyPriorityMetadataProducer,
|
||||||
&EmptyPluginSet{},
|
&EmptyPluginSet{},
|
||||||
[]algorithm.SchedulerExtender{},
|
[]algorithm.SchedulerExtender{},
|
||||||
nil,
|
nil,
|
||||||
|
@ -690,8 +691,8 @@ func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, sc
|
||||||
nil,
|
nil,
|
||||||
predicateMap,
|
predicateMap,
|
||||||
predicates.EmptyPredicateMetadataProducer,
|
predicates.EmptyPredicateMetadataProducer,
|
||||||
[]algorithm.PriorityConfig{},
|
[]priorities.PriorityConfig{},
|
||||||
algorithm.EmptyPriorityMetadataProducer,
|
priorities.EmptyPriorityMetadataProducer,
|
||||||
&EmptyPluginSet{},
|
&EmptyPluginSet{},
|
||||||
[]algorithm.SchedulerExtender{},
|
[]algorithm.SchedulerExtender{},
|
||||||
nil,
|
nil,
|
||||||
|
|
Loading…
Reference in New Issue