-
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
nomad exec part 2: CLI #5633
nomad exec part 2: CLI #5633
Conversation
@notnoop nice, this seems like a similar thing to nomad-helper attach ? |
@jippi indeed, they are functionally similar. By this being built-in, it can work without ssh access (only using the nomad API which can handle forwarding across federated regions) and other drivers besides docker. When targeting an exec task for example, the command will run inside the exec task chroot/container environment. |
@notnoop thats great! :) Any plans to build in similar "interactive" flow as my tool have? we use it a ton internally, both on infra and dev side - and being guided through each selection of job, alloc and task is a pretty loved feature (opposite to a random alloc if omitted) |
Looks more like the exec functionality of https://github.com/42wim/nomadctld ;) Maybe make |
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 start, but I'd like to see command line argument handling cleaned up a little. I'd also like to see test cases for handling of -job
and --task
, for both happy and sad paths.
command/alloc_exec.go
Outdated
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient), | ||
complete.Flags{ | ||
"--task": complete.PredictAnything, | ||
"-job": complete.PredictAnything, |
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.
We could predict the job here?
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.
Not quite - this matches the pattern of nomad logs
where --job
is boolean flag about whether to interpret the first argument is an alloc or a job id. So --job
itself doesn't take any arguments technically.
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.
Ah - In which case the documentation for -job
needs to be updated to show that it's parsed as a boolean flag
} | ||
|
||
if numArgs := len(args); numArgs < 1 { | ||
if job { |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
bffe3d2
to
980e4f5
Compare
f6969b3
to
96ac203
Compare
96ac203
to
bad77f1
Compare
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.
I would say that alloc_exec.go
could use some additional comments throughout especially in execImpl
. Working with terminals/ttys has bit me in the past before. Otherwise the impl LGTM.
Only one question I had before hitting approve:
Is there an escape sequence similar to ~.
to break the session when using a tty? I think something like that would be really useful over having to send a SIGTERM to the pid.
-job | ||
Use a random allocation from the specified job ID. | ||
|
||
-i |
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.
If this default's to true then how do you unset it? -i false
? I'm imagining the inverse since that's how docker works.
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.
Clarified - our CLI library is different from docker - it needs to be -i=false
.
return isTerminal | ||
} | ||
|
||
func setRawTerminal(stream interface{}) (cleanup func(), err error) { |
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.
comment on this func would be helpful
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.
done!
This is an excellent suggestion. I'm going to follow up with adding it in a separate PR. |
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Sequel to #5632 .
This PR adds the actual nomad exec CLI command, that's inspired by
docker exec
with some modification:The command is primarily intended for interactive debugging so it makes the default more sensible for that case:
stdin
to ultimate command - indocker exec
terminology,--interactive
is enabled by default.docker
terminology very confusing (since passing stdin isn't necessary interactive), so I used the long form--stdin
instead, matchingkubectl
flag-tty
is enabled.For explicitly negating the options, we use the golang flag way of disabling (e.g.
--tty=false
,--stdin=false
).I added this as a separate PR to separate the CLI UX review from internal plumbing of nomad exec.