mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-02 03:08:15 +00:00
NewSchedulerFromInterface implementation
This commit is contained in:
@@ -51,6 +51,10 @@ type Scheduler struct {
|
||||
config *Config
|
||||
}
|
||||
|
||||
func (sched *Scheduler) StopEverything() {
|
||||
close(sched.config.StopEverything)
|
||||
}
|
||||
|
||||
// These are the functions which need to be provided in order to build a Scheduler configuration.
|
||||
// An implementation of this can be seen in factory.go.
|
||||
type Configurator interface {
|
||||
@@ -78,6 +82,7 @@ type Configurator interface {
|
||||
CreateFromKeys(predicateKeys, priorityKeys sets.String, extenders []algorithm.SchedulerExtender) (*Config, error)
|
||||
}
|
||||
|
||||
// TODO over time we should make this struct a hidden implementation detail of the scheduler.
|
||||
type Config struct {
|
||||
// It is expected that changes made via SchedulerCache will be observed
|
||||
// by NodeLister and Algorithm.
|
||||
@@ -108,6 +113,7 @@ type Config struct {
|
||||
}
|
||||
|
||||
// New returns a new scheduler.
|
||||
// TODO replace this with NewFromConfigurator.
|
||||
func New(c *Config) *Scheduler {
|
||||
s := &Scheduler{
|
||||
config: c,
|
||||
@@ -116,6 +122,25 @@ func New(c *Config) *Scheduler {
|
||||
return s
|
||||
}
|
||||
|
||||
// NewFromConfigurator returns a new scheduler that is created entirely by the Configurator. Assumes Create() is implemented.
|
||||
// Supports intermediate Config mutation for now if you provide modifier functions which will run after Config is created.
|
||||
func NewFromConfigurator(c Configurator, modifiers ...func(c *Config)) (*Scheduler, error) {
|
||||
cfg, err := c.Create()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Mutate it if any functions were provided, changes might be required for certain types of tests (i.e. change the recorder).
|
||||
for _, modifier := range modifiers {
|
||||
modifier(cfg)
|
||||
}
|
||||
// From this point on the config is immutable to the outside.
|
||||
s := &Scheduler{
|
||||
config: cfg,
|
||||
}
|
||||
metrics.Register()
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Run begins watching and scheduling. It starts a goroutine and returns immediately.
|
||||
func (s *Scheduler) Run() {
|
||||
go wait.Until(s.scheduleOne, 0, s.config.StopEverything)
|
||||
|
||||
Reference in New Issue
Block a user