Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hashicorp/nomad
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Jan 9, 2017
2 parents 30655ef + e3ed621 commit 35af1ed
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## 0.5.3 (Unreleased)

__BACKWARDS INCOMPATIBILITIES:__
* Client must be run as user with ability to call mount syscall

IMPROVEMENTS:
* core: Introduce Constructor jobs and Dispatch command/API [GH-2128]
* cli: Defaulting to showing allocations which belong to currently registered
Expand Down
37 changes: 30 additions & 7 deletions client/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func (r *TaskRunner) createDriver() (driver.Driver, error) {
eventEmitter := func(m string, args ...interface{}) {
msg := fmt.Sprintf(m, args...)
r.logger.Printf("[DEBUG] client: driver event for alloc %q: %s", r.alloc.ID, msg)
r.setState("", structs.NewTaskEvent(structs.TaskDriverMessage).SetDriverMessage(msg))
r.setState(structs.TaskStatePending, structs.NewTaskEvent(structs.TaskDriverMessage).SetDriverMessage(msg))
}

driverCtx := driver.NewDriverContext(r.task.Name, r.config, r.config.Node, r.logger, env, eventEmitter)
Expand Down Expand Up @@ -395,6 +395,27 @@ func (r *TaskRunner) Run() {
return
}

// Create a driver so that we can determine the FSIsolation required
drv, err := r.createDriver()
if err != nil {
e := fmt.Errorf("failed to create driver of task %q for alloc %q: %v", r.task.Name, r.alloc.ID, err)
r.setState(
structs.TaskStateDead,
structs.NewTaskEvent(structs.TaskSetupFailure).SetSetupError(e).SetFailsTask())
return
}

// Build base task directory structure regardless of FS isolation abilities.
// This needs to happen before we start the Vault manager and call prestart
// as both those can write to the task directories
if err := r.buildTaskDir(drv.FSIsolation()); err != nil {
e := fmt.Errorf("failed to build task directory for %q: %v", r.task.Name, err)
r.setState(
structs.TaskStateDead,
structs.NewTaskEvent(structs.TaskSetupFailure).SetSetupError(e).SetFailsTask())
return
}

// If there is no Vault policy leave the static future created in
// NewTaskRunner
if r.task.Vault != nil {
Expand Down Expand Up @@ -693,7 +714,6 @@ func (r *TaskRunner) updatedTokenHandler() {

// prestart handles life-cycle tasks that occur before the task has started.
func (r *TaskRunner) prestart(resultCh chan bool) {

if r.task.Vault != nil {
// Wait for the token
r.logger.Printf("[DEBUG] client: waiting for Vault token for task %v in alloc %q", r.task.Name, r.alloc.ID)
Expand Down Expand Up @@ -729,6 +749,14 @@ func (r *TaskRunner) prestart(resultCh chan bool) {
return
}

if err := os.MkdirAll(filepath.Dir(renderTo), 07777); err != nil {
r.setState(
structs.TaskStateDead,
structs.NewTaskEvent(structs.TaskSetupFailure).SetSetupError(err).SetFailsTask())
resultCh <- false
return
}

if err := ioutil.WriteFile(renderTo, decoded, 0777); err != nil {
r.setState(
structs.TaskStateDead,
Expand Down Expand Up @@ -1065,11 +1093,6 @@ func (r *TaskRunner) startTask() error {
r.task.Name, r.alloc.ID, err)
}

// Build base task directory structure regardless of FS isolation abilities
if err := r.buildTaskDir(drv.FSIsolation()); err != nil {
return fmt.Errorf("failed to build task directory for %q: %v", r.task.Name, err)
}

// Run prestart
ctx := driver.NewExecContext(r.taskDir, r.alloc.ID)
if err := drv.Prestart(ctx, r.task); err != nil {
Expand Down

0 comments on commit 35af1ed

Please sign in to comment.