@@ -36,9 +36,7 @@ import (
36
36
"k8s.io/kubernetes/pkg/api/legacyscheme"
37
37
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
38
38
"k8s.io/kubernetes/pkg/scheduler"
39
- schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
40
39
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
41
- "k8s.io/kubernetes/pkg/scheduler/factory"
42
40
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
43
41
"k8s.io/kubernetes/test/integration/framework"
44
42
@@ -47,15 +45,13 @@ import (
47
45
)
48
46
49
47
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 {}
59
55
}
60
56
61
57
// initTestMaster initializes a test environment and creates a master with default
@@ -109,83 +105,68 @@ func initTestSchedulerWithOptions(
109
105
context .informerFactory = informers .NewSharedInformerFactory (context .clientSet , resyncPeriod )
110
106
111
107
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
126
108
eventBroadcaster := events .NewBroadcaster (& events.EventSinkImpl {
127
109
Interface : context .clientSet .EventsV1beta1 ().Events ("" ),
128
110
})
129
- context . schedulerConfig . Recorder = eventBroadcaster .NewRecorder (
111
+ recorder : = eventBroadcaster .NewRecorder (
130
112
legacyscheme .Scheme ,
131
113
v1 .DefaultSchedulerName ,
132
114
)
133
115
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 )
135
120
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
+ }
146
124
147
125
stopCh := make (chan struct {})
148
126
eventBroadcaster .StartRecordingToSink (stopCh )
149
127
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 )
152
130
153
131
context .scheduler .Run ()
154
132
return context
155
133
}
156
134
157
- // createConfiguratorWithPodInformer creates a configurator for scheduler.
158
- func createConfiguratorArgsWithPodInformer (
135
+ // createSchedulerWithPodInformer creates a new scheduler.
136
+ func createSchedulerWithPodInformer (
159
137
clientSet clientset.Interface ,
160
138
podInformer coreinformers.PodInformer ,
161
139
informerFactory informers.SharedInformerFactory ,
162
140
pluginRegistry schedulerframework.Registry ,
163
141
plugins * schedulerconfig.Plugins ,
164
142
pluginConfig []schedulerconfig.PluginConfig ,
143
+ recorder events.EventRecorder ,
165
144
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
+ )
189
170
}
190
171
191
172
// cleanupTest deletes the scheduler and the test namespace. It should be called
0 commit comments