runservice scheduler: choose executor with right arch

Choose an executor matching the required arch or any if no arch is required
This commit is contained in:
Simone Gotti 2019-04-17 15:26:09 +02:00
parent f3e583bb40
commit adf9c73518
1 changed files with 13 additions and 3 deletions

View File

@ -208,12 +208,15 @@ func (s *Scheduler) submitRunTasks(ctx context.Context, r *types.Run, rc *types.
log.Debugf("tasksToRun: %s", util.Dump(tasks)) log.Debugf("tasksToRun: %s", util.Dump(tasks))
for _, rt := range tasks { for _, rt := range tasks {
executor, err := s.chooseExecutor(ctx) rct := rc.Tasks[rt.ID]
executor, err := s.chooseExecutor(ctx, rct)
if err != nil { if err != nil {
return err return err
} }
if executor == nil { if executor == nil {
return errors.Errorf("cannot choose an executor") log.Warnf("cannot choose an executor")
return nil
} }
et := s.genExecutorTask(ctx, r, rt, rc, executor) et := s.genExecutorTask(ctx, r, rt, rc, executor)
@ -242,12 +245,19 @@ func (s *Scheduler) submitRunTasks(ctx context.Context, r *types.Run, rc *types.
// chooseExecutor chooses the executor to schedule the task on. Now it's a very simple/dumb selection // chooseExecutor chooses the executor to schedule the task on. Now it's a very simple/dumb selection
// TODO(sgotti) improve this to use executor statistic, labels (arch type) etc... // TODO(sgotti) improve this to use executor statistic, labels (arch type) etc...
func (s *Scheduler) chooseExecutor(ctx context.Context) (*types.Executor, error) { func (s *Scheduler) chooseExecutor(ctx context.Context, rct *types.RunConfigTask) (*types.Executor, error) {
executors, err := store.GetExecutors(ctx, s.e) executors, err := store.GetExecutors(ctx, s.e)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, e := range executors { for _, e := range executors {
// if arch is not defined use any executor arch
if rct.Runtime.Arch != "" {
if e.Labels["arch"] != string(rct.Runtime.Arch) {
continue
}
}
return e, nil return e, nil
} }
return nil, nil return nil, nil