mirror of
https://github.com/kemko/nomad.git
synced 2026-01-10 20:35:42 +03:00
driver: Flatten SetEnvvars into taskdirhook
This commit is contained in:
@@ -2,11 +2,14 @@ package taskrunner
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
log "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
|
||||
cconfig "github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/client/driver"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/drivers/shared/env"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
@@ -45,7 +48,30 @@ func (h *taskDirHook) Prestart(ctx context.Context, req *interfaces.TaskPrestart
|
||||
}
|
||||
|
||||
// Update the environment variables based on the built task directory
|
||||
driver.SetEnvvars(h.runner.envBuilder, fsi, h.runner.taskDir, h.runner.clientConfig)
|
||||
setEnvvars(h.runner.envBuilder, fsi, h.runner.taskDir, h.runner.clientConfig)
|
||||
resp.Done = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// setEnvvars sets path and host env vars depending on the FS isolation used.
|
||||
func setEnvvars(envBuilder *env.Builder, fsi cstructs.FSIsolation, taskDir *allocdir.TaskDir, conf *cconfig.Config) {
|
||||
// Set driver-specific environment variables
|
||||
switch fsi {
|
||||
case cstructs.FSIsolationNone:
|
||||
// Use host paths
|
||||
envBuilder.SetAllocDir(taskDir.SharedAllocDir)
|
||||
envBuilder.SetTaskLocalDir(taskDir.LocalDir)
|
||||
envBuilder.SetSecretsDir(taskDir.SecretsDir)
|
||||
default:
|
||||
// filesystem isolation; use container paths
|
||||
envBuilder.SetAllocDir(allocdir.SharedAllocContainerPath)
|
||||
envBuilder.SetTaskLocalDir(allocdir.TaskLocalContainerPath)
|
||||
envBuilder.SetSecretsDir(allocdir.TaskSecretsContainerPath)
|
||||
}
|
||||
|
||||
// Set the host environment variables for non-image based drivers
|
||||
if fsi != cstructs.FSIsolationImage {
|
||||
filter := strings.Split(conf.ReadDefault("env.blacklist", cconfig.DefaultEnvBlacklist), ",")
|
||||
envBuilder.SetHostEnvvars(filter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,8 @@ import (
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/hashicorp/go-plugin"
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
dstructs "github.com/hashicorp/nomad/client/driver/structs"
|
||||
cstructs "github.com/hashicorp/nomad/client/structs"
|
||||
"github.com/hashicorp/nomad/drivers/shared/env"
|
||||
"github.com/hashicorp/nomad/drivers/shared/executor"
|
||||
"github.com/hashicorp/nomad/helper/discover"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
@@ -179,29 +176,6 @@ func getExecutorUser(task *structs.Task) string {
|
||||
return task.User
|
||||
}
|
||||
|
||||
// SetEnvvars sets path and host env vars depending on the FS isolation used.
|
||||
func SetEnvvars(envBuilder *env.Builder, fsi cstructs.FSIsolation, taskDir *allocdir.TaskDir, conf *config.Config) {
|
||||
// Set driver-specific environment variables
|
||||
switch fsi {
|
||||
case cstructs.FSIsolationNone:
|
||||
// Use host paths
|
||||
envBuilder.SetAllocDir(taskDir.SharedAllocDir)
|
||||
envBuilder.SetTaskLocalDir(taskDir.LocalDir)
|
||||
envBuilder.SetSecretsDir(taskDir.SecretsDir)
|
||||
default:
|
||||
// filesystem isolation; use container paths
|
||||
envBuilder.SetAllocDir(allocdir.SharedAllocContainerPath)
|
||||
envBuilder.SetTaskLocalDir(allocdir.TaskLocalContainerPath)
|
||||
envBuilder.SetSecretsDir(allocdir.TaskSecretsContainerPath)
|
||||
}
|
||||
|
||||
// Set the host environment variables for non-image based drivers
|
||||
if fsi != cstructs.FSIsolationImage {
|
||||
filter := strings.Split(conf.ReadDefault("env.blacklist", config.DefaultEnvBlacklist), ",")
|
||||
envBuilder.SetHostEnvvars(filter)
|
||||
}
|
||||
}
|
||||
|
||||
// getTaskKillSignal looks up the signal specified for the task if it has been
|
||||
// specified. If it is not supported on the platform, returns an error.
|
||||
func getTaskKillSignal(signal string) (os.Signal, error) {
|
||||
|
||||
Reference in New Issue
Block a user