2015-09-04 06:50:14 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2015 The Kubernetes Authors.
|
2015-09-04 06:50:14 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-01-31 16:03:46 +00:00
|
|
|
package core
|
2015-09-04 06:50:14 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-12-07 03:40:45 +00:00
|
|
|
"reflect"
|
2015-09-04 06:50:14 +00:00
|
|
|
"testing"
|
2016-09-30 13:14:29 +00:00
|
|
|
"time"
|
2015-09-04 06:50:14 +00:00
|
|
|
|
2017-06-22 18:24:23 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2017-01-17 03:38:19 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-01-11 14:09:48 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
2018-01-04 02:12:18 +00:00
|
|
|
"k8s.io/kubernetes/pkg/scheduler/algorithm"
|
2018-12-19 12:30:54 +00:00
|
|
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/predicates"
|
2019-01-08 21:09:11 +00:00
|
|
|
"k8s.io/kubernetes/pkg/scheduler/algorithm/priorities"
|
2018-01-04 02:12:18 +00:00
|
|
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
2018-09-22 00:30:18 +00:00
|
|
|
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
2018-09-21 23:18:48 +00:00
|
|
|
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
|
2018-12-08 02:36:11 +00:00
|
|
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
2018-01-04 02:12:18 +00:00
|
|
|
schedulertesting "k8s.io/kubernetes/pkg/scheduler/testing"
|
2017-11-17 02:21:03 +00:00
|
|
|
"k8s.io/kubernetes/pkg/scheduler/util"
|
2015-09-04 06:50:14 +00:00
|
|
|
)
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
type fitPredicate func(pod *v1.Pod, node *v1.Node) (bool, error)
|
|
|
|
type priorityFunc func(pod *v1.Pod, nodes []*v1.Node) (*schedulerapi.HostPriorityList, error)
|
2015-09-04 06:50:14 +00:00
|
|
|
|
|
|
|
type priorityConfig struct {
|
|
|
|
function priorityFunc
|
|
|
|
weight int
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func errorPredicateExtender(pod *v1.Pod, node *v1.Node) (bool, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
return false, fmt.Errorf("Some error")
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func falsePredicateExtender(pod *v1.Pod, node *v1.Node) (bool, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func truePredicateExtender(pod *v1.Pod, node *v1.Node) (bool, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func machine1PredicateExtender(pod *v1.Pod, node *v1.Node) (bool, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
if node.Name == "machine1" {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func machine2PredicateExtender(pod *v1.Pod, node *v1.Node) (bool, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
if node.Name == "machine2" {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func errorPrioritizerExtender(pod *v1.Pod, nodes []*v1.Node) (*schedulerapi.HostPriorityList, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
return &schedulerapi.HostPriorityList{}, fmt.Errorf("Some error")
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func machine1PrioritizerExtender(pod *v1.Pod, nodes []*v1.Node) (*schedulerapi.HostPriorityList, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
result := schedulerapi.HostPriorityList{}
|
2016-07-11 14:55:10 +00:00
|
|
|
for _, node := range nodes {
|
2015-09-04 06:50:14 +00:00
|
|
|
score := 1
|
|
|
|
if node.Name == "machine1" {
|
|
|
|
score = 10
|
|
|
|
}
|
2016-03-23 23:45:24 +00:00
|
|
|
result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: score})
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
return &result, nil
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func machine2PrioritizerExtender(pod *v1.Pod, nodes []*v1.Node) (*schedulerapi.HostPriorityList, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
result := schedulerapi.HostPriorityList{}
|
2016-07-11 14:55:10 +00:00
|
|
|
for _, node := range nodes {
|
2015-09-04 06:50:14 +00:00
|
|
|
score := 1
|
|
|
|
if node.Name == "machine2" {
|
|
|
|
score = 10
|
|
|
|
}
|
2016-03-23 23:45:24 +00:00
|
|
|
result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: score})
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
return &result, nil
|
|
|
|
}
|
|
|
|
|
2018-12-08 02:36:11 +00:00
|
|
|
func machine2Prioritizer(_ *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo, nodes []*v1.Node) (schedulerapi.HostPriorityList, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
result := []schedulerapi.HostPriority{}
|
2016-07-11 14:55:10 +00:00
|
|
|
for _, node := range nodes {
|
2015-09-04 06:50:14 +00:00
|
|
|
score := 1
|
|
|
|
if node.Name == "machine2" {
|
|
|
|
score = 10
|
|
|
|
}
|
2016-03-23 23:45:24 +00:00
|
|
|
result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: score})
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type FakeExtender struct {
|
2017-02-01 06:57:42 +00:00
|
|
|
predicates []fitPredicate
|
|
|
|
prioritizers []priorityConfig
|
|
|
|
weight int
|
|
|
|
nodeCacheCapable bool
|
2017-04-24 22:34:28 +00:00
|
|
|
filteredNodes []*v1.Node
|
2018-02-08 08:40:56 +00:00
|
|
|
unInterested bool
|
2018-03-19 19:15:24 +00:00
|
|
|
ignorable bool
|
2017-11-17 02:21:03 +00:00
|
|
|
|
|
|
|
// Cached node information for fake extender
|
2018-12-08 02:36:11 +00:00
|
|
|
cachedNodeNameToInfo map[string]*schedulernodeinfo.NodeInfo
|
2017-11-17 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 02:31:03 +00:00
|
|
|
func (f *FakeExtender) Name() string {
|
|
|
|
return "FakeExtender"
|
|
|
|
}
|
|
|
|
|
2018-03-19 19:15:24 +00:00
|
|
|
func (f *FakeExtender) IsIgnorable() bool {
|
|
|
|
return f.ignorable
|
|
|
|
}
|
|
|
|
|
2018-03-02 08:34:55 +00:00
|
|
|
func (f *FakeExtender) SupportsPreemption() bool {
|
|
|
|
// Assume preempt verb is always defined.
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeExtender) ProcessPreemption(
|
|
|
|
pod *v1.Pod,
|
|
|
|
nodeToVictims map[*v1.Node]*schedulerapi.Victims,
|
2018-12-08 02:36:11 +00:00
|
|
|
nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo,
|
2018-03-02 08:34:55 +00:00
|
|
|
) (map[*v1.Node]*schedulerapi.Victims, error) {
|
|
|
|
nodeToVictimsCopy := map[*v1.Node]*schedulerapi.Victims{}
|
|
|
|
// We don't want to change the original nodeToVictims
|
|
|
|
for k, v := range nodeToVictims {
|
2018-05-25 21:48:17 +00:00
|
|
|
// In real world implementation, extender's user should have their own way to get node object
|
2018-03-02 08:34:55 +00:00
|
|
|
// by name if needed (e.g. query kube-apiserver etc).
|
|
|
|
//
|
|
|
|
// For test purpose, we just use node from parameters directly.
|
|
|
|
nodeToVictimsCopy[k] = v
|
|
|
|
}
|
|
|
|
|
|
|
|
for node, victims := range nodeToVictimsCopy {
|
|
|
|
// Try to do preemption on extender side.
|
2018-03-30 21:01:09 +00:00
|
|
|
extenderVictimPods, extendernPDBViolations, fits, err := f.selectVictimsOnNodeByExtender(pod, node, nodeNameToInfo)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-03-02 08:34:55 +00:00
|
|
|
// If it's unfit after extender's preemption, this node is unresolvable by preemption overall,
|
|
|
|
// let's remove it from potential preemption nodes.
|
|
|
|
if !fits {
|
|
|
|
delete(nodeToVictimsCopy, node)
|
|
|
|
} else {
|
|
|
|
// Append new victims to original victims
|
|
|
|
nodeToVictimsCopy[node].Pods = append(victims.Pods, extenderVictimPods...)
|
|
|
|
nodeToVictimsCopy[node].NumPDBViolations = victims.NumPDBViolations + extendernPDBViolations
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodeToVictimsCopy, nil
|
|
|
|
}
|
|
|
|
|
2017-11-17 02:21:03 +00:00
|
|
|
// selectVictimsOnNodeByExtender checks the given nodes->pods map with predicates on extender's side.
|
|
|
|
// Returns:
|
|
|
|
// 1. More victim pods (if any) amended by preemption phase of extender.
|
|
|
|
// 2. Number of violating victim (used to calculate PDB).
|
|
|
|
// 3. Fits or not after preemption phase on extender's side.
|
|
|
|
func (f *FakeExtender) selectVictimsOnNodeByExtender(
|
|
|
|
pod *v1.Pod,
|
|
|
|
node *v1.Node,
|
2018-12-08 02:36:11 +00:00
|
|
|
nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo,
|
2018-03-30 21:01:09 +00:00
|
|
|
) ([]*v1.Pod, int, bool, error) {
|
2017-11-17 02:21:03 +00:00
|
|
|
// If a extender support preemption but have no cached node info, let's run filter to make sure
|
|
|
|
// default scheduler's decision still stand with given pod and node.
|
|
|
|
if !f.nodeCacheCapable {
|
2018-03-30 21:01:09 +00:00
|
|
|
fits, err := f.runPredicate(pod, node)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, false, err
|
2017-11-17 02:21:03 +00:00
|
|
|
}
|
2018-03-30 21:01:09 +00:00
|
|
|
if !fits {
|
|
|
|
return nil, 0, false, nil
|
|
|
|
}
|
|
|
|
return []*v1.Pod{}, 0, true, nil
|
2017-11-17 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, as a extender support preemption and have cached node info, we will assume cachedNodeNameToInfo is available
|
2018-03-02 08:34:55 +00:00
|
|
|
// and get cached node info by given node name.
|
2017-11-17 02:21:03 +00:00
|
|
|
nodeInfoCopy := f.cachedNodeNameToInfo[node.GetName()].Clone()
|
|
|
|
|
|
|
|
potentialVictims := util.SortableList{CompFunc: util.HigherPriorityPod}
|
|
|
|
|
|
|
|
removePod := func(rp *v1.Pod) {
|
|
|
|
nodeInfoCopy.RemovePod(rp)
|
|
|
|
}
|
|
|
|
addPod := func(ap *v1.Pod) {
|
|
|
|
nodeInfoCopy.AddPod(ap)
|
|
|
|
}
|
|
|
|
// As the first step, remove all the lower priority pods from the node and
|
|
|
|
// check if the given pod can be scheduled.
|
|
|
|
podPriority := util.GetPodPriority(pod)
|
|
|
|
for _, p := range nodeInfoCopy.Pods() {
|
|
|
|
if util.GetPodPriority(p) < podPriority {
|
|
|
|
potentialVictims.Items = append(potentialVictims.Items, p)
|
|
|
|
removePod(p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
potentialVictims.Sort()
|
|
|
|
|
|
|
|
// If the new pod does not fit after removing all the lower priority pods,
|
|
|
|
// we are almost done and this node is not suitable for preemption.
|
2018-03-30 21:01:09 +00:00
|
|
|
fits, err := f.runPredicate(pod, nodeInfoCopy.Node())
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, false, err
|
|
|
|
}
|
|
|
|
if !fits {
|
|
|
|
return nil, 0, false, nil
|
2017-11-17 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var victims []*v1.Pod
|
|
|
|
|
|
|
|
// TODO(harry): handle PDBs in the future.
|
|
|
|
numViolatingVictim := 0
|
|
|
|
|
|
|
|
reprievePod := func(p *v1.Pod) bool {
|
|
|
|
addPod(p)
|
|
|
|
fits, _ := f.runPredicate(pod, nodeInfoCopy.Node())
|
|
|
|
if !fits {
|
|
|
|
removePod(p)
|
|
|
|
victims = append(victims, p)
|
|
|
|
}
|
|
|
|
return fits
|
|
|
|
}
|
|
|
|
|
|
|
|
// For now, assume all potential victims to be non-violating.
|
|
|
|
// Now we try to reprieve non-violating victims.
|
|
|
|
for _, p := range potentialVictims.Items {
|
|
|
|
reprievePod(p.(*v1.Pod))
|
|
|
|
}
|
|
|
|
|
2018-03-30 21:01:09 +00:00
|
|
|
return victims, numViolatingVictim, true, nil
|
2017-11-17 02:21:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// runPredicate run predicates of extender one by one for given pod and node.
|
|
|
|
// Returns: fits or not.
|
|
|
|
func (f *FakeExtender) runPredicate(pod *v1.Pod, node *v1.Node) (bool, error) {
|
|
|
|
fits := true
|
|
|
|
var err error
|
|
|
|
for _, predicate := range f.predicates {
|
|
|
|
fits, err = predicate(pod, node)
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
if !fits {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fits, nil
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 02:36:11 +00:00
|
|
|
func (f *FakeExtender) Filter(pod *v1.Pod, nodes []*v1.Node, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo) ([]*v1.Node, schedulerapi.FailedNodesMap, error) {
|
2016-11-18 20:52:35 +00:00
|
|
|
filtered := []*v1.Node{}
|
2016-06-27 09:31:46 +00:00
|
|
|
failedNodesMap := schedulerapi.FailedNodesMap{}
|
2016-07-11 14:55:10 +00:00
|
|
|
for _, node := range nodes {
|
2017-11-17 02:21:03 +00:00
|
|
|
fits, err := f.runPredicate(pod, node)
|
|
|
|
if err != nil {
|
|
|
|
return []*v1.Node{}, schedulerapi.FailedNodesMap{}, err
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
if fits {
|
|
|
|
filtered = append(filtered, node)
|
2016-06-27 09:31:46 +00:00
|
|
|
} else {
|
|
|
|
failedNodesMap[node.Name] = "FakeExtender failed"
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-01 06:57:42 +00:00
|
|
|
|
2017-04-24 22:34:28 +00:00
|
|
|
f.filteredNodes = filtered
|
2017-02-01 06:57:42 +00:00
|
|
|
if f.nodeCacheCapable {
|
|
|
|
return filtered, failedNodesMap, nil
|
|
|
|
}
|
2016-06-27 09:31:46 +00:00
|
|
|
return filtered, failedNodesMap, nil
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 20:52:35 +00:00
|
|
|
func (f *FakeExtender) Prioritize(pod *v1.Pod, nodes []*v1.Node) (*schedulerapi.HostPriorityList, int, error) {
|
2015-09-04 06:50:14 +00:00
|
|
|
result := schedulerapi.HostPriorityList{}
|
|
|
|
combinedScores := map[string]int{}
|
|
|
|
for _, prioritizer := range f.prioritizers {
|
|
|
|
weight := prioritizer.weight
|
|
|
|
if weight == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
priorityFunc := prioritizer.function
|
|
|
|
prioritizedList, err := priorityFunc(pod, nodes)
|
|
|
|
if err != nil {
|
|
|
|
return &schedulerapi.HostPriorityList{}, 0, err
|
|
|
|
}
|
|
|
|
for _, hostEntry := range *prioritizedList {
|
|
|
|
combinedScores[hostEntry.Host] += hostEntry.Score * weight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for host, score := range combinedScores {
|
|
|
|
result = append(result, schedulerapi.HostPriority{Host: host, Score: score})
|
|
|
|
}
|
|
|
|
return &result, f.weight, nil
|
|
|
|
}
|
|
|
|
|
2017-04-24 22:34:28 +00:00
|
|
|
func (f *FakeExtender) Bind(binding *v1.Binding) error {
|
|
|
|
if len(f.filteredNodes) != 0 {
|
|
|
|
for _, node := range f.filteredNodes {
|
|
|
|
if node.Name == binding.Target.Name {
|
|
|
|
f.filteredNodes = nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err := fmt.Errorf("Node %v not in filtered nodes %v", binding.Target.Name, f.filteredNodes)
|
|
|
|
f.filteredNodes = nil
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *FakeExtender) IsBinder() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-02-08 08:40:56 +00:00
|
|
|
func (f *FakeExtender) IsInterested(pod *v1.Pod) bool {
|
|
|
|
return !f.unInterested
|
|
|
|
}
|
|
|
|
|
2017-08-10 01:15:40 +00:00
|
|
|
var _ algorithm.SchedulerExtender = &FakeExtender{}
|
|
|
|
|
2015-09-04 06:50:14 +00:00
|
|
|
func TestGenericSchedulerWithExtenders(t *testing.T) {
|
|
|
|
tests := []struct {
|
2018-12-07 03:40:45 +00:00
|
|
|
name string
|
|
|
|
predicates map[string]predicates.FitPredicate
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers []priorities.PriorityConfig
|
2018-12-07 03:40:45 +00:00
|
|
|
extenders []FakeExtender
|
|
|
|
nodes []string
|
|
|
|
expectedResult ScheduleResult
|
|
|
|
expectsErr bool
|
2015-09-04 06:50:14 +00:00
|
|
|
}{
|
|
|
|
{
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
2015-09-04 06:50:14 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{truePredicateExtender},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{errorPredicateExtender},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nodes: []string{"machine1", "machine2"},
|
|
|
|
expectsErr: true,
|
|
|
|
name: "test 1",
|
|
|
|
},
|
|
|
|
{
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
2015-09-04 06:50:14 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{truePredicateExtender},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{falsePredicateExtender},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nodes: []string{"machine1", "machine2"},
|
|
|
|
expectsErr: true,
|
|
|
|
name: "test 2",
|
|
|
|
},
|
|
|
|
{
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
2015-09-04 06:50:14 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{truePredicateExtender},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{machine1PredicateExtender},
|
|
|
|
},
|
|
|
|
},
|
2018-12-07 03:40:45 +00:00
|
|
|
nodes: []string{"machine1", "machine2"},
|
|
|
|
expectedResult: ScheduleResult{
|
|
|
|
SuggestedHost: "machine1",
|
|
|
|
EvaluatedNodes: 2,
|
|
|
|
FeasibleNodes: 1,
|
|
|
|
},
|
|
|
|
name: "test 3",
|
2015-09-04 06:50:14 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
2015-09-04 06:50:14 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{machine2PredicateExtender},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{machine1PredicateExtender},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nodes: []string{"machine1", "machine2"},
|
|
|
|
expectsErr: true,
|
|
|
|
name: "test 4",
|
|
|
|
},
|
|
|
|
{
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
2015-09-04 06:50:14 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{truePredicateExtender},
|
|
|
|
prioritizers: []priorityConfig{{errorPrioritizerExtender, 10}},
|
|
|
|
weight: 1,
|
|
|
|
},
|
|
|
|
},
|
2018-12-07 03:40:45 +00:00
|
|
|
nodes: []string{"machine1"},
|
|
|
|
expectedResult: ScheduleResult{
|
|
|
|
SuggestedHost: "machine1",
|
|
|
|
EvaluatedNodes: 1,
|
|
|
|
FeasibleNodes: 1,
|
|
|
|
},
|
|
|
|
name: "test 5",
|
2015-09-04 06:50:14 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
2015-09-04 06:50:14 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{truePredicateExtender},
|
|
|
|
prioritizers: []priorityConfig{{machine1PrioritizerExtender, 10}},
|
|
|
|
weight: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{truePredicateExtender},
|
|
|
|
prioritizers: []priorityConfig{{machine2PrioritizerExtender, 10}},
|
|
|
|
weight: 5,
|
|
|
|
},
|
|
|
|
},
|
2018-12-07 03:40:45 +00:00
|
|
|
nodes: []string{"machine1", "machine2"},
|
|
|
|
expectedResult: ScheduleResult{
|
|
|
|
SuggestedHost: "machine2",
|
|
|
|
EvaluatedNodes: 2,
|
|
|
|
FeasibleNodes: 2,
|
|
|
|
},
|
|
|
|
name: "test 6",
|
2015-09-04 06:50:14 +00:00
|
|
|
},
|
|
|
|
{
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Function: machine2Prioritizer, Weight: 20}},
|
2015-09-04 06:50:14 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{truePredicateExtender},
|
|
|
|
prioritizers: []priorityConfig{{machine1PrioritizerExtender, 10}},
|
|
|
|
weight: 1,
|
|
|
|
},
|
|
|
|
},
|
2018-12-07 03:40:45 +00:00
|
|
|
nodes: []string{"machine1", "machine2"},
|
|
|
|
expectedResult: ScheduleResult{
|
|
|
|
SuggestedHost: "machine2",
|
|
|
|
EvaluatedNodes: 2,
|
|
|
|
FeasibleNodes: 2,
|
|
|
|
}, // machine2 has higher score
|
|
|
|
name: "test 7",
|
2015-09-04 06:50:14 +00:00
|
|
|
},
|
2018-02-08 08:40:56 +00:00
|
|
|
{
|
|
|
|
// Scheduler is expected to not send pod to extender in
|
|
|
|
// Filter/Prioritize phases if the extender is not interested in
|
|
|
|
// the pod.
|
|
|
|
//
|
2018-03-30 21:01:09 +00:00
|
|
|
// If scheduler sends the pod by mistake, the test would fail
|
2018-02-08 08:40:56 +00:00
|
|
|
// because of the errors from errorPredicateExtender and/or
|
|
|
|
// errorPrioritizerExtender.
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Function: machine2Prioritizer, Weight: 1}},
|
2018-02-08 08:40:56 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{errorPredicateExtender},
|
|
|
|
prioritizers: []priorityConfig{{errorPrioritizerExtender, 10}},
|
|
|
|
unInterested: true,
|
|
|
|
},
|
|
|
|
},
|
2018-12-07 03:40:45 +00:00
|
|
|
nodes: []string{"machine1", "machine2"},
|
|
|
|
expectsErr: false,
|
|
|
|
expectedResult: ScheduleResult{
|
|
|
|
SuggestedHost: "machine2",
|
|
|
|
EvaluatedNodes: 2,
|
|
|
|
FeasibleNodes: 2,
|
|
|
|
}, // machine2 has higher score
|
|
|
|
name: "test 8",
|
2018-02-08 08:40:56 +00:00
|
|
|
},
|
2018-03-19 19:15:24 +00:00
|
|
|
{
|
|
|
|
// Scheduling is expected to not fail in
|
|
|
|
// Filter/Prioritize phases if the extender is not available and ignorable.
|
|
|
|
//
|
2018-03-30 21:01:09 +00:00
|
|
|
// If scheduler did not ignore the extender, the test would fail
|
2018-03-19 19:15:24 +00:00
|
|
|
// because of the errors from errorPredicateExtender.
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates: map[string]predicates.FitPredicate{"true": truePredicate},
|
2019-01-08 21:09:11 +00:00
|
|
|
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
|
2018-03-19 19:15:24 +00:00
|
|
|
extenders: []FakeExtender{
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{errorPredicateExtender},
|
|
|
|
ignorable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
predicates: []fitPredicate{machine1PredicateExtender},
|
|
|
|
},
|
|
|
|
},
|
2018-12-07 03:40:45 +00:00
|
|
|
nodes: []string{"machine1", "machine2"},
|
|
|
|
expectsErr: false,
|
|
|
|
expectedResult: ScheduleResult{
|
|
|
|
SuggestedHost: "machine1",
|
|
|
|
EvaluatedNodes: 2,
|
|
|
|
FeasibleNodes: 1,
|
|
|
|
},
|
|
|
|
name: "test 9",
|
2018-03-19 19:15:24 +00:00
|
|
|
},
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2018-06-01 14:16:50 +00:00
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
extenders := []algorithm.SchedulerExtender{}
|
|
|
|
for ii := range test.extenders {
|
|
|
|
extenders = append(extenders, &test.extenders[ii])
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
2018-09-22 00:30:18 +00:00
|
|
|
cache := schedulerinternalcache.New(time.Duration(0), wait.NeverStop)
|
2018-06-01 14:16:50 +00:00
|
|
|
for _, name := range test.nodes {
|
|
|
|
cache.AddNode(createNode(name))
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
2018-07-24 20:46:40 +00:00
|
|
|
queue := internalqueue.NewSchedulingQueue(nil)
|
2018-06-01 14:16:50 +00:00
|
|
|
scheduler := NewGenericScheduler(
|
|
|
|
cache,
|
|
|
|
queue,
|
|
|
|
test.predicates,
|
2018-12-19 12:30:54 +00:00
|
|
|
predicates.EmptyPredicateMetadataProducer,
|
2018-06-01 14:16:50 +00:00
|
|
|
test.prioritizers,
|
2019-01-08 21:09:11 +00:00
|
|
|
priorities.EmptyPriorityMetadataProducer,
|
2018-11-09 02:08:38 +00:00
|
|
|
emptyPluginSet,
|
2018-06-01 14:16:50 +00:00
|
|
|
extenders,
|
|
|
|
nil,
|
|
|
|
schedulertesting.FakePersistentVolumeClaimLister{},
|
2018-09-19 00:05:48 +00:00
|
|
|
schedulertesting.FakePDBLister{},
|
2018-06-01 14:16:50 +00:00
|
|
|
false,
|
2018-07-28 00:17:09 +00:00
|
|
|
false,
|
|
|
|
schedulerapi.DefaultPercentageOfNodesToScore)
|
2018-06-01 14:16:50 +00:00
|
|
|
podIgnored := &v1.Pod{}
|
2018-12-07 03:40:45 +00:00
|
|
|
result, err := scheduler.Schedule(podIgnored, schedulertesting.FakeNodeLister(makeNodeList(test.nodes)))
|
2018-06-01 14:16:50 +00:00
|
|
|
if test.expectsErr {
|
|
|
|
if err == nil {
|
2018-12-07 03:40:45 +00:00
|
|
|
t.Errorf("Unexpected non-error, result %+v", result)
|
2018-06-01 14:16:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unexpected error: %v", err)
|
|
|
|
return
|
|
|
|
}
|
2018-12-07 03:40:45 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(result, test.expectedResult) {
|
|
|
|
t.Errorf("Expected: %+v, Saw: %+v", test.expectedResult, result)
|
2018-06-01 14:16:50 +00:00
|
|
|
}
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
2018-06-01 14:16:50 +00:00
|
|
|
})
|
2015-09-04 06:50:14 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-17 02:21:03 +00:00
|
|
|
|
|
|
|
func createNode(name string) *v1.Node {
|
|
|
|
return &v1.Node{ObjectMeta: metav1.ObjectMeta{Name: name}}
|
|
|
|
}
|