Skip to content

Commit cfc801b

Browse files
committed
Fix running tests under Docker/Podman and cgroup v2
For "make integration", the tests are run inside a Docker/Podman container. Problem is, if cgroup v2 is used, the in-container /sys/fs/cgroup/cgroup.subtree_control is empty. The added script, used as Docker entrypoint, moves the current process into a sub-cgroup, and then adds all controllers in top-level cgroup.subtree_control. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent f0a5e6b commit cfc801b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ ENV PKG_CONFIG_PATH=/opt/libseccomp/lib/pkgconfig
6363
RUN git config --global --add safe.directory /go/src/github.com/opencontainers/runc
6464

6565
WORKDIR /go/src/github.com/opencontainers/runc
66+
67+
# Fixup for cgroup v2.
68+
COPY script/prepare-cgroup-v2.sh /
69+
ENTRYPOINT [ "/prepare-cgroup-v2.sh" ]

script/prepare-cgroup-v2.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
#
3+
# This script is used from ../Dockerfile as the ENTRYPOINT. It sets up cgroup
4+
# delegation for cgroup v2 to make sure runc tests can be properly run inside
5+
# a container.
6+
7+
# Only do this for cgroup v2.
8+
if [ -f /sys/fs/cgroup/cgroup.controllers ]; then
9+
set -x
10+
# Move the current process to a sub-cgroup.
11+
mkdir /sys/fs/cgroup/init
12+
echo 0 >/sys/fs/cgroup/init/cgroup.procs
13+
# Enable all controllers.
14+
sed 's/\b\w/+\0/g' <"/sys/fs/cgroup/cgroup.controllers" >"/sys/fs/cgroup/cgroup.subtree_control"
15+
fi
16+
17+
exec "$@"

0 commit comments

Comments
 (0)