Skip to content

Commit d03d648

Browse files
authored
Merge pull request #71 from AkihiroSuda/dev-vagrant
add Vagrantfile (Fedora 33) for cgroup2 testing
2 parents 3d61627 + 2d39375 commit d03d648

File tree

8 files changed

+155
-7
lines changed

8 files changed

+155
-7
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

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ARG CNI_ISOLATION_VERSION=0.0.3
88
ARG BUILDKIT_VERSION=0.8.1
99
ARG GO_VERSION=1.15.8
1010

11-
FROM ubuntu:${UBUNTU_VERSION} AS base
11+
FROM mirror.gcr.io/library/ubuntu:${UBUNTU_VERSION} AS base
1212
ENV DEBIAN_FRONTEND=noninteractive
1313
RUN apt-get update && \
1414
apt-get install -qq -y --no-install-recommends \

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.

main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/containerd/containerd"
2929
"github.com/containerd/containerd/defaults"
3030
"github.com/containerd/containerd/namespaces"
31-
gocni "github.com/containerd/go-cni"
3231
"github.com/pkg/errors"
3332
"github.com/sirupsen/logrus"
3433
"github.com/urfave/cli/v2"
@@ -90,7 +89,7 @@ func newApp() *cli.App {
9089
Usage: "Set the cni-plugins binary directory",
9190
// CNI_PATH is from https://www.cni.dev/docs/cnitool/
9291
EnvVars: []string{"CNI_PATH"},
93-
Value: gocni.DefaultCNIDir,
92+
Value: ncdefaults.CNIPath(),
9493
},
9594
&cli.StringFlag{
9695
Name: "cni-netconfpath",

pkg/defaults/defaults.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package defaults
1919

2020
import (
2121
"fmt"
22+
"os"
2223
"path/filepath"
2324

2425
"github.com/AkihiroSuda/nerdctl/pkg/rootlessutil"
@@ -38,6 +39,31 @@ func DataRoot() string {
3839
return filepath.Join(xdh, "nerdctl")
3940
}
4041

42+
func CNIPath() string {
43+
candidates := []string{
44+
"/usr/local/libexec/cni",
45+
"/usr/libexec/cni", // Fedora
46+
}
47+
if rootlessutil.IsRootless() {
48+
home := os.Getenv("HOME")
49+
if home == "" {
50+
panic("environment variable HOME is not set")
51+
}
52+
candidates = append([]string{
53+
filepath.Join(home, "opt/cni/bin"),
54+
}, candidates...)
55+
}
56+
57+
for _, f := range candidates {
58+
if _, err := os.Stat(f); err == nil {
59+
return f
60+
}
61+
}
62+
63+
// default: /opt/cni/bin
64+
return gocni.DefaultCNIDir
65+
}
66+
4167
func CNINetConfPath() string {
4268
if !rootlessutil.IsRootless() {
4369
return gocni.DefaultNetDir

pkg/testutil/testutil.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ func NewBase(t *testing.T) *Base {
133133
return base
134134
}
135135

136-
// TODO: avoid using Docker Hub
136+
// use GCR mirror to avoid hitting Docker Hub rate limit
137137
const (
138-
AlpineImage = "alpine"
139-
NginxAlpineImage = "nginx:1.19.6-alpine"
138+
AlpineImage = "mirror.gcr.io/library/alpine:3.13"
139+
NginxAlpineImage = "mirror.gcr.io/library/nginx:1.19.6-alpine"
140140
NginxAlpineIndexHTMLSnippet = "<title>Welcome to nginx!</title>"
141141
)

0 commit comments

Comments
 (0)