@@ -20,7 +20,6 @@ import (
20
20
"context"
21
21
"errors"
22
22
"fmt"
23
- "sort"
24
23
"time"
25
24
26
25
"github.com/google/go-cmp/cmp"
@@ -268,138 +267,56 @@ func (c *Configurator) createFromConfig(policy schedulerapi.Policy) (*Scheduler,
268
267
269
268
klog .V (2 ).Infof ("Creating scheduler with fit predicates '%v' and priority functions '%v'" , predicateKeys , priorityKeys )
270
269
271
- pluginsForPredicates , pluginConfigForPredicates , err := getPredicateConfigs (predicateKeys , lr , args )
272
- if err != nil {
273
- return nil , err
274
- }
275
-
276
- pluginsForPriorities , pluginConfigForPriorities , err := getPriorityConfigs (priorityKeys , lr , args )
277
- if err != nil {
278
- return nil , err
279
- }
280
270
// Combine all framework configurations. If this results in any duplication, framework
281
271
// instantiation should fail.
282
- var defPlugins schedulerapi. Plugins
272
+
283
273
// "PrioritySort" and "DefaultBinder" were neither predicates nor priorities
284
274
// before. We add them by default.
285
- defPlugins . Append ( & schedulerapi.Plugins {
275
+ plugins := schedulerapi.Plugins {
286
276
QueueSort : & schedulerapi.PluginSet {
287
277
Enabled : []schedulerapi.Plugin {{Name : queuesort .Name }},
288
278
},
289
279
Bind : & schedulerapi.PluginSet {
290
280
Enabled : []schedulerapi.Plugin {{Name : defaultbinder .Name }},
291
281
},
292
- })
293
- defPlugins .Append (pluginsForPredicates )
294
- defPlugins .Append (pluginsForPriorities )
295
- defPluginConfig , err := mergePluginConfigsFromPolicy (pluginConfigForPredicates , pluginConfigForPriorities )
296
- if err != nil {
282
+ }
283
+ var pluginConfig []schedulerapi.PluginConfig
284
+ var err error
285
+ if plugins , pluginConfig , err = lr .AppendPredicateConfigs (predicateKeys , args , plugins , pluginConfig ); err != nil {
286
+ return nil , err
287
+ }
288
+ if plugins , pluginConfig , err = lr .AppendPriorityConfigs (priorityKeys , args , plugins , pluginConfig ); err != nil {
289
+ return nil , err
290
+ }
291
+ if pluginConfig , err = dedupPluginConfigs (pluginConfig ); err != nil {
297
292
return nil , err
298
293
}
299
294
for i := range c .profiles {
300
295
prof := & c .profiles [i ]
301
- // Plugins are empty when using Policy.
296
+ // Plugins and PluginConfig are empty when using Policy; overriding .
302
297
prof .Plugins = & schedulerapi.Plugins {}
303
- prof .Plugins .Append (& defPlugins )
304
-
305
- // PluginConfig is ignored when using Policy.
306
- prof .PluginConfig = defPluginConfig
298
+ prof .Plugins .Append (& plugins )
299
+ prof .PluginConfig = pluginConfig
307
300
}
308
301
309
302
return c .create ()
310
303
}
311
304
312
- // mergePluginConfigsFromPolicy merges the giving plugin configs ensuring that,
305
+ // dedupPluginConfigs removes duplicates from pluginConfig, ensuring that,
313
306
// if a plugin name is repeated, the arguments are the same.
314
- func mergePluginConfigsFromPolicy ( pc1 , pc2 []schedulerapi.PluginConfig ) ([]schedulerapi.PluginConfig , error ) {
307
+ func dedupPluginConfigs ( pc []schedulerapi.PluginConfig ) ([]schedulerapi.PluginConfig , error ) {
315
308
args := make (map [string ]runtime.Object )
316
- for _ , c := range pc1 {
317
- args [c .Name ] = c .Args
318
- }
319
- for _ , c := range pc2 {
320
- if v , ok := args [c .Name ]; ok && ! cmp .Equal (v , c .Args ) {
309
+ result := make ([]schedulerapi.PluginConfig , 0 , len (pc ))
310
+ for _ , c := range pc {
311
+ if v , found := args [c .Name ]; ! found {
312
+ result = append (result , c )
313
+ args [c .Name ] = c .Args
314
+ } else if ! cmp .Equal (v , c .Args ) {
321
315
// This should be unreachable.
322
316
return nil , fmt .Errorf ("inconsistent configuration produced for plugin %s" , c .Name )
323
317
}
324
- args [c .Name ] = c .Args
325
318
}
326
- pc := make ([]schedulerapi.PluginConfig , 0 , len (args ))
327
- for k , v := range args {
328
- pc = append (pc , schedulerapi.PluginConfig {
329
- Name : k ,
330
- Args : v ,
331
- })
332
- }
333
- return pc , nil
334
- }
335
-
336
- // getPriorityConfigs returns priorities configuration: ones that will run as priorities and ones that will run
337
- // as framework plugins. Specifically, a priority will run as a framework plugin if a plugin config producer was
338
- // registered for that priority.
339
- func getPriorityConfigs (keys map [string ]int64 , lr * frameworkplugins.LegacyRegistry , args * frameworkplugins.ConfigProducerArgs ) (* schedulerapi.Plugins , []schedulerapi.PluginConfig , error ) {
340
- var plugins schedulerapi.Plugins
341
- var pluginConfig []schedulerapi.PluginConfig
342
-
343
- // Sort the keys so that it is easier for unit tests to do compare.
344
- var sortedKeys []string
345
- for k := range keys {
346
- sortedKeys = append (sortedKeys , k )
347
- }
348
- sort .Strings (sortedKeys )
349
-
350
- for _ , priority := range sortedKeys {
351
- weight := keys [priority ]
352
- producer , exist := lr .PriorityToConfigProducer [priority ]
353
- if ! exist {
354
- return nil , nil , fmt .Errorf ("no config producer registered for %q" , priority )
355
- }
356
- a := * args
357
- a .Weight = int32 (weight )
358
- pl , plc := producer (a )
359
- plugins .Append (& pl )
360
- pluginConfig = append (pluginConfig , plc ... )
361
- }
362
- return & plugins , pluginConfig , nil
363
- }
364
-
365
- // getPredicateConfigs returns predicates configuration: ones that will run as fitPredicates and ones that will run
366
- // as framework plugins. Specifically, a predicate will run as a framework plugin if a plugin config producer was
367
- // registered for that predicate.
368
- // Note that the framework executes plugins according to their order in the Plugins list, and so predicates run as plugins
369
- // are added to the Plugins list according to the order specified in predicates.Ordering().
370
- func getPredicateConfigs (keys sets.String , lr * frameworkplugins.LegacyRegistry , args * frameworkplugins.ConfigProducerArgs ) (* schedulerapi.Plugins , []schedulerapi.PluginConfig , error ) {
371
- allPredicates := keys .Union (lr .MandatoryPredicates )
372
-
373
- // Create the framework plugin configurations, and place them in the order
374
- // that the corresponding predicates were supposed to run.
375
- var plugins schedulerapi.Plugins
376
- var pluginConfig []schedulerapi.PluginConfig
377
-
378
- for _ , predicateKey := range frameworkplugins .PredicateOrdering () {
379
- if allPredicates .Has (predicateKey ) {
380
- producer , exist := lr .PredicateToConfigProducer [predicateKey ]
381
- if ! exist {
382
- return nil , nil , fmt .Errorf ("no framework config producer registered for %q" , predicateKey )
383
- }
384
- pl , plc := producer (* args )
385
- plugins .Append (& pl )
386
- pluginConfig = append (pluginConfig , plc ... )
387
- allPredicates .Delete (predicateKey )
388
- }
389
- }
390
-
391
- // Third, add the rest in no specific order.
392
- for predicateKey := range allPredicates {
393
- producer , exist := lr .PredicateToConfigProducer [predicateKey ]
394
- if ! exist {
395
- return nil , nil , fmt .Errorf ("no framework config producer registered for %q" , predicateKey )
396
- }
397
- pl , plc := producer (* args )
398
- plugins .Append (& pl )
399
- pluginConfig = append (pluginConfig , plc ... )
400
- }
401
-
402
- return & plugins , pluginConfig , nil
319
+ return result , nil
403
320
}
404
321
405
322
// MakeDefaultErrorFunc construct a function to handle pod scheduler error
0 commit comments