From 77889a16fb93507d4ac86baa3e5b2005b96f5821 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Tue, 26 Mar 2024 08:02:41 -0500 Subject: [PATCH] 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 --- helper/subproc/subproc.go | 9 ++++++--- plugins/drivers/testutils/testing.go | 13 +++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/helper/subproc/subproc.go b/helper/subproc/subproc.go index 0cc18422d1cf..1857fa4f8711 100644 --- a/helper/subproc/subproc.go +++ b/helper/subproc/subproc.go @@ -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. diff --git a/plugins/drivers/testutils/testing.go b/plugins/drivers/testutils/testing.go index 2ebeb3b595a2..bf645f08f899 100644 --- a/plugins/drivers/testutils/testing.go +++ b/plugins/drivers/testutils/testing.go @@ -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)