-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add cwd to exec drivers #24249
base: main
Are you sure you want to change the base?
add cwd to exec drivers #24249
Conversation
…cwd-to-exec-drivers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great @mismithhisler!
Two big picture items:
- It looks like the ticket didn't include the
java
driver but it's nearly identical to theexec
driver and uses all the same underlying bits. We should probably add that as well. - We're referring to this as the "working directory for the task" but we already document a "task working directory" in the Filesystem docs, which is the directory where Nomad creates the
local/
dir, etc. That directory is the default value ofwork_dir
, isn't it? That leads to a few questions:- Should we use the
work_dir
as part of the binary search path we describe in thecommand
docs? - Is it possible to simply replace the value of the
TaskDir
field with the value ofwork_dir
if set to avoid having an extra field in our protobufs, or does the executor need to know about the fine-grained difference? - How do we disambiguate between the two in our docs?
- Should we use the
drivers/rawexec/driver_test.go
Outdated
Args: []string{"foo.txt"}, | ||
WorkDir: workDir, | ||
} | ||
require.NoError(task.EncodeConcreteDriverConfig(&tc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For new tests we should be swapping out testify
for shoenig/test
.
@@ -355,6 +359,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive | |||
Env: cfg.EnvList(), | |||
User: cfg.User, | |||
TaskDir: cfg.TaskDir().Dir, | |||
WorkDir: driverConfig.WorkDir, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we're not validating the work_dir
is absolute the way we're doing for the exec
driver.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
drivers/rawexec/driver_test.go
Outdated
@@ -598,6 +598,55 @@ func TestRawExecDriver_Exec(t *testing.T) { | |||
require.NoError(harness.DestroyTask(task.ID, true)) | |||
} | |||
|
|||
func TestRawExecDriver_WorkDir(t *testing.T) { | |||
ci.Parallel(t) | |||
ctestutil.ExecCompatible(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExecCompatible
means we can only run this test on Linux and as root. Do we need that restriction here? If so, can we have a test that runs on Windows as well (rawexec
is a popular driver for Windows users).
@@ -53,6 +53,8 @@ the Nomad client has been hardened according to the [production][hardening] guid | |||
- `oom_score_adj` - (Optional) A positive integer to indicate the likelihood of | |||
the task being OOM killed (valid only for Linux). Defaults to 0. | |||
|
|||
- `work_dir` - (Optional) The working directory for the task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any restrictions on this? If it's relative, what will it be relative to?
@@ -482,7 +490,7 @@ func (e *UniversalExecutor) ExecStreaming(ctx context.Context, command []string, | |||
|
|||
cmd := exec.CommandContext(ctx, command[0], command[1:]...) | |||
|
|||
cmd.Dir = "/" | |||
cmd.Dir = e.childCmd.Dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the working directory for alloc exec
. We should probably document that in the work_dir
docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is the one opinionated change I added here. But it makes work_dir
function the same as setting the working directory in a container. I'll add something to the docs.
@tgross These are all good points.
I'll get this added.
That's a good suggestion.
The executor uses
An idea here is to change |
Eh, come to think of it having the |
Co-authored-by: Tim Gross <[email protected]>
1c88031
to
ddf67de
Compare
Adds support for setting the working directory in
exec
andraw_exec
drivers.Fixes: #2224