Merge pull request #3846 from flyinprogrammer/driverctx
drivers: use ctx.TaskEnv for mount points
This commit is contained in:
commit
2a14f0701d
|
@ -1013,12 +1013,12 @@ func (d *DockerDriver) dockerClients() (*docker.Client, *docker.Client, error) {
|
|||
return client, waitClient, merr.ErrorOrNil()
|
||||
}
|
||||
|
||||
func (d *DockerDriver) containerBinds(driverConfig *DockerDriverConfig, taskDir *allocdir.TaskDir,
|
||||
func (d *DockerDriver) containerBinds(driverConfig *DockerDriverConfig, ctx *ExecContext,
|
||||
task *structs.Task) ([]string, error) {
|
||||
|
||||
allocDirBind := fmt.Sprintf("%s:%s", taskDir.SharedAllocDir, allocdir.SharedAllocContainerPath)
|
||||
taskLocalBind := fmt.Sprintf("%s:%s", taskDir.LocalDir, allocdir.TaskLocalContainerPath)
|
||||
secretDirBind := fmt.Sprintf("%s:%s", taskDir.SecretsDir, allocdir.TaskSecretsContainerPath)
|
||||
allocDirBind := fmt.Sprintf("%s:%s", ctx.TaskDir.SharedAllocDir, ctx.TaskEnv.EnvMap[env.AllocDir])
|
||||
taskLocalBind := fmt.Sprintf("%s:%s", ctx.TaskDir.LocalDir, ctx.TaskEnv.EnvMap[env.TaskLocalDir])
|
||||
secretDirBind := fmt.Sprintf("%s:%s", ctx.TaskDir.SecretsDir, ctx.TaskEnv.EnvMap[env.SecretsDir])
|
||||
binds := []string{allocDirBind, taskLocalBind, secretDirBind}
|
||||
|
||||
volumesEnabled := d.config.ReadBoolDefault(dockerVolumesConfigOption, dockerVolumesConfigDefault)
|
||||
|
@ -1051,7 +1051,7 @@ func (d *DockerDriver) containerBinds(driverConfig *DockerDriverConfig, taskDir
|
|||
// Otherwise, we assume we receive a relative path binding in the format relative/to/task:/also/in/container
|
||||
if driverConfig.VolumeDriver == "" {
|
||||
// Expand path relative to alloc dir
|
||||
parts[0] = filepath.Join(taskDir.Dir, parts[0])
|
||||
parts[0] = filepath.Join(ctx.TaskDir.Dir, parts[0])
|
||||
}
|
||||
|
||||
binds = append(binds, strings.Join(parts, ":"))
|
||||
|
@ -1078,7 +1078,7 @@ func (d *DockerDriver) createContainerConfig(ctx *ExecContext, task *structs.Tas
|
|||
return c, fmt.Errorf("task.Resources is empty")
|
||||
}
|
||||
|
||||
binds, err := d.containerBinds(driverConfig, ctx.TaskDir, task)
|
||||
binds, err := d.containerBinds(driverConfig, ctx, task)
|
||||
if err != nil {
|
||||
return c, err
|
||||
}
|
||||
|
|
|
@ -1618,25 +1618,29 @@ func setupDockerVolumes(t *testing.T, cfg *config.Config, hostpath string) (*str
|
|||
allocDir.Destroy()
|
||||
t.Fatalf("failed to build task dir: %v", err)
|
||||
}
|
||||
copyImage(t, taskDir, "busybox.tar")
|
||||
|
||||
// Setup driver
|
||||
alloc := mock.Alloc()
|
||||
envBuilder := env.NewBuilder(cfg.Node, alloc, task, cfg.Region)
|
||||
execCtx := NewExecContext(taskDir, envBuilder.Build())
|
||||
cleanup := func() {
|
||||
allocDir.Destroy()
|
||||
if filepath.IsAbs(hostpath) {
|
||||
os.RemoveAll(hostpath)
|
||||
}
|
||||
}
|
||||
|
||||
logger := testLogger()
|
||||
emitter := func(m string, args ...interface{}) {
|
||||
logger.Printf("[EVENT] "+m, args...)
|
||||
}
|
||||
driverCtx := NewDriverContext(task.Name, alloc.ID, cfg, cfg.Node, testLogger(), emitter)
|
||||
driver := NewDockerDriver(driverCtx)
|
||||
copyImage(t, taskDir, "busybox.tar")
|
||||
|
||||
// Setup execCtx
|
||||
envBuilder := env.NewBuilder(cfg.Node, alloc, task, cfg.Region)
|
||||
SetEnvvars(envBuilder, driver.FSIsolation(), taskDir, cfg)
|
||||
execCtx := NewExecContext(taskDir, envBuilder.Build())
|
||||
|
||||
// Setup cleanup function
|
||||
cleanup := func() {
|
||||
allocDir.Destroy()
|
||||
if filepath.IsAbs(hostpath) {
|
||||
os.RemoveAll(hostpath)
|
||||
}
|
||||
}
|
||||
return task, driver, execCtx, hostfile, cleanup
|
||||
}
|
||||
|
||||
|
|
|
@ -438,17 +438,17 @@ func (d *RktDriver) Start(ctx *ExecContext, task *structs.Task) (*StartResponse,
|
|||
// Mount /alloc
|
||||
allocVolName := fmt.Sprintf("%s-%s-alloc", d.DriverContext.allocID, sanitizedName)
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--volume=%s,kind=host,source=%s", allocVolName, ctx.TaskDir.SharedAllocDir))
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--mount=volume=%s,target=%s", allocVolName, allocdir.SharedAllocContainerPath))
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--mount=volume=%s,target=%s", allocVolName, ctx.TaskEnv.EnvMap[env.AllocDir]))
|
||||
|
||||
// Mount /local
|
||||
localVolName := fmt.Sprintf("%s-%s-local", d.DriverContext.allocID, sanitizedName)
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--volume=%s,kind=host,source=%s", localVolName, ctx.TaskDir.LocalDir))
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--mount=volume=%s,target=%s", localVolName, allocdir.TaskLocalContainerPath))
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--mount=volume=%s,target=%s", localVolName, ctx.TaskEnv.EnvMap[env.TaskLocalDir]))
|
||||
|
||||
// Mount /secrets
|
||||
secretsVolName := fmt.Sprintf("%s-%s-secrets", d.DriverContext.allocID, sanitizedName)
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--volume=%s,kind=host,source=%s", secretsVolName, ctx.TaskDir.SecretsDir))
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--mount=volume=%s,target=%s", secretsVolName, allocdir.TaskSecretsContainerPath))
|
||||
prepareArgs = append(prepareArgs, fmt.Sprintf("--mount=volume=%s,target=%s", secretsVolName, ctx.TaskEnv.EnvMap[env.SecretsDir]))
|
||||
|
||||
// Mount arbitrary volumes if enabled
|
||||
if len(driverConfig.Volumes) > 0 {
|
||||
|
|
Loading…
Reference in New Issue