Skip to content

Commit

Permalink
task lifecycle poststart: code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzyfresh committed Aug 31, 2020
1 parent 0770b44 commit 81cad55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
24 changes: 15 additions & 9 deletions client/allocrunner/alloc_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,16 @@ func TestAllocRunner_TaskMain_KillTG(t *testing.T) {
alloc.Job.TaskGroups[0].Tasks[0].RestartPolicy.Attempts = 0

// Create four tasks in the task group
sidecar := alloc.Job.TaskGroups[0].Tasks[0].Copy()
sidecar.Name = "prestart-sidecar"
sidecar.Driver = "mock_driver"
sidecar.KillTimeout = 10 * time.Millisecond
sidecar.Lifecycle = &structs.TaskLifecycleConfig{
prestart := alloc.Job.TaskGroups[0].Tasks[0].Copy()
prestart.Name = "prestart-sidecar"
prestart.Driver = "mock_driver"
prestart.KillTimeout = 10 * time.Millisecond
prestart.Lifecycle = &structs.TaskLifecycleConfig{
Hook: structs.TaskLifecycleHookPrestart,
Sidecar: true,
}

sidecar.Config = map[string]interface{}{
prestart.Config = map[string]interface{}{
"run_for": "100s",
}

Expand Down Expand Up @@ -288,9 +288,9 @@ func TestAllocRunner_TaskMain_KillTG(t *testing.T) {
"run_for": "2s",
}

alloc.Job.TaskGroups[0].Tasks = []*structs.Task{sidecar, main1, main2}
alloc.Job.TaskGroups[0].Tasks = []*structs.Task{prestart, poststart, main1, main2}
alloc.AllocatedResources.Tasks = map[string]*structs.AllocatedTaskResources{
sidecar.Name: tr,
prestart.Name: tr,
poststart.Name: tr,
main1.Name: tr,
main2.Name: tr,
Expand Down Expand Up @@ -327,7 +327,10 @@ func TestAllocRunner_TaskMain_KillTG(t *testing.T) {
var state *structs.TaskState

// both sidecars should be killed because Task2 exited
state = last.TaskStates[sidecar.Name]
state = last.TaskStates[prestart.Name]
if state == nil {
return false, fmt.Errorf("could not find state for task %s", prestart.Name)
}
if state.State != structs.TaskStateDead {
return false, fmt.Errorf("got state %v; want %v", state.State, structs.TaskStateDead)
}
Expand All @@ -344,6 +347,9 @@ func TestAllocRunner_TaskMain_KillTG(t *testing.T) {
}

state = last.TaskStates[poststart.Name]
if state == nil {
return false, fmt.Errorf("could not find state for task %s", poststart.Name)
}
if state.State != structs.TaskStateDead {
return false, fmt.Errorf("got state %v; want %v", state.State, structs.TaskStateDead)
}
Expand Down
8 changes: 2 additions & 6 deletions e2e/lifecycle/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lifecycle

import (
"fmt"

"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/e2e/framework"
Expand All @@ -18,8 +19,7 @@ type LifecycleE2ETest struct {

func init() {
framework.AddSuites(&framework.TestSuite{
Component: "Lifecycle",
// YOU COULD RUN THIS LOCALLY BC DIS FLAG
Component: "Lifecycle",
CanRunLocal: true,
Cases: []framework.TestCase{new(LifecycleE2ETest)},
})
Expand Down Expand Up @@ -61,10 +61,6 @@ func (tc *LifecycleE2ETest) TestBatchJob(f *framework.F) {
require.Equal(expected, got)
}

// TODO: cleanup == poststop
// q: what is a good example for a poststart?
// a: notify(-slack)

// TestServiceJob runs a service job with prestart and poststop hooks
func (tc *LifecycleE2ETest) TestServiceJob(f *framework.F) {
t := f.T()
Expand Down
2 changes: 1 addition & 1 deletion nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4905,7 +4905,7 @@ func (d *DispatchPayloadConfig) Validate() error {
}

const (
TaskLifecycleHookPrestart = "prestart"
TaskLifecycleHookPrestart = "prestart"
TaskLifecycleHookPoststart = "poststart"
)

Expand Down

0 comments on commit 81cad55

Please sign in to comment.