mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 01:15:43 +03:00
Fix inconsistent task env setting
Consolidate task environment building in GetTaskEnv since it can determine what kind of filesystem isolation is used. This means drivers no longer have to manipulate task environment paths.
This commit is contained in:
@@ -352,10 +352,6 @@ func (d *DockerDriver) FSIsolation() cstructs.FSIsolation {
|
||||
}
|
||||
|
||||
func (d *DockerDriver) Prestart(ctx *ExecContext, task *structs.Task) error {
|
||||
// Set environment variables.
|
||||
d.taskEnv.SetAllocDir(allocdir.SharedAllocContainerPath).
|
||||
SetTaskLocalDir(allocdir.TaskLocalContainerPath).SetSecretsDir(allocdir.TaskSecretsContainerPath).Build()
|
||||
|
||||
driverConfig, err := NewDockerDriverConfig(task, d.taskEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -164,10 +164,22 @@ func GetTaskEnv(taskDir *allocdir.TaskDir, node *structs.Node,
|
||||
SetEnvvars(task.Env).
|
||||
SetTaskName(task.Name)
|
||||
|
||||
if taskDir != nil {
|
||||
// Vary paths by filesystem isolation used
|
||||
drv, err := NewDriver(task.Driver, NewEmptyDriverContext())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch drv.FSIsolation() {
|
||||
case cstructs.FSIsolationNone:
|
||||
// Use host paths
|
||||
env.SetAllocDir(taskDir.SharedAllocDir)
|
||||
env.SetTaskLocalDir(taskDir.LocalDir)
|
||||
env.SetSecretsDir(taskDir.SecretsDir)
|
||||
default:
|
||||
// filesystem isolation; use container paths
|
||||
env.SetAllocDir(allocdir.SharedAllocContainerPath)
|
||||
env.SetTaskLocalDir(allocdir.TaskLocalContainerPath)
|
||||
env.SetSecretsDir(allocdir.TaskSecretsContainerPath)
|
||||
}
|
||||
|
||||
if task.Resources != nil {
|
||||
|
||||
@@ -130,7 +130,7 @@ func testDriverContexts(t *testing.T, task *structs.Task) *testContext {
|
||||
func TestDriver_GetTaskEnv(t *testing.T) {
|
||||
task := &structs.Task{
|
||||
Name: "Foo",
|
||||
Driver: "mock",
|
||||
Driver: "mock_driver",
|
||||
Env: map[string]string{
|
||||
"HELLO": "world",
|
||||
"lorem": "ipsum",
|
||||
@@ -155,7 +155,9 @@ func TestDriver_GetTaskEnv(t *testing.T) {
|
||||
alloc := mock.Alloc()
|
||||
alloc.Job.TaskGroups[0].Tasks[0] = task
|
||||
alloc.Name = "Bar"
|
||||
env, err := GetTaskEnv(nil, nil, task, alloc, testConfig(), "")
|
||||
conf := testConfig()
|
||||
allocDir := allocdir.NewAllocDir(testLogger(), filepath.Join(conf.AllocDir, alloc.ID))
|
||||
env, err := GetTaskEnv(allocDir.NewTaskDir(task.Name), nil, task, alloc, conf, "")
|
||||
if err != nil {
|
||||
t.Fatalf("GetTaskEnv() failed: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user