Skip to content

Commit 2d39375

Browse files
committed
add Vagrantfile (Fedora 33) for cgroup2 testing
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
1 parent 44c5bb8 commit 2d39375

File tree

4 files changed

+124
-1
lines changed

4 files changed

+124
-1
lines changed

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,31 @@ jobs:
5858
fetch-depth: 1
5959
- name: "Ensure that the test suite is compatible with Docker"
6060
run: go test -v -exec sudo -test.target=docker .
61+
62+
test-cgroup2:
63+
name: "Cgroup2 + rootless"
64+
# nested virtualization is only available on macOS hosts
65+
runs-on: macos-10.15
66+
timeout-minutes: 40
67+
steps:
68+
- uses: actions/setup-go@v2
69+
with:
70+
go-version: 1.15.x
71+
- uses: actions/checkout@v2
72+
with:
73+
fetch-depth: 1
74+
# Vagrant is slow, so we build binaries outside Vagrant
75+
- name: "Build binaries"
76+
run: |
77+
GOOS=linux make binaries
78+
GOOS=linux go test -c .
79+
- name: "Boot VM"
80+
run: |
81+
vagrant up
82+
vagrant ssh-config >> ~/.ssh/config
83+
- name: "Install rootless containerd"
84+
run: ssh default -- containerd-rootless-setuptool.sh install
85+
- name: "Run tests (rootless)"
86+
run: ssh default -- "CONTAINERD_SNAPSHOTTER=native /vagrant/nerdctl.test -test.v"
87+
- name: "Uninstall rootless containerd"
88+
run: ssh default -- containerd-rootless-setuptool.sh uninstall

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ _output
44

55
# golangci-lint
66
build
7+
8+
# vagrant
9+
/.vagrant

Vagrantfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrant box for testing cgroup v2
5+
Vagrant.configure("2") do |config|
6+
config.vm.box = "fedora/33-cloud-base"
7+
memory = 4096
8+
cpus = 2
9+
config.vm.provider :virtualbox do |v|
10+
v.memory = memory
11+
v.cpus = cpus
12+
end
13+
config.vm.provider :libvirt do |v|
14+
v.memory = memory
15+
v.cpus = cpus
16+
end
17+
config.vm.provision "shell", inline: <<-SHELL
18+
set -eux -o pipefail
19+
if [ ! -x /vagrant/_output/nerdctl ]; then
20+
echo "Run 'GOOS=linux make' before running 'vagrant up'"
21+
exit 1
22+
fi
23+
if [ ! -x /vagrant/nerdctl.test ]; then
24+
echo "Run 'GOOS=linux go test -c' before running 'vagrant up'"
25+
exit 1
26+
fi
27+
28+
# Install RPMs
29+
dnf install -y \
30+
make \
31+
containerd \
32+
containernetworking-plugins \
33+
iptables \
34+
slirp4netns \
35+
policycoreutils-python-utils
36+
37+
# SELinux workaround (https://github.com/moby/moby/issues/41230)
38+
semanage permissive -a iptables_t
39+
40+
# Install runc
41+
RUNC_VERSION=1.0.0-rc93
42+
# remove rpm version of runc, which doesn't support cgroup v2
43+
rm -f /usr/bin/runc
44+
curl -o /usr/local/sbin/runc -fsSL https://github.com/opencontainers/runc/releases/download/v${RUNC_VERSION}/runc.amd64
45+
chmod +x /usr/local/sbin/runc
46+
47+
# Install RootlessKit
48+
ROOTLESSKIT_VERSION=0.13.1
49+
curl -sSL https://github.com/rootless-containers/rootlesskit/releases/download/v${ROOTLESSKIT_VERSION}/rootlesskit-$(uname -m).tar.gz | tar Cxzv /usr/local/bin
50+
51+
# Delegate cgroup v2 controllers
52+
mkdir -p /etc/systemd/system/user@.service.d
53+
cat <<EOF >/etc/systemd/system/user@.service.d/delegate.conf
54+
[Service]
55+
Delegate=yes
56+
EOF
57+
systemctl daemon-reload
58+
59+
# Install nerdctl
60+
# The binary is built outside Vagrant.
61+
make -C /vagrant install
62+
SHELL
63+
end

docs/rootless.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $ containerd-rootless-setuptool.sh install
1515
...
1616
[INFO] Installed containerd.service successfully.
1717
[INFO] To control containerd.service, run: `systemctl --user (start|stop|restart) containerd.service`
18-
[INFO] To run containerd.service on system startup, run: `sudo loginctl enable-linger suda`
18+
[INFO] To run containerd.service on system startup, run: `sudo loginctl enable-linger testuser`
1919

2020
[INFO] Use `nerdctl` to connect to the rootless containerd.
2121
[INFO] You do NOT need to specify $CONTAINERD_ADDRESS explicitly.
@@ -35,3 +35,32 @@ $ nerdctl run -it --rm alpine
3535

3636
Depending on your kernel version, you may need to set `export CONTAINERD_SNAPSHOTTER=native`.
3737
See https://rootlesscontaine.rs/how-it-works/overlayfs/ .
38+
39+
## Troubleshooting
40+
41+
### Hint to Fedora 33 users
42+
43+
#### runc rpm
44+
The runc package of Fedora 33 does not support cgroup v2.
45+
Use the upstream runc binary: https://github.com/opencontainers/runc/releases
46+
47+
The runc package of Fedora 34 will probably support cgroup v2.
48+
49+
Alternatively, you may choose to use `crun` instead of `runc`:
50+
`nerdctl run --runtime=crun`
51+
52+
#### OverlayFS
53+
You need to set `export CONTAINERD_SNAPSHOTTER=native` on Fedora 33 because Fedora 33 does not support rootless overlayfs.
54+
(FUSE-OverlayFS could be used instead, but you might need to recompile containerd, see https://github.com/AkihiroSuda/containerd-fuse-overlayfs)
55+
56+
Fedora 34 (kernel >= 5.11) will probably support rootless overlayfs.
57+
58+
#### SELinux
59+
If SELinux is enabled on your host, probably you need the following workaround to avoid `can't open lock file /run/xtables.lock:` error:
60+
```bash
61+
sudo dnf install -y policycoreutils-python-utils
62+
sudo semanage permissive -a iptables_t
63+
```
64+
65+
See https://github.com/moby/moby/issues/41230 .
66+
This workaround will no longer be needed after the release of Fedora 34.

0 commit comments

Comments
 (0)