mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
use scheduler.Option in initTestSchedulerWithOptions
This commit is contained in:
parent
995e741ef9
commit
bf6a70a1ce
@ -181,7 +181,7 @@ func New(client clientset.Interface,
|
||||
registry framework.Registry,
|
||||
plugins *kubeschedulerconfig.Plugins,
|
||||
pluginConfig []kubeschedulerconfig.PluginConfig,
|
||||
opts ...func(o *schedulerOptions)) (*Scheduler, error) {
|
||||
opts ...Option) (*Scheduler, error) {
|
||||
|
||||
options := defaultSchedulerOptions
|
||||
for _, opt := range opts {
|
||||
|
@ -449,7 +449,7 @@ func TestPreFilterPlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "prefilter-plugin", nil),
|
||||
false, nil, registry, plugins, emptyPluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
||||
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
@ -627,7 +627,7 @@ func TestReservePlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "reserve-plugin", nil),
|
||||
false, nil, registry, plugins, emptyPluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -691,7 +691,7 @@ func TestPrebindPlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "prebind-plugin", nil),
|
||||
false, nil, registry, plugins, preBindPluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, preBindPluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -792,7 +792,7 @@ func TestUnreservePlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "unreserve-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -907,7 +907,7 @@ func TestBindPlugin(t *testing.T) {
|
||||
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t, testContext,
|
||||
false, nil, registry, plugins, pluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -1079,7 +1079,7 @@ func TestPostBindPlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "postbind-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -1160,7 +1160,7 @@ func TestPermitPlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "permit-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -1272,7 +1272,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "permit-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -1362,7 +1362,7 @@ func TestFilterPlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "filter-plugin", nil),
|
||||
false, nil, registry, plugin, emptyPluginConfig, false, time.Second)
|
||||
false, nil, registry, plugin, emptyPluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -1422,7 +1422,7 @@ func TestPostFilterPlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "post-filter-plugin", nil),
|
||||
false, nil, registry, pluginsConfig, emptyPluginConfig, false, time.Second)
|
||||
false, nil, registry, pluginsConfig, emptyPluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -1487,7 +1487,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "preempt-with-permit-plugin", nil),
|
||||
false, nil, registry, plugins, pluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, pluginConfig, time.Second)
|
||||
defer cleanupTest(t, context)
|
||||
|
||||
cs := context.clientSet
|
||||
@ -1558,7 +1558,7 @@ func initTestContextForScorePlugin(t *testing.T, plugins *schedulerconfig.Plugin
|
||||
// Create the master and the scheduler with the test plugin set.
|
||||
context := initTestSchedulerWithOptions(t,
|
||||
initTestMaster(t, "score-plugin", nil),
|
||||
false, nil, registry, plugins, emptyPluginConfig, false, time.Second)
|
||||
false, nil, registry, plugins, emptyPluginConfig, time.Second)
|
||||
|
||||
cs := context.clientSet
|
||||
_, err := createNodes(cs, "test-node", nil, 10)
|
||||
|
@ -41,7 +41,6 @@ import (
|
||||
_ "k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
|
||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
|
||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
"k8s.io/kubernetes/pkg/scheduler/factory"
|
||||
schedulerplugins "k8s.io/kubernetes/pkg/scheduler/framework/plugins"
|
||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||
@ -597,49 +596,7 @@ func TestMultiScheduler(t *testing.T) {
|
||||
}
|
||||
|
||||
// 5. create and start a scheduler with name "foo-scheduler"
|
||||
clientSet2 := clientset.NewForConfigOrDie(&restclient.Config{Host: context.httpServer.URL, ContentConfig: restclient.ContentConfig{GroupVersion: &schema.GroupVersion{Group: "", Version: "v1"}}})
|
||||
informerFactory2 := informers.NewSharedInformerFactory(context.clientSet, 0)
|
||||
podInformer2 := factory.NewPodInformer(context.clientSet, 0)
|
||||
|
||||
stopCh := make(chan struct{})
|
||||
defer close(stopCh)
|
||||
|
||||
eventBroadcaster2 := events.NewBroadcaster(&events.EventSinkImpl{Interface: clientSet2.EventsV1beta1().Events("")})
|
||||
recorder := eventBroadcaster2.NewRecorder(legacyscheme.Scheme, "k8s.io/"+fooScheduler)
|
||||
provider := schedulerconfig.SchedulerDefaultProviderName
|
||||
algorithmSrc := schedulerconfig.SchedulerAlgorithmSource{
|
||||
Provider: &provider,
|
||||
}
|
||||
sched2, err := scheduler.New(
|
||||
clientSet2,
|
||||
informerFactory2.Core().V1().Nodes(),
|
||||
podInformer2,
|
||||
informerFactory2.Core().V1().PersistentVolumes(),
|
||||
informerFactory2.Core().V1().PersistentVolumeClaims(),
|
||||
informerFactory2.Core().V1().ReplicationControllers(),
|
||||
informerFactory2.Apps().V1().ReplicaSets(),
|
||||
informerFactory2.Apps().V1().StatefulSets(),
|
||||
informerFactory2.Core().V1().Services(),
|
||||
informerFactory2.Policy().V1beta1().PodDisruptionBudgets(),
|
||||
informerFactory2.Storage().V1().StorageClasses(),
|
||||
informerFactory2.Storage().V1beta1().CSINodes(),
|
||||
recorder,
|
||||
algorithmSrc,
|
||||
stopCh,
|
||||
schedulerplugins.NewDefaultRegistry(),
|
||||
nil,
|
||||
[]kubeschedulerconfig.PluginConfig{},
|
||||
scheduler.WithName(fooScheduler),
|
||||
scheduler.WithBindTimeoutSeconds(600),
|
||||
)
|
||||
if err != nil {
|
||||
t.Errorf("Couldn't create scheduler config: %v", err)
|
||||
}
|
||||
eventBroadcaster2.StartRecordingToSink(stopCh)
|
||||
|
||||
go podInformer2.Informer().Run(stopCh)
|
||||
informerFactory2.Start(stopCh)
|
||||
sched2.Run()
|
||||
context = initTestSchedulerWithOptions(t, context, true, nil, schedulerplugins.NewDefaultRegistry(), nil, []kubeschedulerconfig.PluginConfig{}, time.Second, scheduler.WithName(fooScheduler))
|
||||
|
||||
// 6. **check point-2**:
|
||||
// - testPodWithAnnotationFitsFoo should be scheduled
|
||||
|
@ -143,7 +143,7 @@ func initTestScheduler(
|
||||
) *testContext {
|
||||
// Pod preemption is enabled by default scheduler configuration.
|
||||
return initTestSchedulerWithOptions(t, context, setPodInformer, policy, schedulerplugins.NewDefaultRegistry(),
|
||||
nil, []schedulerconfig.PluginConfig{}, false, time.Second)
|
||||
nil, []schedulerconfig.PluginConfig{}, time.Second)
|
||||
}
|
||||
|
||||
// initTestSchedulerWithOptions initializes a test environment and creates a scheduler with default
|
||||
@ -156,8 +156,8 @@ func initTestSchedulerWithOptions(
|
||||
pluginRegistry schedulerframework.Registry,
|
||||
plugins *schedulerconfig.Plugins,
|
||||
pluginConfig []schedulerconfig.PluginConfig,
|
||||
disablePreemption bool,
|
||||
resyncPeriod time.Duration,
|
||||
opts ...scheduler.Option,
|
||||
) *testContext {
|
||||
// 1. Create scheduler
|
||||
context.informerFactory = informers.NewSharedInformerFactory(context.clientSet, resyncPeriod)
|
||||
@ -187,6 +187,7 @@ func initTestSchedulerWithOptions(
|
||||
Provider: &provider,
|
||||
}
|
||||
}
|
||||
opts = append([]scheduler.Option{scheduler.WithBindTimeoutSeconds(600)}, opts...)
|
||||
context.scheduler, err = scheduler.New(
|
||||
context.clientSet,
|
||||
context.informerFactory.Core().V1().Nodes(),
|
||||
@ -206,8 +207,7 @@ func initTestSchedulerWithOptions(
|
||||
pluginRegistry,
|
||||
plugins,
|
||||
pluginConfig,
|
||||
scheduler.WithPreemptionDisabled(disablePreemption),
|
||||
scheduler.WithBindTimeoutSeconds(600),
|
||||
opts...,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
@ -274,7 +274,7 @@ func initTestDisablePreemption(t *testing.T, nsPrefix string) *testContext {
|
||||
return initTestSchedulerWithOptions(
|
||||
t, initTestMaster(t, nsPrefix, nil), true, nil,
|
||||
schedulerplugins.NewDefaultRegistry(), nil, []schedulerconfig.PluginConfig{},
|
||||
true, time.Second)
|
||||
time.Second, scheduler.WithPreemptionDisabled(true))
|
||||
}
|
||||
|
||||
// cleanupTest deletes the scheduler and the test namespace. It should be called
|
||||
|
Loading…
Reference in New Issue
Block a user