Skip to content

Commit 2638360

Browse files
Merge pull request #34 from Roblox/signals
Error out on invalid signal
2 parents 418cd4a + e26c9d0 commit 2638360

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

containerd/driver.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package containerd
2020
import (
2121
"context"
2222
"fmt"
23-
"os"
2423
"syscall"
2524
"time"
2625

@@ -583,13 +582,11 @@ func (d *Driver) SignalTask(taskID string, signal string) error {
583582
// The given signal will be forwarded to the target taskID.
584583
// Please checkout https://github.com/hashicorp/consul-template/blob/master/signals/signals_unix.go
585584
// for a list of supported signals.
586-
sig := os.Interrupt
587-
if s, ok := signals.SignalLookup[signal]; ok {
588-
sig = s
589-
} else {
590-
d.logger.Warn("unknown signal to send to task, using SIGINT instead", "signal", signal, "task_id", handle.taskConfig.ID)
591-
585+
sig, ok := signals.SignalLookup[signal]
586+
if !ok {
587+
return fmt.Errorf("Invalid signal: %s", signal)
592588
}
589+
593590
return handle.signal(d.ctxContainerd, sig)
594591
}
595592

tests/002-test-signal-handler.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ test_signal_handler_nomad_job() {
2020
exit 1
2121
fi
2222

23+
# Even though $(nomad job status) reports signal job status as "running"
24+
# The actual container process might not be running yet.
25+
# We need to wait for actual container to start running before trying to send invalid signal.
26+
echo "INFO: Wait for signal container to get into RUNNING state, before trying to send invalid signal."
27+
is_signal_container_active
28+
29+
echo "INFO: Test invalid signal."
30+
alloc_id=$(nomad job status signal|awk 'END{print}'|cut -d ' ' -f 1)
31+
local outfile=$(mktemp /tmp/signal.XXXXXX)
32+
nomad alloc signal -s INVALID $alloc_id >> $outfile 2>&1
33+
if ! grep -q "Invalid signal" $outfile; then
34+
echo "ERROR: Invalid signal didn't error out."
35+
cleanup "$outfile"
36+
exit 1
37+
fi
38+
cleanup "$outfile"
39+
2340
echo "INFO: Stopping nomad signal handler job."
2441
nomad job stop signal
2542
signal_status=$(nomad job status -short signal|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ')
@@ -33,4 +50,29 @@ test_signal_handler_nomad_job() {
3350
popd
3451
}
3552

53+
cleanup() {
54+
local tmpfile=$1
55+
rm $tmpfile > /dev/null 2>&1
56+
}
57+
58+
is_signal_container_active() {
59+
i="0"
60+
while test $i -lt 5
61+
do
62+
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
63+
if [ $? -eq 0 ]; then
64+
echo "INFO: signal container is up and running"
65+
break
66+
fi
67+
echo "INFO: signal container is down, sleep for 4 seconds."
68+
sleep 4s
69+
i=$[$i+1]
70+
done
71+
72+
if [ $i -ge 5 ]; then
73+
echo "ERROR: signal container didn't come up. exit 1."
74+
exit 1
75+
fi
76+
}
77+
3678
test_signal_handler_nomad_job

tests/003-test-capabilities.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ is_capabilities_container_active() {
8181
sudo CONTAINERD_NAMESPACE=nomad ctr task ls|grep -q RUNNING
8282
if [ $? -eq 0 ]; then
8383
echo "INFO: capabilities container is up and running"
84+
sleep 5s
8485
break
8586
fi
8687
echo "INFO: capabilities container is down, sleep for 4 seconds."

0 commit comments

Comments
 (0)