exec2: more tweaks to driver harness (#20221)

Also add an explicit exit code to subproc package for when a child
process is instructed to run an unrunnable command (i.e. cannot be
found or is not executable) - with the 127 return code folks using bash
are familiar with
This commit is contained in:
Seth Hoenig
2024-03-26 08:02:41 -05:00
committed by GitHub
parent a50e6267d0
commit 77889a16fb
2 changed files with 17 additions and 5 deletions

View File

@@ -15,13 +15,16 @@ import (
const (
// ExitSuccess indicates the subprocess completed successfully.
ExitSuccess = iota
ExitSuccess = 0
// ExitFailure indicates the subprocess terminated unsuccessfully.
ExitFailure
ExitFailure = 1
// ExitTimeout indicates the subprocess timed out before completion.
ExitTimeout
ExitTimeout = 2
// ExitNotRunnable indicates a command cannot be run.
ExitNotRunnable = 127 // bash-ism
)
// MainFunc is the function that runs for this sub-process.

View File

@@ -83,7 +83,11 @@ func (h *DriverHarness) MkAllocDir(t *drivers.TaskConfig, enableLogs bool) func(
dir, err := os.MkdirTemp("", "nomad_driver_harness-")
must.NoError(h.t, err)
allocDir := allocdir.NewAllocDir(h.logger, dir, dir, t.AllocID)
mountsDir, err := os.MkdirTemp("", "nomad_driver_harness-mounts-")
must.NoError(h.t, err)
must.NoError(h.t, os.Chmod(mountsDir, 0755))
allocDir := allocdir.NewAllocDir(h.logger, dir, mountsDir, t.AllocID)
must.NoError(h.t, allocDir.Build())
t.AllocDir = allocDir.AllocDir
@@ -261,7 +265,12 @@ func SetEnvvars(envBuilder *taskenv.Builder, fsmode fsisolation.Mode, taskDir *a
// Set driver-specific environment variables
switch fsmode {
case fsisolation.None, fsisolation.Unveil:
case fsisolation.Unveil:
// Use mounts host paths
envBuilder.SetAllocDir(filepath.Join(taskDir.MountsAllocDir, "alloc"))
envBuilder.SetTaskLocalDir(filepath.Join(taskDir.MountsTaskDir, "local"))
envBuilder.SetSecretsDir(filepath.Join(taskDir.SecretsDir, "secrets"))
case fsisolation.None:
// Use host paths
envBuilder.SetAllocDir(taskDir.SharedAllocDir)
envBuilder.SetTaskLocalDir(taskDir.LocalDir)