mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Refactor scheduler.New so that all framework-related parameters are passed as options
This commit is contained in:
parent
8b611ac7df
commit
30e7016ccf
@ -182,14 +182,15 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}, regis
|
|||||||
cc.Recorder,
|
cc.Recorder,
|
||||||
cc.ComponentConfig.AlgorithmSource,
|
cc.ComponentConfig.AlgorithmSource,
|
||||||
stopCh,
|
stopCh,
|
||||||
registry,
|
|
||||||
cc.ComponentConfig.Plugins,
|
|
||||||
cc.ComponentConfig.PluginConfig,
|
|
||||||
scheduler.WithName(cc.ComponentConfig.SchedulerName),
|
scheduler.WithName(cc.ComponentConfig.SchedulerName),
|
||||||
scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight),
|
scheduler.WithHardPodAffinitySymmetricWeight(cc.ComponentConfig.HardPodAffinitySymmetricWeight),
|
||||||
scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption),
|
scheduler.WithPreemptionDisabled(cc.ComponentConfig.DisablePreemption),
|
||||||
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
|
scheduler.WithPercentageOfNodesToScore(cc.ComponentConfig.PercentageOfNodesToScore),
|
||||||
scheduler.WithBindTimeoutSeconds(*cc.ComponentConfig.BindTimeoutSeconds))
|
scheduler.WithBindTimeoutSeconds(*cc.ComponentConfig.BindTimeoutSeconds),
|
||||||
|
scheduler.WithFrameworkRegistry(registry),
|
||||||
|
scheduler.WithFrameworkPlugins(cc.ComponentConfig.Plugins),
|
||||||
|
scheduler.WithFrameworkPluginConfig(cc.ComponentConfig.PluginConfig),
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ go_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",
|
||||||
"//pkg/scheduler/factory:go_default_library",
|
"//pkg/scheduler/factory:go_default_library",
|
||||||
|
"//pkg/scheduler/framework/plugins:go_default_library",
|
||||||
"//pkg/scheduler/framework/v1alpha1:go_default_library",
|
"//pkg/scheduler/framework/v1alpha1: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",
|
||||||
|
@ -11,7 +11,6 @@ go_test(
|
|||||||
"//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",
|
||||||
"//pkg/scheduler/factory:go_default_library",
|
"//pkg/scheduler/factory:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins:go_default_library",
|
|
||||||
"//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/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||||
|
@ -32,7 +32,6 @@ import (
|
|||||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/core"
|
"k8s.io/kubernetes/pkg/scheduler/core"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/factory"
|
"k8s.io/kubernetes/pkg/scheduler/factory"
|
||||||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCompatibility_v1_Scheduler(t *testing.T) {
|
func TestCompatibility_v1_Scheduler(t *testing.T) {
|
||||||
@ -1163,9 +1162,6 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
|
|||||||
nil,
|
nil,
|
||||||
algorithmSrc,
|
algorithmSrc,
|
||||||
make(chan struct{}),
|
make(chan struct{}),
|
||||||
schedulerframework.NewDefaultRegistry(),
|
|
||||||
nil,
|
|
||||||
[]kubeschedulerconfig.PluginConfig{},
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%s: Error constructing: %v", v, err)
|
t.Fatalf("%s: Error constructing: %v", v, err)
|
||||||
|
@ -40,6 +40,7 @@ import (
|
|||||||
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"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/factory"
|
"k8s.io/kubernetes/pkg/scheduler/factory"
|
||||||
|
frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||||
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
|
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
|
||||||
@ -114,6 +115,10 @@ type schedulerOptions struct {
|
|||||||
disablePreemption bool
|
disablePreemption bool
|
||||||
percentageOfNodesToScore int32
|
percentageOfNodesToScore int32
|
||||||
bindTimeoutSeconds int64
|
bindTimeoutSeconds int64
|
||||||
|
frameworkRegistry framework.Registry
|
||||||
|
frameworkConfigProducerRegistry *frameworkplugins.ConfigProducerRegistry
|
||||||
|
frameworkPlugins *kubeschedulerconfig.Plugins
|
||||||
|
frameworkPluginConfig []kubeschedulerconfig.PluginConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option configures a Scheduler
|
// Option configures a Scheduler
|
||||||
@ -154,12 +159,51 @@ func WithBindTimeoutSeconds(bindTimeoutSeconds int64) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithFrameworkRegistry sets the framework registry.
|
||||||
|
func WithFrameworkRegistry(registry framework.Registry) Option {
|
||||||
|
return func(o *schedulerOptions) {
|
||||||
|
o.frameworkRegistry = registry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithFrameworkConfigProducerRegistry sets the framework plugin producer registry.
|
||||||
|
func WithFrameworkConfigProducerRegistry(registry *frameworkplugins.ConfigProducerRegistry) Option {
|
||||||
|
return func(o *schedulerOptions) {
|
||||||
|
o.frameworkConfigProducerRegistry = registry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithFrameworkPlugins sets the plugins that the framework should be configured with.
|
||||||
|
func WithFrameworkPlugins(plugins *kubeschedulerconfig.Plugins) Option {
|
||||||
|
return func(o *schedulerOptions) {
|
||||||
|
o.frameworkPlugins = plugins
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithFrameworkPluginConfig sets the PluginConfig slice that the framework should be configured with.
|
||||||
|
func WithFrameworkPluginConfig(pluginConfig []kubeschedulerconfig.PluginConfig) Option {
|
||||||
|
return func(o *schedulerOptions) {
|
||||||
|
o.frameworkPluginConfig = pluginConfig
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var defaultSchedulerOptions = schedulerOptions{
|
var defaultSchedulerOptions = schedulerOptions{
|
||||||
schedulerName: v1.DefaultSchedulerName,
|
schedulerName: v1.DefaultSchedulerName,
|
||||||
hardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
|
hardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
|
||||||
disablePreemption: false,
|
disablePreemption: false,
|
||||||
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
|
percentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
|
||||||
bindTimeoutSeconds: BindTimeoutSeconds,
|
bindTimeoutSeconds: BindTimeoutSeconds,
|
||||||
|
frameworkRegistry: frameworkplugins.NewDefaultRegistry(),
|
||||||
|
frameworkConfigProducerRegistry: frameworkplugins.NewDefaultConfigProducerRegistry(),
|
||||||
|
// The plugins and pluginConfig options are currently nil because we currently don't have
|
||||||
|
// "default" plugins. All plugins that we run through the framework currently come from two
|
||||||
|
// sources: 1) specified in component config, in which case those two options should be
|
||||||
|
// set using their corresponding With* functions, 2) predicate/priority-mapped plugins, which
|
||||||
|
// pluginConfigProducerRegistry contains a mapping for and produces their configurations.
|
||||||
|
// TODO(ahg-g) Once predicates and priorities are migrated to natively run as plugins, the
|
||||||
|
// below two parameters will be populated accordingly.
|
||||||
|
frameworkPlugins: nil,
|
||||||
|
frameworkPluginConfig: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a Scheduler
|
// New returns a Scheduler
|
||||||
@ -178,9 +222,6 @@ func New(client clientset.Interface,
|
|||||||
recorder events.EventRecorder,
|
recorder events.EventRecorder,
|
||||||
schedulerAlgorithmSource kubeschedulerconfig.SchedulerAlgorithmSource,
|
schedulerAlgorithmSource kubeschedulerconfig.SchedulerAlgorithmSource,
|
||||||
stopCh <-chan struct{},
|
stopCh <-chan struct{},
|
||||||
registry framework.Registry,
|
|
||||||
plugins *kubeschedulerconfig.Plugins,
|
|
||||||
pluginConfig []kubeschedulerconfig.PluginConfig,
|
|
||||||
opts ...Option) (*Scheduler, error) {
|
opts ...Option) (*Scheduler, error) {
|
||||||
|
|
||||||
options := defaultSchedulerOptions
|
options := defaultSchedulerOptions
|
||||||
@ -205,9 +246,10 @@ func New(client clientset.Interface,
|
|||||||
DisablePreemption: options.disablePreemption,
|
DisablePreemption: options.disablePreemption,
|
||||||
PercentageOfNodesToScore: options.percentageOfNodesToScore,
|
PercentageOfNodesToScore: options.percentageOfNodesToScore,
|
||||||
BindTimeoutSeconds: options.bindTimeoutSeconds,
|
BindTimeoutSeconds: options.bindTimeoutSeconds,
|
||||||
Registry: registry,
|
Registry: options.frameworkRegistry,
|
||||||
Plugins: plugins,
|
PluginConfigProducerRegistry: options.frameworkConfigProducerRegistry,
|
||||||
PluginConfig: pluginConfig,
|
Plugins: options.frameworkPlugins,
|
||||||
|
PluginConfig: options.frameworkPluginConfig,
|
||||||
})
|
})
|
||||||
var config *factory.Config
|
var config *factory.Config
|
||||||
source := schedulerAlgorithmSource
|
source := schedulerAlgorithmSource
|
||||||
|
@ -59,11 +59,9 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
emptyPluginRegistry = framework.Registry{}
|
emptyPluginRegistry = framework.Registry{}
|
||||||
// emptyPluginConfig is an empty plugin config used in tests.
|
|
||||||
emptyPluginConfig []kubeschedulerconfig.PluginConfig
|
|
||||||
// emptyFramework is an empty framework used in tests.
|
// emptyFramework is an empty framework used in tests.
|
||||||
// Note: If the test runs in goroutine, please don't use this variable to avoid a race condition.
|
// Note: If the test runs in goroutine, please don't use this variable to avoid a race condition.
|
||||||
emptyFramework, _ = framework.NewFramework(emptyPluginRegistry, nil, emptyPluginConfig)
|
emptyFramework, _ = framework.NewFramework(emptyPluginRegistry, nil, nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeBinder struct {
|
type fakeBinder struct {
|
||||||
@ -178,7 +176,6 @@ func TestSchedulerCreation(t *testing.T) {
|
|||||||
testSource := "testProvider"
|
testSource := "testProvider"
|
||||||
eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1beta1().Events("")})
|
eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{Interface: client.EventsV1beta1().Events("")})
|
||||||
|
|
||||||
defaultBindTimeout := int64(30)
|
|
||||||
factory.RegisterFitPredicate("PredicateOne", PredicateOne)
|
factory.RegisterFitPredicate("PredicateOne", PredicateOne)
|
||||||
factory.RegisterPriorityFunction("PriorityOne", PriorityOne, 1)
|
factory.RegisterPriorityFunction("PriorityOne", PriorityOne, 1)
|
||||||
factory.RegisterAlgorithmProvider(testSource, sets.NewString("PredicateOne"), sets.NewString("PriorityOne"))
|
factory.RegisterAlgorithmProvider(testSource, sets.NewString("PredicateOne"), sets.NewString("PriorityOne"))
|
||||||
@ -200,10 +197,7 @@ func TestSchedulerCreation(t *testing.T) {
|
|||||||
eventBroadcaster.NewRecorder(scheme.Scheme, "scheduler"),
|
eventBroadcaster.NewRecorder(scheme.Scheme, "scheduler"),
|
||||||
kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &testSource},
|
kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &testSource},
|
||||||
stopCh,
|
stopCh,
|
||||||
emptyPluginRegistry,
|
)
|
||||||
nil,
|
|
||||||
emptyPluginConfig,
|
|
||||||
WithBindTimeoutSeconds(defaultBindTimeout))
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create scheduler: %v", err)
|
t.Fatalf("Failed to create scheduler: %v", err)
|
||||||
|
@ -23,7 +23,6 @@ go_test(
|
|||||||
"//pkg/scheduler/algorithmprovider:go_default_library",
|
"//pkg/scheduler/algorithmprovider: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/framework/plugins:go_default_library",
|
|
||||||
"//pkg/util/labels:go_default_library",
|
"//pkg/util/labels:go_default_library",
|
||||||
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
|
@ -51,7 +51,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
|
||||||
labelsutil "k8s.io/kubernetes/pkg/util/labels"
|
labelsutil "k8s.io/kubernetes/pkg/util/labels"
|
||||||
"k8s.io/kubernetes/test/integration/framework"
|
"k8s.io/kubernetes/test/integration/framework"
|
||||||
)
|
)
|
||||||
@ -126,9 +125,6 @@ func setupScheduler(
|
|||||||
Provider: &defaultProviderName,
|
Provider: &defaultProviderName,
|
||||||
},
|
},
|
||||||
stopCh,
|
stopCh,
|
||||||
schedulerframework.NewDefaultRegistry(),
|
|
||||||
nil,
|
|
||||||
[]schedulerconfig.PluginConfig{},
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Couldn't create scheduler: %v", err)
|
t.Fatalf("Couldn't create scheduler: %v", err)
|
||||||
|
@ -97,8 +97,6 @@ go_library(
|
|||||||
"//pkg/scheduler/api/latest:go_default_library",
|
"//pkg/scheduler/api/latest:go_default_library",
|
||||||
"//pkg/scheduler/apis/config:go_default_library",
|
"//pkg/scheduler/apis/config:go_default_library",
|
||||||
"//pkg/scheduler/factory:go_default_library",
|
"//pkg/scheduler/factory:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins:go_default_library",
|
|
||||||
"//pkg/scheduler/framework/v1alpha1:go_default_library",
|
|
||||||
"//pkg/util/taints:go_default_library",
|
"//pkg/util/taints:go_default_library",
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",
|
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
|
scheduler "k8s.io/kubernetes/pkg/scheduler"
|
||||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
@ -456,23 +457,13 @@ func TestPreFilterPlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Set empty plugin config for testing
|
|
||||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "prefilter-plugin", nil), 2,
|
||||||
initTestMaster(t, "prefilter-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
|
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
fail bool
|
fail bool
|
||||||
reject bool
|
reject bool
|
||||||
@ -495,18 +486,18 @@ func TestPreFilterPlugin(t *testing.T) {
|
|||||||
preFilterPlugin.failPreFilter = test.fail
|
preFilterPlugin.failPreFilter = test.fail
|
||||||
preFilterPlugin.rejectPreFilter = test.reject
|
preFilterPlugin.rejectPreFilter = test.reject
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.reject || test.fail {
|
if test.reject || test.fail {
|
||||||
if err = waitForPodUnschedulable(cs, pod); err != nil {
|
if err = waitForPodUnschedulable(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -516,7 +507,7 @@ func TestPreFilterPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
preFilterPlugin.reset()
|
preFilterPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,27 +529,30 @@ func TestScorePlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
context, cs := initTestContextForScorePlugin(t, plugins, registry)
|
|
||||||
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "score-plugin", nil), 10,
|
||||||
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
for i, fail := range []bool{false, true} {
|
for i, fail := range []bool{false, true} {
|
||||||
scorePlugin.failScore = fail
|
scorePlugin.failScore = fail
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error while creating a test pod: %v", err)
|
t.Fatalf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fail {
|
if fail {
|
||||||
if err = waitForPodUnschedulable(cs, pod); err != nil {
|
if err = waitForPodUnschedulable(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
} else {
|
} else {
|
||||||
p, err := getPod(cs, pod.Name, pod.Namespace)
|
p, err := getPod(context.clientSet, pod.Name, pod.Namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Failed to retrieve the pod. error: %v", err)
|
t.Errorf("Failed to retrieve the pod. error: %v", err)
|
||||||
} else if p.Spec.NodeName != scorePlugin.highScoreNode {
|
} else if p.Spec.NodeName != scorePlugin.highScoreNode {
|
||||||
@ -572,7 +566,7 @@ func TestScorePlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scorePlugin.reset()
|
scorePlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,17 +588,20 @@ func TestNormalizeScorePlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
context, cs := initTestContextForScorePlugin(t, plugins, registry)
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "score-plugin", nil), 10,
|
||||||
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
|
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error while creating a test pod: %v", err)
|
t.Fatalf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,37 +631,29 @@ func TestReservePlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Set empty plugin config for testing
|
|
||||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "reserve-plugin", nil), 2,
|
||||||
initTestMaster(t, "reserve-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, fail := range []bool{false, true} {
|
for _, fail := range []bool{false, true} {
|
||||||
reservePlugin.failReserve = fail
|
reservePlugin.failReserve = fail
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fail {
|
if fail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second,
|
||||||
|
podSchedulingError(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -674,7 +663,7 @@ func TestReservePlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reservePlugin.reset()
|
reservePlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -702,18 +691,12 @@ func TestPrebindPlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "prebind-plugin", nil), 2,
|
||||||
initTestMaster(t, "prebind-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugins, preBindPluginConfig, time.Second)
|
scheduler.WithFrameworkPluginConfig(preBindPluginConfig),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
fail bool
|
fail bool
|
||||||
reject bool
|
reject bool
|
||||||
@ -740,17 +723,17 @@ func TestPrebindPlugin(t *testing.T) {
|
|||||||
preBindPlugin.failPreBind = test.fail
|
preBindPlugin.failPreBind = test.fail
|
||||||
preBindPlugin.rejectPreBind = test.reject
|
preBindPlugin.rejectPreBind = test.reject
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.fail || test.reject {
|
if test.fail || test.reject {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
||||||
}
|
}
|
||||||
} else if err = waitForPodToSchedule(cs, pod); err != nil {
|
} else if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,7 +742,7 @@ func TestPrebindPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
preBindPlugin.reset()
|
preBindPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -803,18 +786,12 @@ func TestUnreservePlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "unreserve-plugin", nil), 2,
|
||||||
initTestMaster(t, "unreserve-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
preBindFail bool
|
preBindFail bool
|
||||||
}{
|
}{
|
||||||
@ -830,21 +807,21 @@ func TestUnreservePlugin(t *testing.T) {
|
|||||||
preBindPlugin.failPreBind = test.preBindFail
|
preBindPlugin.failPreBind = test.preBindFail
|
||||||
|
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.preBindFail {
|
if test.preBindFail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
||||||
}
|
}
|
||||||
if unreservePlugin.numUnreserveCalled == 0 || unreservePlugin.numUnreserveCalled != preBindPlugin.numPreBindCalled {
|
if unreservePlugin.numUnreserveCalled == 0 || unreservePlugin.numUnreserveCalled != preBindPlugin.numPreBindCalled {
|
||||||
t.Errorf("test #%v: Expected the unreserve plugin to be called %d times, was called %d times.", i, preBindPlugin.numPreBindCalled, unreservePlugin.numUnreserveCalled)
|
t.Errorf("test #%v: Expected the unreserve plugin to be called %d times, was called %d times.", i, preBindPlugin.numPreBindCalled, unreservePlugin.numUnreserveCalled)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
if unreservePlugin.numUnreserveCalled > 0 {
|
if unreservePlugin.numUnreserveCalled > 0 {
|
||||||
@ -854,7 +831,7 @@ func TestUnreservePlugin(t *testing.T) {
|
|||||||
|
|
||||||
unreservePlugin.reset()
|
unreservePlugin.reset()
|
||||||
preBindPlugin.reset()
|
preBindPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -919,13 +896,14 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t, testContext,
|
context := initTestSchedulerWithOptions(t, testContext, false, nil, time.Second,
|
||||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
|
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
// Add a few nodes.
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
_, err := createNodes(context.clientSet, "test-node", nil, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
t.Fatalf("Cannot create nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -976,19 +954,19 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
postBindPlugin.pluginInvokeEventChan = pluginInvokeEventChan
|
postBindPlugin.pluginInvokeEventChan = pluginInvokeEventChan
|
||||||
|
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.expectBoundByScheduler || test.expectBoundByPlugin {
|
if test.expectBoundByScheduler || test.expectBoundByPlugin {
|
||||||
// bind plugins skipped to bind the pod
|
// bind plugins skipped to bind the pod
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
pod, err = cs.CoreV1().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{})
|
pod, err = context.clientSet.CoreV1().Pods(pod.Namespace).Get(pod.Name, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("can't get pod: %v", err)
|
t.Errorf("can't get pod: %v", err)
|
||||||
}
|
}
|
||||||
@ -1021,7 +999,7 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// bind plugin fails to bind the pod
|
// bind plugin fails to bind the pod
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
||||||
}
|
}
|
||||||
if postBindPlugin.numPostBindCalled > 0 {
|
if postBindPlugin.numPostBindCalled > 0 {
|
||||||
@ -1046,7 +1024,7 @@ func TestBindPlugin(t *testing.T) {
|
|||||||
bindPlugin1.reset()
|
bindPlugin1.reset()
|
||||||
bindPlugin2.reset()
|
bindPlugin2.reset()
|
||||||
unreservePlugin.reset()
|
unreservePlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1090,18 +1068,12 @@ func TestPostBindPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "postbind-plugin", nil), 2,
|
||||||
initTestMaster(t, "postbind-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
preBindFail bool
|
preBindFail bool
|
||||||
preBindReject bool
|
preBindReject bool
|
||||||
@ -1118,21 +1090,21 @@ func TestPostBindPlugin(t *testing.T) {
|
|||||||
preBindPlugin.failPreBind = test.preBindFail
|
preBindPlugin.failPreBind = test.preBindFail
|
||||||
|
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.preBindFail {
|
if test.preBindFail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
||||||
}
|
}
|
||||||
if postBindPlugin.numPostBindCalled > 0 {
|
if postBindPlugin.numPostBindCalled > 0 {
|
||||||
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
|
t.Errorf("test #%v: Didn't expected the postbind plugin to be called %d times.", i, postBindPlugin.numPostBindCalled)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
if postBindPlugin.numPostBindCalled == 0 {
|
if postBindPlugin.numPostBindCalled == 0 {
|
||||||
@ -1142,7 +1114,7 @@ func TestPostBindPlugin(t *testing.T) {
|
|||||||
|
|
||||||
postBindPlugin.reset()
|
postBindPlugin.reset()
|
||||||
preBindPlugin.reset()
|
preBindPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1171,18 +1143,12 @@ func TestPermitPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "permit-plugin", nil), 2,
|
||||||
initTestMaster(t, "permit-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
fail bool
|
fail bool
|
||||||
reject bool
|
reject bool
|
||||||
@ -1228,22 +1194,22 @@ func TestPermitPlugin(t *testing.T) {
|
|||||||
perPlugin.waitAndAllowPermit = false
|
perPlugin.waitAndAllowPermit = false
|
||||||
|
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
if test.fail {
|
if test.fail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(cs, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podSchedulingError(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
t.Errorf("test #%v: Expected a scheduling error, but didn't get it. error: %v", i, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if test.reject || test.timeout {
|
if test.reject || test.timeout {
|
||||||
if err = waitForPodUnschedulable(cs, pod); err != nil {
|
if err = waitForPodUnschedulable(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Didn't expect the pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Expected the pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1254,7 +1220,7 @@ func TestPermitPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
perPlugin.reset()
|
perPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1283,18 +1249,12 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "permit-plugin", nil), 2,
|
||||||
initTestMaster(t, "permit-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
waitReject bool
|
waitReject bool
|
||||||
waitAllow bool
|
waitAllow bool
|
||||||
@ -1317,29 +1277,29 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
|||||||
permitPlugin.waitAndAllowPermit = test.waitAllow
|
permitPlugin.waitAndAllowPermit = test.waitAllow
|
||||||
|
|
||||||
// Create two pods.
|
// Create two pods.
|
||||||
waitingPod, err := createPausePod(cs,
|
waitingPod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "waiting-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "waiting-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating the waiting pod: %v", err)
|
t.Errorf("Error while creating the waiting pod: %v", err)
|
||||||
}
|
}
|
||||||
signallingPod, err := createPausePod(cs,
|
signallingPod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "signalling-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "signalling-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating the signalling pod: %v", err)
|
t.Errorf("Error while creating the signalling pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test.waitReject {
|
if test.waitReject {
|
||||||
if err = waitForPodUnschedulable(cs, waitingPod); err != nil {
|
if err = waitForPodUnschedulable(context.clientSet, waitingPod); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the waiting pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Didn't expect the waiting pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
if err = waitForPodUnschedulable(cs, signallingPod); err != nil {
|
if err = waitForPodUnschedulable(context.clientSet, signallingPod); err != nil {
|
||||||
t.Errorf("test #%v: Didn't expect the signalling pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Didn't expect the signalling pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, waitingPod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, waitingPod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the waiting pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Expected the waiting pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
if err = waitForPodToSchedule(cs, signallingPod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, signallingPod); err != nil {
|
||||||
t.Errorf("test #%v: Expected the signalling pod to be scheduled. error: %v", i, err)
|
t.Errorf("test #%v: Expected the signalling pod to be scheduled. error: %v", i, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1349,7 +1309,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
permitPlugin.reset()
|
permitPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{waitingPod, signallingPod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{waitingPod, signallingPod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1360,7 +1320,7 @@ func TestFilterPlugin(t *testing.T) {
|
|||||||
registry := framework.Registry{filterPluginName: newPlugin(filterPlugin)}
|
registry := framework.Registry{filterPluginName: newPlugin(filterPlugin)}
|
||||||
|
|
||||||
// Setup initial filter plugin for testing.
|
// Setup initial filter plugin for testing.
|
||||||
plugin := &schedulerconfig.Plugins{
|
plugins := &schedulerconfig.Plugins{
|
||||||
Filter: &schedulerconfig.PluginSet{
|
Filter: &schedulerconfig.PluginSet{
|
||||||
Enabled: []schedulerconfig.Plugin{
|
Enabled: []schedulerconfig.Plugin{
|
||||||
{
|
{
|
||||||
@ -1369,37 +1329,28 @@ func TestFilterPlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Set empty plugin config for testing
|
|
||||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "filter-plugin", nil), 2,
|
||||||
initTestMaster(t, "filter-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugin, emptyPluginConfig, time.Second)
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, fail := range []bool{false, true} {
|
for _, fail := range []bool{false, true} {
|
||||||
filterPlugin.failFilter = fail
|
filterPlugin.failFilter = fail
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fail {
|
if fail {
|
||||||
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(cs, pod.Namespace, pod.Name)); err != nil {
|
if err = wait.Poll(10*time.Millisecond, 30*time.Second, podUnschedulable(context.clientSet, pod.Namespace, pod.Name)); err != nil {
|
||||||
t.Errorf("Didn't expect the pod to be scheduled.")
|
t.Errorf("Didn't expect the pod to be scheduled.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1409,7 +1360,7 @@ func TestFilterPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filterPlugin.reset()
|
filterPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1420,7 +1371,7 @@ func TestPostFilterPlugin(t *testing.T) {
|
|||||||
registry := framework.Registry{postFilterPluginName: newPlugin(postFilterPlugin)}
|
registry := framework.Registry{postFilterPluginName: newPlugin(postFilterPlugin)}
|
||||||
|
|
||||||
// Setup initial post-filter plugin for testing.
|
// Setup initial post-filter plugin for testing.
|
||||||
pluginsConfig := &schedulerconfig.Plugins{
|
plugins := &schedulerconfig.Plugins{
|
||||||
PostFilter: &schedulerconfig.PluginSet{
|
PostFilter: &schedulerconfig.PluginSet{
|
||||||
Enabled: []schedulerconfig.Plugin{
|
Enabled: []schedulerconfig.Plugin{
|
||||||
{
|
{
|
||||||
@ -1429,37 +1380,28 @@ func TestPostFilterPlugin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// Set empty plugin config for testing
|
|
||||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "post-filter-plugin", nil), 2,
|
||||||
initTestMaster(t, "post-filter-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, pluginsConfig, emptyPluginConfig, time.Second)
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add a few nodes.
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 2)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, fail := range []bool{false, true} {
|
for _, fail := range []bool{false, true} {
|
||||||
postFilterPlugin.failPostFilter = fail
|
postFilterPlugin.failPostFilter = fail
|
||||||
// Create a best effort pod.
|
// Create a best effort pod.
|
||||||
pod, err := createPausePod(cs,
|
pod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "test-pod", Namespace: context.ns.Name}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating a test pod: %v", err)
|
t.Errorf("Error while creating a test pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if fail {
|
if fail {
|
||||||
if err = waitForPodUnschedulable(cs, pod); err != nil {
|
if err = waitForPodUnschedulable(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
t.Errorf("Didn't expect the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err = waitForPodToSchedule(cs, pod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, pod); err != nil {
|
||||||
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
t.Errorf("Expected the pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1469,7 +1411,7 @@ func TestPostFilterPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
postFilterPlugin.reset()
|
postFilterPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{pod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{pod})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1498,19 +1440,19 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the master and the scheduler with the test plugin set.
|
// Create the master and the scheduler with the test plugin set.
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerForFrameworkTest(t, initTestMaster(t, "preempt-with-permit-plugin", nil), 0,
|
||||||
initTestMaster(t, "preempt-with-permit-plugin", nil),
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
scheduler.WithFrameworkPluginConfig(pluginConfig),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
// Add one node.
|
// Add one node.
|
||||||
nodeRes := &v1.ResourceList{
|
nodeRes := &v1.ResourceList{
|
||||||
v1.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
|
v1.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
|
||||||
v1.ResourceCPU: *resource.NewMilliQuantity(500, resource.DecimalSI),
|
v1.ResourceCPU: *resource.NewMilliQuantity(500, resource.DecimalSI),
|
||||||
v1.ResourceMemory: *resource.NewQuantity(500, resource.DecimalSI),
|
v1.ResourceMemory: *resource.NewQuantity(500, resource.DecimalSI),
|
||||||
}
|
}
|
||||||
_, err := createNodes(cs, "test-node", nodeRes, 1)
|
_, err := createNodes(context.clientSet, "test-node", nodeRes, 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
t.Fatalf("Cannot create nodes: %v", err)
|
||||||
}
|
}
|
||||||
@ -1529,9 +1471,9 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create two pods.
|
// Create two pods.
|
||||||
waitingPod := initPausePod(cs, &pausePodConfig{Name: "waiting-pod", Namespace: context.ns.Name, Priority: &lowPriority, Resources: &resourceRequest})
|
waitingPod := initPausePod(context.clientSet, &pausePodConfig{Name: "waiting-pod", Namespace: context.ns.Name, Priority: &lowPriority, Resources: &resourceRequest})
|
||||||
waitingPod.Spec.TerminationGracePeriodSeconds = new(int64)
|
waitingPod.Spec.TerminationGracePeriodSeconds = new(int64)
|
||||||
waitingPod, err = createPausePod(cs, waitingPod)
|
waitingPod, err = createPausePod(context.clientSet, waitingPod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating the waiting pod: %v", err)
|
t.Errorf("Error while creating the waiting pod: %v", err)
|
||||||
}
|
}
|
||||||
@ -1542,17 +1484,17 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
|||||||
return w, nil
|
return w, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
preemptorPod, err := createPausePod(cs,
|
preemptorPod, err := createPausePod(context.clientSet,
|
||||||
initPausePod(cs, &pausePodConfig{Name: "preemptor-pod", Namespace: context.ns.Name, Priority: &highPriority, Resources: &resourceRequest}))
|
initPausePod(context.clientSet, &pausePodConfig{Name: "preemptor-pod", Namespace: context.ns.Name, Priority: &highPriority, Resources: &resourceRequest}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error while creating the preemptor pod: %v", err)
|
t.Errorf("Error while creating the preemptor pod: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = waitForPodToSchedule(cs, preemptorPod); err != nil {
|
if err = waitForPodToSchedule(context.clientSet, preemptorPod); err != nil {
|
||||||
t.Errorf("Expected the preemptor pod to be scheduled. error: %v", err)
|
t.Errorf("Expected the preemptor pod to be scheduled. error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := getPod(cs, waitingPod.Name, waitingPod.Namespace); err == nil {
|
if _, err := getPod(context.clientSet, waitingPod.Name, waitingPod.Namespace); err == nil {
|
||||||
t.Error("Expected the waiting pod to get preempted and deleted")
|
t.Error("Expected the waiting pod to get preempted and deleted")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1561,22 +1503,17 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
permitPlugin.reset()
|
permitPlugin.reset()
|
||||||
cleanupPods(cs, t, []*v1.Pod{waitingPod, preemptorPod})
|
cleanupPods(context.clientSet, t, []*v1.Pod{waitingPod, preemptorPod})
|
||||||
}
|
}
|
||||||
|
|
||||||
func initTestContextForScorePlugin(t *testing.T, plugins *schedulerconfig.Plugins, registry framework.Registry) (*testContext, *clientset.Clientset) {
|
func initTestSchedulerForFrameworkTest(t *testing.T, context *testContext, nodeCount int, opts ...scheduler.Option) *testContext {
|
||||||
// Set empty plugin config for testing
|
opts = append(opts, scheduler.WithFrameworkConfigProducerRegistry(nil))
|
||||||
emptyPluginConfig := []schedulerconfig.PluginConfig{}
|
c := initTestSchedulerWithOptions(t, context, false, nil, time.Second, opts...)
|
||||||
|
if nodeCount > 0 {
|
||||||
// Create the master and the scheduler with the test plugin set.
|
_, err := createNodes(c.clientSet, "test-node", nil, nodeCount)
|
||||||
context := initTestSchedulerWithOptions(t,
|
|
||||||
initTestMaster(t, "score-plugin", nil),
|
|
||||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
|
||||||
|
|
||||||
cs := context.clientSet
|
|
||||||
_, err := createNodes(cs, "test-node", nil, 10)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cannot create nodes: %v", err)
|
t.Fatalf("Cannot create nodes: %v", err)
|
||||||
}
|
}
|
||||||
return context, cs
|
}
|
||||||
|
return c
|
||||||
}
|
}
|
||||||
|
@ -38,13 +38,16 @@ import (
|
|||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||||
"k8s.io/kubernetes/pkg/apis/scheduling"
|
"k8s.io/kubernetes/pkg/apis/scheduling"
|
||||||
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
"k8s.io/kubernetes/pkg/scheduler"
|
||||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
|
frameworkplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
"k8s.io/kubernetes/plugin/pkg/admission/priority"
|
"k8s.io/kubernetes/plugin/pkg/admission/priority"
|
||||||
testutils "k8s.io/kubernetes/test/utils"
|
testutils "k8s.io/kubernetes/test/utils"
|
||||||
|
|
||||||
|
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
||||||
|
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -121,10 +124,12 @@ var _ = framework.FilterPlugin(&tokenFilter{})
|
|||||||
func TestPreemption(t *testing.T) {
|
func TestPreemption(t *testing.T) {
|
||||||
// Initialize scheduler with a filter plugin.
|
// Initialize scheduler with a filter plugin.
|
||||||
var filter tokenFilter
|
var filter tokenFilter
|
||||||
registry := framework.Registry{filterPluginName: func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
|
registry := frameworkplugins.NewDefaultRegistry()
|
||||||
|
|
||||||
|
registry.Register(filterPluginName, func(_ *runtime.Unknown, fh framework.FrameworkHandle) (framework.Plugin, error) {
|
||||||
return &filter, nil
|
return &filter, nil
|
||||||
}}
|
})
|
||||||
plugin := &schedulerconfig.Plugins{
|
plugins := &schedulerconfig.Plugins{
|
||||||
Filter: &schedulerconfig.PluginSet{
|
Filter: &schedulerconfig.PluginSet{
|
||||||
Enabled: []schedulerconfig.Plugin{
|
Enabled: []schedulerconfig.Plugin{
|
||||||
{
|
{
|
||||||
@ -142,7 +147,9 @@ func TestPreemption(t *testing.T) {
|
|||||||
}
|
}
|
||||||
context := initTestSchedulerWithOptions(t,
|
context := initTestSchedulerWithOptions(t,
|
||||||
initTestMaster(t, "preemptiom", nil),
|
initTestMaster(t, "preemptiom", nil),
|
||||||
false, nil, registry, plugin, []schedulerconfig.PluginConfig{}, time.Second)
|
false, nil, time.Second,
|
||||||
|
scheduler.WithFrameworkPlugins(plugins),
|
||||||
|
scheduler.WithFrameworkRegistry(registry))
|
||||||
|
|
||||||
defer cleanupTest(t, context)
|
defer cleanupTest(t, context)
|
||||||
cs := context.clientSet
|
cs := context.clientSet
|
||||||
|
@ -41,7 +41,6 @@ import (
|
|||||||
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
||||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/factory"
|
"k8s.io/kubernetes/pkg/scheduler/factory"
|
||||||
schedulerplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
|
||||||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||||
"k8s.io/kubernetes/test/integration/framework"
|
"k8s.io/kubernetes/test/integration/framework"
|
||||||
@ -265,9 +264,6 @@ priorities: []
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
schedulerplugins.NewDefaultRegistry(),
|
|
||||||
nil,
|
|
||||||
[]kubeschedulerconfig.PluginConfig{},
|
|
||||||
scheduler.WithName(v1.DefaultSchedulerName),
|
scheduler.WithName(v1.DefaultSchedulerName),
|
||||||
scheduler.WithHardPodAffinitySymmetricWeight(v1.DefaultHardPodAffinitySymmetricWeight),
|
scheduler.WithHardPodAffinitySymmetricWeight(v1.DefaultHardPodAffinitySymmetricWeight),
|
||||||
scheduler.WithBindTimeoutSeconds(defaultBindTimeout),
|
scheduler.WithBindTimeoutSeconds(defaultBindTimeout),
|
||||||
@ -336,9 +332,6 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
nil,
|
nil,
|
||||||
schedulerplugins.NewDefaultRegistry(),
|
|
||||||
nil,
|
|
||||||
[]kubeschedulerconfig.PluginConfig{},
|
|
||||||
scheduler.WithName(v1.DefaultSchedulerName),
|
scheduler.WithName(v1.DefaultSchedulerName),
|
||||||
scheduler.WithHardPodAffinitySymmetricWeight(v1.DefaultHardPodAffinitySymmetricWeight),
|
scheduler.WithHardPodAffinitySymmetricWeight(v1.DefaultHardPodAffinitySymmetricWeight),
|
||||||
scheduler.WithBindTimeoutSeconds(defaultBindTimeout))
|
scheduler.WithBindTimeoutSeconds(defaultBindTimeout))
|
||||||
@ -596,7 +589,7 @@ func TestMultiScheduler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 5. create and start a scheduler with name "foo-scheduler"
|
// 5. create and start a scheduler with name "foo-scheduler"
|
||||||
context = initTestSchedulerWithOptions(t, context, true, nil, schedulerplugins.NewDefaultRegistry(), nil, []kubeschedulerconfig.PluginConfig{}, time.Second, scheduler.WithName(fooScheduler))
|
context = initTestSchedulerWithOptions(t, context, true, nil, time.Second, scheduler.WithName(fooScheduler))
|
||||||
|
|
||||||
// 6. **check point-2**:
|
// 6. **check point-2**:
|
||||||
// - testPodWithAnnotationFitsFoo should be scheduled
|
// - testPodWithAnnotationFitsFoo should be scheduled
|
||||||
|
@ -56,8 +56,6 @@ import (
|
|||||||
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
||||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/factory"
|
"k8s.io/kubernetes/pkg/scheduler/factory"
|
||||||
schedulerplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
|
||||||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
|
||||||
taintutils "k8s.io/kubernetes/pkg/util/taints"
|
taintutils "k8s.io/kubernetes/pkg/util/taints"
|
||||||
"k8s.io/kubernetes/test/integration/framework"
|
"k8s.io/kubernetes/test/integration/framework"
|
||||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
@ -142,8 +140,7 @@ func initTestScheduler(
|
|||||||
policy *schedulerapi.Policy,
|
policy *schedulerapi.Policy,
|
||||||
) *testContext {
|
) *testContext {
|
||||||
// Pod preemption is enabled by default scheduler configuration.
|
// Pod preemption is enabled by default scheduler configuration.
|
||||||
return initTestSchedulerWithOptions(t, context, setPodInformer, policy, schedulerplugins.NewDefaultRegistry(),
|
return initTestSchedulerWithOptions(t, context, setPodInformer, policy, time.Second)
|
||||||
nil, []schedulerconfig.PluginConfig{}, time.Second)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// initTestSchedulerWithOptions initializes a test environment and creates a scheduler with default
|
// initTestSchedulerWithOptions initializes a test environment and creates a scheduler with default
|
||||||
@ -153,9 +150,6 @@ func initTestSchedulerWithOptions(
|
|||||||
context *testContext,
|
context *testContext,
|
||||||
setPodInformer bool,
|
setPodInformer bool,
|
||||||
policy *schedulerapi.Policy,
|
policy *schedulerapi.Policy,
|
||||||
pluginRegistry schedulerframework.Registry,
|
|
||||||
plugins *schedulerconfig.Plugins,
|
|
||||||
pluginConfig []schedulerconfig.PluginConfig,
|
|
||||||
resyncPeriod time.Duration,
|
resyncPeriod time.Duration,
|
||||||
opts ...scheduler.Option,
|
opts ...scheduler.Option,
|
||||||
) *testContext {
|
) *testContext {
|
||||||
@ -204,9 +198,6 @@ func initTestSchedulerWithOptions(
|
|||||||
recorder,
|
recorder,
|
||||||
algorithmSrc,
|
algorithmSrc,
|
||||||
context.stopCh,
|
context.stopCh,
|
||||||
pluginRegistry,
|
|
||||||
plugins,
|
|
||||||
pluginConfig,
|
|
||||||
opts...,
|
opts...,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -273,7 +264,6 @@ func initTest(t *testing.T, nsPrefix string) *testContext {
|
|||||||
func initTestDisablePreemption(t *testing.T, nsPrefix string) *testContext {
|
func initTestDisablePreemption(t *testing.T, nsPrefix string) *testContext {
|
||||||
return initTestSchedulerWithOptions(
|
return initTestSchedulerWithOptions(
|
||||||
t, initTestMaster(t, nsPrefix, nil), true, nil,
|
t, initTestMaster(t, nsPrefix, nil), true, nil,
|
||||||
schedulerplugins.NewDefaultRegistry(), nil, []schedulerconfig.PluginConfig{},
|
|
||||||
time.Second, scheduler.WithPreemptionDisabled(true))
|
time.Second, scheduler.WithPreemptionDisabled(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ go_library(
|
|||||||
"//pkg/scheduler:go_default_library",
|
"//pkg/scheduler:go_default_library",
|
||||||
"//pkg/scheduler/algorithmprovider/defaults:go_default_library",
|
"//pkg/scheduler/algorithmprovider/defaults:go_default_library",
|
||||||
"//pkg/scheduler/apis/config:go_default_library",
|
"//pkg/scheduler/apis/config:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins:go_default_library",
|
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/informers:go_default_library",
|
"//staging/src/k8s.io/client-go/informers:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||||
|
@ -31,7 +31,6 @@ import (
|
|||||||
// import DefaultProvider
|
// import DefaultProvider
|
||||||
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider/defaults"
|
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider/defaults"
|
||||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
schedulerplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
|
||||||
"k8s.io/kubernetes/test/integration/framework"
|
"k8s.io/kubernetes/test/integration/framework"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -124,8 +123,5 @@ func createScheduler(
|
|||||||
Provider: &defaultProviderName,
|
Provider: &defaultProviderName,
|
||||||
},
|
},
|
||||||
stopCh,
|
stopCh,
|
||||||
schedulerplugins.NewDefaultRegistry(),
|
|
||||||
nil,
|
|
||||||
[]schedulerconfig.PluginConfig{},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,6 @@ go_library(
|
|||||||
"//pkg/scheduler:go_default_library",
|
"//pkg/scheduler:go_default_library",
|
||||||
"//pkg/scheduler/algorithmprovider/defaults:go_default_library",
|
"//pkg/scheduler/algorithmprovider/defaults:go_default_library",
|
||||||
"//pkg/scheduler/apis/config:go_default_library",
|
"//pkg/scheduler/apis/config:go_default_library",
|
||||||
"//pkg/scheduler/framework/plugins:go_default_library",
|
|
||||||
"//pkg/scheduler/framework/v1alpha1:go_default_library",
|
|
||||||
"//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/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
|
@ -37,8 +37,6 @@ import (
|
|||||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||||
"k8s.io/kubernetes/pkg/scheduler"
|
"k8s.io/kubernetes/pkg/scheduler"
|
||||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
schedulerplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
|
||||||
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
|
||||||
"k8s.io/kubernetes/test/integration/framework"
|
"k8s.io/kubernetes/test/integration/framework"
|
||||||
|
|
||||||
// Install "DefaultProvider" algorithprovider
|
// Install "DefaultProvider" algorithprovider
|
||||||
@ -116,8 +114,7 @@ func initTestSchedulerWithOptions(
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
context.scheduler, err = createSchedulerWithPodInformer(
|
context.scheduler, err = createSchedulerWithPodInformer(
|
||||||
context.clientSet, podInformer, context.informerFactory, schedulerplugins.NewDefaultRegistry(), nil,
|
context.clientSet, podInformer, context.informerFactory, recorder, context.stopCh)
|
||||||
[]schedulerconfig.PluginConfig{}, recorder, context.stopCh)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Couldn't create scheduler: %v", err)
|
t.Fatalf("Couldn't create scheduler: %v", err)
|
||||||
@ -138,9 +135,6 @@ func createSchedulerWithPodInformer(
|
|||||||
clientSet clientset.Interface,
|
clientSet clientset.Interface,
|
||||||
podInformer coreinformers.PodInformer,
|
podInformer coreinformers.PodInformer,
|
||||||
informerFactory informers.SharedInformerFactory,
|
informerFactory informers.SharedInformerFactory,
|
||||||
pluginRegistry schedulerframework.Registry,
|
|
||||||
plugins *schedulerconfig.Plugins,
|
|
||||||
pluginConfig []schedulerconfig.PluginConfig,
|
|
||||||
recorder events.EventRecorder,
|
recorder events.EventRecorder,
|
||||||
stopCh <-chan struct{},
|
stopCh <-chan struct{},
|
||||||
) (*scheduler.Scheduler, error) {
|
) (*scheduler.Scheduler, error) {
|
||||||
@ -164,9 +158,6 @@ func createSchedulerWithPodInformer(
|
|||||||
Provider: &defaultProviderName,
|
Provider: &defaultProviderName,
|
||||||
},
|
},
|
||||||
stopCh,
|
stopCh,
|
||||||
pluginRegistry,
|
|
||||||
plugins,
|
|
||||||
pluginConfig,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user