workload validation before registering elektron. (#19)
Added a utility to help with validating structs. This utility accepts validators and runs them. If any of the validators fail, then the error is wrapped with a given base message and returned. Added validators for checking different attributes of a task definition. Added test code to test task validators. Retrofitted scheduler.go to just log the task validation error and terminate. If task validation does not report any error, then the tasks are provided to the scheduler and elektron registers itself with Mesos.
This commit is contained in:
parent
e3caa90c31
commit
9977251c14
5 changed files with 220 additions and 1 deletions
13
def/task.go
13
def/task.go
|
@ -20,6 +20,7 @@ package def
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/spdfg/elektron/utilities/validation"
|
||||
"os"
|
||||
|
||||
mesos "github.com/mesos/mesos-go/api/v0/mesosproto"
|
||||
|
@ -55,6 +56,18 @@ func TasksFromJSON(uri string) ([]Task, error) {
|
|||
return nil, errors.Wrap(err, "Error unmarshalling")
|
||||
}
|
||||
|
||||
// Validating task definitions.
|
||||
for _, task := range tasks {
|
||||
err := validation.Validate("invalid task definition",
|
||||
ValidatorForTask(task,
|
||||
withNameValidator(),
|
||||
withImageValidator(),
|
||||
withResourceValidator()))
|
||||
if err != nil {
|
||||
return tasks, err
|
||||
}
|
||||
}
|
||||
|
||||
initTaskResourceRequirements(tasks)
|
||||
return tasks, nil
|
||||
}
|
||||
|
|
Reference in a new issue