A mapping from predicates/priorities to pluing configuration.
This PR only implements the mapping, but does not use it. A followup PR will use this mapping to produce a framework configuration that redirects mapped predicates/priorites to be exected as plugins.
This commit is contained in:
@@ -17,6 +17,9 @@ limitations under the License.
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
noop "k8s.io/kubernetes/pkg/scheduler/framework/plugins/noop"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
)
|
||||
@@ -31,3 +34,47 @@ func NewDefaultRegistry() framework.Registry {
|
||||
noop.Name: noop.New,
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigProducerArgs contains arguments that are passed to the producer.
|
||||
// As we add more predicates/priorities to framework plugins mappings, more arguments
|
||||
// may be added here.
|
||||
type ConfigProducerArgs struct {
|
||||
// Weight used for priority functions.
|
||||
Weight int32
|
||||
}
|
||||
|
||||
// ConfigProducer produces a framework's configuration.
|
||||
type ConfigProducer func(args ConfigProducerArgs) (config.Plugins, []config.PluginConfig)
|
||||
|
||||
// ConfigProducerRegistry tracks mappings from predicates/priorities to framework config producers.
|
||||
type ConfigProducerRegistry struct {
|
||||
// maps that associate predicates/priorities with framework plugin configurations.
|
||||
PredicateToConfigProducer map[string]ConfigProducer
|
||||
PriorityToConfigProducer map[string]ConfigProducer
|
||||
}
|
||||
|
||||
// NewConfigProducerRegistry creates a new producer registry.
|
||||
func NewConfigProducerRegistry() *ConfigProducerRegistry {
|
||||
return &ConfigProducerRegistry{
|
||||
PredicateToConfigProducer: make(map[string]ConfigProducer),
|
||||
PriorityToConfigProducer: make(map[string]ConfigProducer),
|
||||
}
|
||||
}
|
||||
|
||||
func registerProducer(name string, producer ConfigProducer, producersMap map[string]ConfigProducer) error {
|
||||
if _, exist := producersMap[name]; exist {
|
||||
return fmt.Errorf("already registered %q", name)
|
||||
}
|
||||
producersMap[name] = producer
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterPredicate registers a config producer for a predicate.
|
||||
func (f *ConfigProducerRegistry) RegisterPredicate(name string, producer ConfigProducer) error {
|
||||
return registerProducer(name, producer, f.PredicateToConfigProducer)
|
||||
}
|
||||
|
||||
// RegisterPriority registers a framework config producer for a priority.
|
||||
func (f *ConfigProducerRegistry) RegisterPriority(name string, producer ConfigProducer) error {
|
||||
return registerProducer(name, producer, f.PriorityToConfigProducer)
|
||||
}
|
||||
|
Reference in New Issue
Block a user