Skip to content

Commit aa07db3

Browse files
authored
Merge pull request kubernetes#82040 from ahmad-diaa/use-scheduler-in-volumescheduling
Use scheduler.New() Instead of factory.NewConfigFactory() in volumescheduling Integration Test
2 parents 3870692 + 071e64d commit aa07db3

File tree

2 files changed

+45
-66
lines changed

2 files changed

+45
-66
lines changed

test/integration/volumescheduling/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ go_library(
6262
"//pkg/api/v1/pod:go_default_library",
6363
"//pkg/scheduler:go_default_library",
6464
"//pkg/scheduler/algorithmprovider/defaults:go_default_library",
65-
"//pkg/scheduler/api:go_default_library",
6665
"//pkg/scheduler/apis/config:go_default_library",
67-
"//pkg/scheduler/factory:go_default_library",
6866
"//pkg/scheduler/framework/v1alpha1:go_default_library",
6967
"//staging/src/k8s.io/api/core/v1:go_default_library",
7068
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",

test/integration/volumescheduling/util.go

Lines changed: 45 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ import (
3636
"k8s.io/kubernetes/pkg/api/legacyscheme"
3737
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
3838
"k8s.io/kubernetes/pkg/scheduler"
39-
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
4039
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
41-
"k8s.io/kubernetes/pkg/scheduler/factory"
4240
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
4341
"k8s.io/kubernetes/test/integration/framework"
4442

@@ -47,15 +45,13 @@ import (
4745
)
4846

4947
type testContext struct {
50-
closeFn framework.CloseFunc
51-
httpServer *httptest.Server
52-
ns *v1.Namespace
53-
clientSet *clientset.Clientset
54-
informerFactory informers.SharedInformerFactory
55-
schedulerConfigArgs *factory.ConfigFactoryArgs
56-
schedulerConfig *factory.Config
57-
scheduler *scheduler.Scheduler
58-
stopCh chan struct{}
48+
closeFn framework.CloseFunc
49+
httpServer *httptest.Server
50+
ns *v1.Namespace
51+
clientSet *clientset.Clientset
52+
informerFactory informers.SharedInformerFactory
53+
scheduler *scheduler.Scheduler
54+
stopCh chan struct{}
5955
}
6056

6157
// initTestMaster initializes a test environment and creates a master with default
@@ -109,83 +105,68 @@ func initTestSchedulerWithOptions(
109105
context.informerFactory = informers.NewSharedInformerFactory(context.clientSet, resyncPeriod)
110106

111107
podInformer := context.informerFactory.Core().V1().Pods()
112-
113-
context.schedulerConfigArgs = createConfiguratorArgsWithPodInformer(
114-
context.clientSet, podInformer, context.informerFactory, schedulerframework.NewRegistry(), nil,
115-
[]schedulerconfig.PluginConfig{}, context.stopCh)
116-
configFactory := factory.NewConfigFactory(context.schedulerConfigArgs)
117-
118-
var err error
119-
context.schedulerConfig, err = configFactory.Create()
120-
if err != nil {
121-
t.Fatalf("Couldn't create scheduler config: %v", err)
122-
}
123-
124-
// set DisablePreemption option
125-
context.schedulerConfig.DisablePreemption = false
126108
eventBroadcaster := events.NewBroadcaster(&events.EventSinkImpl{
127109
Interface: context.clientSet.EventsV1beta1().Events(""),
128110
})
129-
context.schedulerConfig.Recorder = eventBroadcaster.NewRecorder(
111+
recorder := eventBroadcaster.NewRecorder(
130112
legacyscheme.Scheme,
131113
v1.DefaultSchedulerName,
132114
)
133115

134-
context.scheduler = scheduler.NewFromConfig(context.schedulerConfig)
116+
var err error
117+
context.scheduler, err = createSchedulerWithPodInformer(
118+
context.clientSet, podInformer, context.informerFactory, schedulerframework.NewRegistry(), nil,
119+
[]schedulerconfig.PluginConfig{}, recorder, context.stopCh)
135120

136-
scheduler.AddAllEventHandlers(context.scheduler,
137-
v1.DefaultSchedulerName,
138-
context.informerFactory.Core().V1().Nodes(),
139-
podInformer,
140-
context.informerFactory.Core().V1().PersistentVolumes(),
141-
context.informerFactory.Core().V1().PersistentVolumeClaims(),
142-
context.informerFactory.Core().V1().Services(),
143-
context.informerFactory.Storage().V1().StorageClasses(),
144-
context.informerFactory.Storage().V1beta1().CSINodes(),
145-
)
121+
if err != nil {
122+
t.Fatalf("Couldn't create scheduler: %v", err)
123+
}
146124

147125
stopCh := make(chan struct{})
148126
eventBroadcaster.StartRecordingToSink(stopCh)
149127

150-
context.informerFactory.Start(context.schedulerConfig.StopEverything)
151-
context.informerFactory.WaitForCacheSync(context.schedulerConfig.StopEverything)
128+
context.informerFactory.Start(context.scheduler.StopEverything)
129+
context.informerFactory.WaitForCacheSync(context.scheduler.StopEverything)
152130

153131
context.scheduler.Run()
154132
return context
155133
}
156134

157-
// createConfiguratorWithPodInformer creates a configurator for scheduler.
158-
func createConfiguratorArgsWithPodInformer(
135+
// createSchedulerWithPodInformer creates a new scheduler.
136+
func createSchedulerWithPodInformer(
159137
clientSet clientset.Interface,
160138
podInformer coreinformers.PodInformer,
161139
informerFactory informers.SharedInformerFactory,
162140
pluginRegistry schedulerframework.Registry,
163141
plugins *schedulerconfig.Plugins,
164142
pluginConfig []schedulerconfig.PluginConfig,
143+
recorder events.EventRecorder,
165144
stopCh <-chan struct{},
166-
) *factory.ConfigFactoryArgs {
167-
return &factory.ConfigFactoryArgs{
168-
Client: clientSet,
169-
NodeInformer: informerFactory.Core().V1().Nodes(),
170-
PodInformer: podInformer,
171-
PvInformer: informerFactory.Core().V1().PersistentVolumes(),
172-
PvcInformer: informerFactory.Core().V1().PersistentVolumeClaims(),
173-
ReplicationControllerInformer: informerFactory.Core().V1().ReplicationControllers(),
174-
ReplicaSetInformer: informerFactory.Apps().V1().ReplicaSets(),
175-
StatefulSetInformer: informerFactory.Apps().V1().StatefulSets(),
176-
ServiceInformer: informerFactory.Core().V1().Services(),
177-
PdbInformer: informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
178-
StorageClassInformer: informerFactory.Storage().V1().StorageClasses(),
179-
CSINodeInformer: informerFactory.Storage().V1beta1().CSINodes(),
180-
Registry: pluginRegistry,
181-
Plugins: plugins,
182-
PluginConfig: pluginConfig,
183-
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
184-
DisablePreemption: false,
185-
PercentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,
186-
BindTimeoutSeconds: 600,
187-
StopCh: stopCh,
188-
}
145+
) (*scheduler.Scheduler, error) {
146+
defaultProviderName := schedulerconfig.SchedulerDefaultProviderName
147+
148+
return scheduler.New(
149+
clientSet,
150+
informerFactory.Core().V1().Nodes(),
151+
podInformer,
152+
informerFactory.Core().V1().PersistentVolumes(),
153+
informerFactory.Core().V1().PersistentVolumeClaims(),
154+
informerFactory.Core().V1().ReplicationControllers(),
155+
informerFactory.Apps().V1().ReplicaSets(),
156+
informerFactory.Apps().V1().StatefulSets(),
157+
informerFactory.Core().V1().Services(),
158+
informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
159+
informerFactory.Storage().V1().StorageClasses(),
160+
informerFactory.Storage().V1beta1().CSINodes(),
161+
recorder,
162+
schedulerconfig.SchedulerAlgorithmSource{
163+
Provider: &defaultProviderName,
164+
},
165+
stopCh,
166+
pluginRegistry,
167+
plugins,
168+
pluginConfig,
169+
)
189170
}
190171

191172
// cleanupTest deletes the scheduler and the test namespace. It should be called

0 commit comments

Comments
 (0)