Skip to content

Commit 285db17

Browse files
authored
Merge pull request #368 from austinvazquez/add-cgroups-v1-testing
Swap cgroupsv1 testing from GitHub Actions runner to Vagrant VM
2 parents 32dca23 + ba9729c commit 285db17

File tree

3 files changed

+266
-10
lines changed

3 files changed

+266
-10
lines changed

.github/workflows/ci.yml

Lines changed: 81 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
#
1616
project:
1717
name: Project Checks
18-
runs-on: ubuntu-22.04
18+
runs-on: ubuntu-latest
1919
timeout-minutes: 5
2020

2121
steps:
@@ -46,7 +46,7 @@ jobs:
4646
name: Lint
4747
timeout-minutes: 10
4848
needs: [project]
49-
runs-on: ubuntu-22.04
49+
runs-on: ubuntu-latest
5050

5151
strategy:
5252
matrix:
@@ -71,18 +71,91 @@ jobs:
7171
args: --verbose
7272
working-directory: src/github.com/containerd/cgroups
7373

74-
test:
75-
name: Test cgroups
74+
cgroupV1:
75+
name: Cgroup V1 tests
76+
runs-on: ubuntu-24.04
7677
timeout-minutes: 15
7778
needs: [project]
7879

7980
strategy:
81+
fail-fast: false
82+
matrix:
83+
go-version: [1.22.x, 1.23.x]
84+
85+
env:
86+
BOX: almalinux/8
87+
GO_VERSION: ${{ matrix.go-version }}
88+
89+
steps:
90+
- name: Show the host info
91+
run: |
92+
set -x
93+
uname -a
94+
cat /etc/os-release
95+
cat /proc/cpuinfo
96+
free -mt
97+
98+
- name: Checkout cgroups
99+
uses: actions/checkout@v4
100+
with:
101+
path: src/github.com/containerd/cgroups
102+
103+
- name: Install Go
104+
uses: actions/setup-go@v5
105+
with:
106+
go-version: ${{ matrix.go-version }}
107+
108+
- name: Set Go version
109+
run: |
110+
go_version=$(go version | grep -oP 'go\d+\.\d+\.\d+' | sed -E 's/go([0-9]+)\.([0-9]+)\.([0-9]+)/\1\.\2\.\3/')
111+
echo "GO_VERSION=$go_version" >> $GITHUB_ENV
112+
113+
- uses: actions/cache@v4
114+
with:
115+
path: /root/.vagrant.d
116+
key: vagrant-${{ env.BOX }}
117+
118+
- name: Set up vagrant
119+
run: |
120+
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
121+
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
122+
sudo sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
123+
sudo apt-get update
124+
sudo apt-get install -y libvirt-daemon libvirt-daemon-system vagrant ovmf
125+
126+
# https://github.com/vagrant-libvirt/vagrant-libvirt/issues/1725#issuecomment-1454058646
127+
sudo cp /usr/share/OVMF/OVMF_VARS_4M.fd /var/lib/libvirt/qemu/nvram/
128+
sudo systemctl enable --now libvirtd
129+
sudo apt-get build-dep -y ruby-libvirt
130+
sudo apt-get install -y --no-install-recommends libxslt-dev libxml2-dev libvirt-dev ruby-bundler ruby-dev zlib1g-dev
131+
132+
if ! vagrant plugin list | grep -q vagrant-libvirt; then
133+
sudo env VAGRANT_DISABLE_STRICT_DEPENDENCY_ENFORCEMENT=1 vagrant plugin install vagrant-libvirt
134+
fi
135+
136+
- name: Boot VM
137+
working-directory: src/github.com/containerd/cgroups
138+
run: sudo BOX=$BOX GO_VERSION=$GO_VERSION vagrant up --provision-with=install-packages,setup-etc-environment,install-golang,setup-gopath
139+
140+
- name: Run cgroup tests
141+
working-directory: src/github.com/containerd/cgroups
142+
run: sudo BOX=$BOX GO_VERSION=$GO_VERSION vagrant up --provision-with=test
143+
144+
- name: Build cgctl
145+
working-directory: src/github.com/containerd/cgroups
146+
run: sudo BOX=$BOX GO_VERSION=$GO_VERSION vagrant up --provision-with=build-cgctl
147+
148+
cgroupV2:
149+
name: Cgroup V2 tests
150+
runs-on: ubuntu-24.04
151+
timeout-minutes: 15
152+
needs: [project]
153+
154+
strategy:
155+
fail-fast: false
80156
matrix:
81157
go-version: [1.22.x, 1.23.x]
82-
# Ubuntu-20.04 has cgroups v1 default; Ubuntu-22.04 has cgroups v2 default.
83-
os: [ubuntu-20.04, ubuntu-22.04]
84158

85-
runs-on: ${{ matrix.os }}
86159
steps:
87160
- name: Checkout cgroups
88161
uses: actions/checkout@v4
@@ -93,8 +166,6 @@ jobs:
93166
uses: actions/setup-go@v5
94167
with:
95168
go-version: ${{ matrix.go-version }}
96-
# Disable Go caching feature when compiling across Linux distributions due to collisions until https://github.com/actions/setup-go/issues/368 is resolved.
97-
cache: false
98169

99170
- name: Run cgroup tests
100171
run: |
@@ -107,7 +178,7 @@ jobs:
107178

108179
proto:
109180
name: Compare auto-generated Go files
110-
runs-on: ubuntu-22.04
181+
runs-on: ubuntu-latest
111182

112183
steps:
113184
- name: Checkout cgroups

Vagrantfile

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Copyright The containerd Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
Vagrant.configure("2") do |config|
19+
config.vm.box = ENV["BOX"] ? ENV["BOX"].split("@")[0] : "almalinux/8"
20+
# BOX_VERSION is deprecated. Use "BOX=<BOX>@<BOX_VERSION>".
21+
config.vm.box_version = ENV["BOX_VERSION"] || (ENV["BOX"].split("@")[1] if ENV["BOX"])
22+
23+
memory = 4096
24+
cpus = 2
25+
disk_size = 60
26+
config.vm.provider :virtualbox do |v, o|
27+
v.memory = memory
28+
v.cpus = cpus
29+
# Needs env var VAGRANT_EXPERIMENTAL="disks"
30+
o.vm.disk :disk, size: "#{disk_size}GB", primary: true
31+
v.customize ["modifyvm", :id, "--firmware", "efi"]
32+
end
33+
config.vm.provider :libvirt do |v|
34+
v.memory = memory
35+
v.cpus = cpus
36+
v.machine_virtual_size = disk_size
37+
# https://github.com/vagrant-libvirt/vagrant-libvirt/issues/1725#issuecomment-1454058646
38+
# Needs `sudo cp /usr/share/OVMF/OVMF_VARS_4M.fd /var/lib/libvirt/qemu/nvram/`
39+
v.loader = '/usr/share/OVMF/OVMF_CODE_4M.fd'
40+
v.nvram = '/var/lib/libvirt/qemu/nvram/OVMF_VARS_4M.fd'
41+
end
42+
43+
config.vm.synced_folder ".", "/vagrant", type: "rsync"
44+
45+
config.vm.provision 'shell', path: 'script/resize-vagrant-root.sh'
46+
47+
# To re-run, installing CNI from RPM:
48+
# INSTALL_PACKAGES="containernetworking-plugins" vagrant up --provision-with=install-packages
49+
#
50+
config.vm.provision "install-packages", type: "shell", run: "once" do |sh|
51+
sh.upload_path = "/tmp/vagrant-install-packages"
52+
sh.env = {
53+
'INSTALL_PACKAGES': ENV['INSTALL_PACKAGES'],
54+
}
55+
sh.inline = <<~SHELL
56+
#!/usr/bin/env bash
57+
set -eux -o pipefail
58+
dnf -y install \
59+
curl \
60+
gcc \
61+
git \
62+
make \
63+
${INSTALL_PACKAGES}
64+
SHELL
65+
end
66+
67+
# AlmaLinux does not have /usr/local/{bin,sbin} in the PATH by default
68+
config.vm.provision "setup-etc-environment", type: "shell", run: "once" do |sh|
69+
sh.upload_path = "/tmp/vagrant-setup-etc-environment"
70+
sh.inline = <<~SHELL
71+
#!/usr/bin/env bash
72+
set -eux -o pipefail
73+
cat >> /etc/environment <<EOF
74+
PATH=/usr/local/go/bin:/usr/local/bin:/usr/local/sbin:$PATH
75+
EOF
76+
source /etc/environment
77+
SHELL
78+
end
79+
80+
# To re-run this provisioner, installing a different version of go:
81+
# GO_VERSION="1.14.6" vagrant up --provision-with=install-golang
82+
#
83+
config.vm.provision "install-golang", type: "shell", run: "once" do |sh|
84+
sh.upload_path = "/tmp/vagrant-install-golang"
85+
sh.env = {
86+
'GO_VERSION': ENV['GO_VERSION'] || "1.24.3",
87+
}
88+
sh.inline = <<~SHELL
89+
#!/usr/bin/env bash
90+
set -eux -o pipefail
91+
curl -fsSL "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" | tar Cxz /usr/local
92+
cat >> /etc/profile.d/sh.local <<EOF
93+
GOPATH=\\$HOME/go
94+
PATH=\\$GOPATH/bin:\\$PATH
95+
export GOPATH PATH
96+
git config --global --add safe.directory /vagrant
97+
EOF
98+
source /etc/profile.d/sh.local
99+
SHELL
100+
end
101+
102+
config.vm.provision "setup-gopath", type: "shell", run: "once" do |sh|
103+
sh.upload_path = "/tmp/vagrant-setup-gopath"
104+
sh.inline = <<~SHELL
105+
#!/usr/bin/env bash
106+
source /etc/environment
107+
source /etc/profile.d/sh.local
108+
set -eux -o pipefail
109+
mkdir -p ${GOPATH}/src/github.com/containerd
110+
ln -fnsv /vagrant ${GOPATH}/src/github.com/containerd/cgroups
111+
SHELL
112+
end
113+
114+
config.vm.provision "test", type: "shell", run: "never" do |sh|
115+
sh.upload_path = "/tmp/test"
116+
sh.env = {
117+
'GOTEST': ENV['GOTEST'] || "go test",
118+
'GOTESTSUM_JUNITFILE': ENV['GOTESTSUM_JUNITFILE'],
119+
'GOTESTSUM_JSONFILE': ENV['GOTESTSUM_JSONFILE'],
120+
}
121+
sh.inline = <<~SHELL
122+
#!/usr/bin/env bash
123+
source /etc/environment
124+
source /etc/profile.d/sh.local
125+
set -eux -o pipefail
126+
cd ${GOPATH}/src/github.com/containerd/cgroups
127+
go env -w CGO_ENABLED=1
128+
go test -exec "sudo" -v -race -coverprofile=coverage.txt -covermode=atomic ./...
129+
SHELL
130+
end
131+
132+
config.vm.provision "build-cgctl", type: "shell", run: "never" do |sh|
133+
sh.upload_path = "/tmp/build-cgctl"
134+
sh.inline = <<~SHELL
135+
#!/usr/bin/env bash
136+
source /etc/environment
137+
source /etc/profile.d/sh.local
138+
set -eux -o pipefail
139+
cd ${GOPATH}/src/github.com/containerd/cgroups
140+
make all
141+
SHELL
142+
end
143+
end

script/resize-vagrant-root.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright The containerd Authors.
4+
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -eu -o pipefail
18+
19+
# Rocky Linux doesn't have growpart by default.
20+
(growpart -h > /dev/null) || dnf -y install cloud-utils-growpart
21+
22+
df_line=$(df -T / | grep '^/dev/')
23+
if [[ "$df_line" =~ ^/dev/([a-z]+)([0-9]+) ]]; then
24+
dev="${BASH_REMATCH[1]}"
25+
part="${BASH_REMATCH[2]}"
26+
growpart "/dev/$dev" "$part"
27+
28+
fstype=$(echo "$df_line" | awk '{print $2}')
29+
if [[ "$fstype" = 'btrfs' ]]; then
30+
btrfs filesystem resize max /
31+
elif [[ "$fstype" = 'xfs' ]]; then
32+
xfs_growfs -d /
33+
else
34+
echo "Unknown filesystem: $df_line"
35+
exit 1
36+
fi
37+
elif [[ "$df_line" =~ ^/dev/mapper/ ]]; then
38+
echo "TODO: support device mapper: $df_line"
39+
else
40+
echo "Failed to parse: $df_line"
41+
exit 1
42+
fi

0 commit comments

Comments
 (0)