Skip to content

Commit 954ef2b

Browse files
authored
Merge pull request #5553 from claudiubelu/integration-test-cleanup-windows
integration: Cleanup containerd on test teardown
2 parents ffeea14 + 2f870aa commit 954ef2b

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

script/test/utils.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ CONTAINERD_FLAGS+="--address ${TRIMMED_CONTAINERD_SOCK} \
7979
--state ${CONTAINERD_STATE} \
8080
--root ${CONTAINERD_ROOT}"
8181

82-
kill_containerd_cmd=
82+
pid=
8383

8484
# NOTE: We don't have the sudo command on Windows.
8585
sudo=""
@@ -103,12 +103,6 @@ test_setup() {
103103
pid=$!
104104
set +m
105105

106-
if [ $IS_WINDOWS -eq 1 ]; then
107-
kill_containerd_cmd="${sudo} kill ${pid}"
108-
else
109-
kill_containerd_cmd="${sudo} pkill -g $(ps -o pgid= -p ${pid})"
110-
fi
111-
112106
# Wait for containerd to be running by using the containerd client ctr to check the version
113107
# of the containerd server. Wait an increasing amount of time after each of five attempts
114108
local -r crictl_path=$(which crictl)
@@ -122,8 +116,14 @@ test_setup() {
122116

123117
# test_teardown kills containerd.
124118
test_teardown() {
125-
if [ -n "${kill_containerd_cmd}" ]; then
126-
${kill_containerd_cmd}
119+
if [ -n "${pid}" ]; then
120+
if [ $IS_WINDOWS -eq 1 ]; then
121+
# NOTE(claudiub): The containerd process will have the same PGID as the keepalive process,
122+
# so we can kill both of them by matching the PGID.
123+
${sudo} ps | awk "{if (\$3 == ${pid}) print \$1}" | xargs kill
124+
else
125+
${sudo} pkill -g $(ps -o pgid= -p ${pid})
126+
fi
127127
fi
128128
}
129129

0 commit comments

Comments
 (0)