-
Notifications
You must be signed in to change notification settings - Fork 2k
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
drivers/docker: add support for STOPSIGNAL #10441
Conversation
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 good, @isabeldepapel.
It looks like there are some tests that exercise the stop behavior vs a real Docker already (example). So you can probably verify this works by querying for Docker API events in those tests, and then making assertions about those events.
// Calling StopContainer lets docker handle the stop signal (specified | ||
// in the Dockerfile or defaulting to SIGTERM). If kill_signal is specified, | ||
// Signal is used to kill the container with the desired signal before | ||
// calling StopContainer |
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 explanatory comment for summarizing the domain-specific knowledge you'd need to understand the code 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.
This looks great. Thanks @isabeldepapel
Made a couple of comments - mostly how the existing code doesn't follow some golang convention. Noting them for educational value only.
drivers/docker/handle.go
Outdated
// parseSignal interprets the signal name into an os.Signal. If no name is | ||
// provided, the docker driver defaults to SIGTERM. If the OS is Windows and | ||
// SIGINT is provided, the signal is converted to SIGTERM. | ||
func (h *taskHandle) parseSignal(os, signal string) (os.Signal, 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.
This method is a simple "pure" function that doesn't depend on taskHandle/driver. You can make it a simple function and simply the tests by avoiding the dockerTest
related boilerplate:
func (h *taskHandle) parseSignal(os, signal string) (os.Signal, error) { | |
func parseSignal(os, signal string) (os.Signal, error) { |
drivers/docker/driver_test.go
Outdated
t.Run("default", func(t *testing.T) { | ||
s, err := d.parseSignal(runtime.GOOS, "") | ||
s, err := handle.parseSignal(runtime.GOOS, "") | ||
require.NoError(t, err) | ||
require.Equal(t, syscall.SIGTERM, s) | ||
}) |
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.
FWIW - These can be better expressed as table driver tests, a common pattern Nomad uses elsewhere: https://jayson.dev/blog/2019/06/table-driven-golang-subtests/#time-for-the-subtests .
Such a refactor is outside the scope of the PR; though, wanted to note it for educational value. If you do want to take it on, no objection ;-).
@@ -2911,28 +2911,33 @@ func TestDockerDriver_memoryLimits(t *testing.T) { | |||
func TestDockerDriver_parseSignal(t *testing.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.
Noting that Golang has a convention about test files: If the tested function is in handle.go
, the tests belong in handle_test.go
. It's odd that handle_test.go
. Seeing how the two files are intertwined, it's fine to leave the test here.
b04f8b2
to
b12ba54
Compare
b12ba54
to
27f0c7e
Compare
232d932
to
b3f6293
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.
This is great! I have few suggestions for the tests; but it's solid. I'll be happy to pair, specially with regards to the concurrency issue.
require.Equal(t, syscall.SIGHUP, s) | ||
}) | ||
// This test asserts that Nomad isn't overriding the STOPSIGNAL in a Dockerfile | ||
func TestDockerDriver_StopSignal(t *testing.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.
This is a great test. Captures all conditions :).
b3f6293
to
1f73582
Compare
Ready for another pass @notnoop |
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.
Looks great. A minor suggestion to the shell script - but merge away 🎉
#!/bin/sh | ||
|
||
# Create the tarball used in TestDockerDriver_StopSignal | ||
echo "FROM busybox:1.29.3\nSTOPSIGNAL 19" > tmpfile && docker build -t busybox:1.29.3-stopsignal - < tmpfile && rm tmpfile |
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 suspect you can avoid needing the tmp file. Also it might a bit nicer to use here-doc style in this case to avoid new lines:
echo "FROM busybox:1.29.3\nSTOPSIGNAL 19" > tmpfile && docker build -t busybox:1.29.3-stopsignal - < tmpfile && rm tmpfile | |
cat <<'EOF' | docker build -t busybox:1.29.3-stopsignal - | |
FROM busybox:1.29.3 | |
STOPSIGNAL 19 | |
EOF |
This fixes a bug where Nomad overrides a Dockerfile's STOPSIGNAL with the default kill_signal (SIGTERM). This adds a check for kill_signal. If it's not set, it calls StopContainer instead of Signal, which uses STOPSIGNAL if it's specified. If both kill_signal and STOPSIGNAL are set, Nomad tries to stop the container with kill_signal first, before then calling StopContainer. Fixes #9989
1f73582
to
379c095
Compare
drivers/docker: add support for STOPSIGNAL
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. |
Still need to figure out the tests but this is what I have so far
This fixes a bug where Nomad overrides a Dockerfile's STOPSIGNAL with
the default kill_signal (SIGTERM).
This adds a check for kill_signal. If it's not set, it calls
StopContainer instead of Signal, which uses STOPSIGNAL if it's
specified. If both kill_signal and STOPSIGNAL are set, Nomad tries to
stop the container with kill_signal first, before then calling
StopContainer.
Fixes #9989