Skip to content

Commit

Permalink
Merge pull request #5212 from hashicorp/b-taskrunner-does-not-set-tas…
Browse files Browse the repository at this point in the history
…kgroupname

task_runner does not set TaskGroupName in TaskConfig
  • Loading branch information
Chris Baker committed Jan 18, 2019
2 parents 4e4ecc9 + b43f803 commit 256ac52
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
7 changes: 4 additions & 3 deletions client/allocrunner/taskrunner/task_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -797,9 +797,10 @@ func (tr *TaskRunner) buildTaskConfig() *drivers.TaskConfig {
env := tr.envBuilder.Build()

return &drivers.TaskConfig{
ID: fmt.Sprintf("%s/%s/%s", alloc.ID, task.Name, invocationid),
Name: task.Name,
JobName: alloc.Job.Name,
ID: fmt.Sprintf("%s/%s/%s", alloc.ID, task.Name, invocationid),
Name: task.Name,
JobName: alloc.Job.Name,
TaskGroupName: alloc.TaskGroup,
Resources: &drivers.Resources{
NomadResources: taskResources,
LinuxResources: &drivers.LinuxResources{
Expand Down
42 changes: 42 additions & 0 deletions client/allocrunner/taskrunner/task_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,48 @@ func TestTaskRunner_TaskEnv(t *testing.T) {
assert.Equal(t, "global bar somebody", mockCfg.StdoutString)
}

func TestTaskRunner_TaskConfig(t *testing.T) {
t.Parallel()
require := require.New(t)

alloc := mock.BatchAlloc()
task := alloc.Job.TaskGroups[0].Tasks[0]
task.Driver = "mock_driver"

//// Use interpolation from both node attributes and meta vars
//task.Config = map[string]interface{}{
// "run_for": "1ms",
//}

conf, cleanup := testTaskRunnerConfig(t, alloc, task.Name)
defer cleanup()

// Run the first TaskRunner
tr, err := NewTaskRunner(conf)
require.NoError(err)
go tr.Run()
defer tr.Kill(context.Background(), structs.NewTaskEvent("cleanup"))

// Wait for task to complete
select {
case <-tr.WaitCh():
case <-time.After(3 * time.Second):
}

// Get the mock driver plugin
driverPlugin, err := conf.DriverManager.Dispense(mockdriver.PluginID.Name)
require.NoError(err)
mockDriver := driverPlugin.(*mockdriver.Driver)

// Assert its config has been properly interpolated
driverCfg, mockCfg := mockDriver.GetTaskConfig()
require.NotNil(driverCfg)
require.NotNil(mockCfg)
assert.Equal(t, alloc.Job.Name, driverCfg.JobName)
assert.Equal(t, alloc.TaskGroup, driverCfg.TaskGroupName)
assert.Equal(t, alloc.Job.TaskGroups[0].Tasks[0].Name, driverCfg.Name)
}

// Test that devices get sent to the driver
func TestTaskRunner_DevicePropogation(t *testing.T) {
t.Parallel()
Expand Down
2 changes: 1 addition & 1 deletion plugins/shared/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func TestPluginLoader_External_Config_Bad(t *testing.T) {
t.Parallel()
require := require.New(t)

// Create two plugins
// Create a plugin
plugins := []string{"mock-device"}
pluginVersions := []string{"v0.0.1"}
h := newHarness(t, plugins)
Expand Down

0 comments on commit 256ac52

Please sign in to comment.