Skip to content

Commit

Permalink
containerd/cri: enable the btrfs snapshotter (#4316)
Browse files Browse the repository at this point in the history
* vendor: btrfs
* enable the btrfs snapshotter
* testing: snapshotter/btrfs

Signed-off-by: Jacob Blain Christen <jacob@rancher.com>
  • Loading branch information
dweomer authored Oct 30, 2021
1 parent 3da1bb3 commit 702fe24
Show file tree
Hide file tree
Showing 22 changed files with 1,644 additions and 2 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/snapshotter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Snapshotter Testing
on:
push:
paths-ignore:
- "install.sh"
- "tests/cgroup2/**"
- "tests/install/**"
- "tests/integration/**"
- "tests/unitcoverage/**"
pull_request:
paths-ignore:
- "install.sh"
- "tests/cgroup2/**"
- "tests/install/**"
- "tests/integration/**"
- "tests/unitcoverage/**"
workflow_dispatch: {}
jobs:
build:
name: "Build"
runs-on: ubuntu-20.04
timeout-minutes: 40
steps:
- name: "Checkout"
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: "Build"
run: DOCKER_BUILDKIT=1 SKIP_VALIDATE=1 make
- name: "Upload Binary"
uses: actions/upload-artifact@v2
with:
name: k3s
path: dist/artifacts/k3s
- name: "Upload Images"
uses: actions/upload-artifact@v2
with:
name: k3s-airgap-images-amd64.tar
path: dist/artifacts/k3s-airgap-images-amd64.tar
test:
name: "Test"
# nested virtualization is only available on macOS hosts
runs-on: macos-10.15
needs: build
timeout-minutes: 40
strategy:
matrix:
vm: [opensuse-leap]
steps:
- name: "Checkout"
uses: actions/checkout@v2
with:
fetch-depth: 1
- name: "Download Binary"
uses: actions/download-artifact@v2
with:
name: k3s
path: dist/artifacts/
- name: "Download Images"
uses: actions/download-artifact@v2
with:
name: k3s-airgap-images-amd64.tar
path: dist/artifacts/
- name: "Vagrant Plugin(s)"
working-directory: tests/snapshotter/btrfs/${{ matrix.vm }}
run: vagrant plugin install vagrant-k3s
- name: "Vagrant VM"
working-directory: tests/snapshotter/btrfs/${{ matrix.vm }}
env:
VAGRANT_EXPERIMENTAL: disks
run: vagrant up
2 changes: 1 addition & 1 deletion Dockerfile.dapper
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ENV no_proxy=$no_proxy
RUN apk -U --no-cache add bash git gcc musl-dev docker vim less file curl wget ca-certificates jq linux-headers \
zlib-dev tar zip squashfs-tools npm coreutils python3 openssl-dev libffi-dev libseccomp libseccomp-dev \
libseccomp-static make libuv-static sqlite-dev sqlite-static libselinux libselinux-dev zlib-dev zlib-static \
zstd gzip alpine-sdk binutils-gold
zstd gzip alpine-sdk binutils-gold btrfs-progs-dev btrfs-progs-static
RUN if [ "$(go env GOARCH)" = "arm64" ]; then \
wget https://github.com/aquasecurity/trivy/releases/download/v0.16.0/trivy_0.16.0_Linux-ARM64.tar.gz && \
tar -zxvf trivy_0.16.0_Linux-ARM64.tar.gz && \
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u9
github.com/container-storage-interface/spec v1.5.0 h1:lvKxe3uLgqQeVQcrnL2CPQKISoKjTJxojEs9cBk+HXo=
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=
github.com/containerd/aufs v1.0.0/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU=
github.com/containerd/btrfs v1.0.0 h1:osn1exbzdub9L5SouXO5swW4ea/xVdJZ3wokxN5GrnA=
github.com/containerd/btrfs v1.0.0/go.mod h1:zMcX3qkXTAi9GI50+0HOeuV8LU2ryCE/V2vG/ZBiTss=
github.com/containerd/cgroups v1.0.1 h1:iJnMvco9XGvKUvNQkv88bE4uJXxRQH18efbKo9w5vHQ=
github.com/containerd/cgroups v1.0.1/go.mod h1:0SJrPIenamHDcZhEcJMNBB85rHcUsw4f25ZfBiPYRkU=
Expand Down
1 change: 1 addition & 0 deletions pkg/containerd/builtins_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
_ "github.com/containerd/containerd/runtime/v2/runc/options"
_ "github.com/containerd/containerd/snapshots/native/plugin"
_ "github.com/containerd/containerd/snapshots/overlay/plugin"
_ "github.com/containerd/containerd/snapshots/btrfs/plugin"
_ "github.com/containerd/fuse-overlayfs-snapshotter/plugin"
_ "github.com/containerd/stargz-snapshotter/service/plugin"
)
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ STATIC="
STATIC_SQLITE="
-extldflags '-static -lm -ldl -lz -lpthread'
"
TAGS="ctrd apparmor seccomp no_btrfs netcgo osusergo providerless"
TAGS="ctrd apparmor seccomp netcgo osusergo providerless"
RUNC_TAGS="apparmor seccomp"
RUNC_STATIC="static"

Expand Down
100 changes: 100 additions & 0 deletions tests/snapshotter/btrfs/opensuse-leap/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
#

ENV['TEST_VM_NAME'] ||= 'snapshotter-btrfs'
ENV['TEST_VM_HOSTNAME'] ||= 'test'

Vagrant.configure("2") do |config|
config.vagrant.plugins = {
'vagrant-k3s' => {:version => '~> 0.1.3'},
}
config.vm.define ENV['TEST_VM_NAME'], primary: true do |test|
test.vm.box = "opensuse/Leap-15.3.x86_64"
test.vm.hostname = ENV['TEST_VM_HOSTNAME']
test.vm.provision 'k3s-prepare', type: 'shell', run: 'once', privileged: true do |sh|
sh.inline = <<~EOF
#!/usr/bin/env bash
set -eu -o pipefail
zypper install -y btrfsprogs hostname
mkdir -p /var/lib/rancher/k3s /etc/rancher/k3s /usr/local/bin
if ! mountpoint -q /var/lib/rancher/k3s; then
: ${BTRFS_DEV:=#{ENV['BTRFS_DEV']}}
for disk in sd[b-d] vd[b-d] xd[b-d]; do
if [ -n "${BTRFS_DEV}" ]; then break; fi
: ${BTRFS_DEV:=$(test -b /dev/$disk && echo $disk)}
done
btrfs filesystem show /dev/${BTRFS_DEV:?unable to determine automatically, please specify} 2>/dev/null || mkfs -t btrfs /dev/${BTRFS_DEV}
mountpoint -q /mnt || mount -t btrfs /dev/${BTRFS_DEV} /mnt
btrfs subvolume show /mnt/@k3s 2>/dev/null || btrfs subvolume create /mnt/@k3s
umount /mnt
mount -t btrfs -o subvol=@k3s /dev/${BTRFS_DEV} /var/lib/rancher/k3s
fi
if [ -e /vagrant/k3s ]; then
cp -vf /vagrant/k3s /usr/local/bin/
chmod -v +x /usr/local/bin/k3s
fi
if [ -e /vagrant/*.tar ]; then
mkdir -vp /var/lib/rancher/k3s/agent/images
for tar in /vagrant/*.tar; do
cp -vf $tar /var/lib/rancher/k3s/agent/images/
done
fi
EOF
end
test.vm.provision 'k3s-install', type: 'k3s', run: 'once' do |k3s|
k3s.args = %w[server --snapshotter=btrfs]
k3s.env = %w[INSTALL_K3S_NAME=server INSTALL_K3S_SKIP_DOWNLOAD=true K3S_TOKEN=vagrant]
k3s.config = {
'disable' => %w[local-storage metrics-server servicelb traefik],
'disable-helm-controller' => true,
'disable-network-policy' => true,
'write-kubeconfig-mode' => '0644',
}
k3s.config_mode = '0644' # side-step https://github.com/k3s-io/k3s/issues/4321
end
test.vm.provision "k3s-ready", type: "shell", run: "once" do |sh|
sh.env = { :PATH => "/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" }
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eu -o pipefail
echo 'Waiting for node to be ready ...'
time timeout 120 bash -c 'while ! (kubectl wait --for condition=ready node/$(hostname) 2>/dev/null); do sleep 5; done'
time timeout 300 bash -c 'while ! (kubectl --namespace kube-system rollout status --timeout 10s deploy/coredns 2>/dev/null); do sleep 5; done'
SHELL
end
test.vm.provision "k3s-status", type: "shell", run: "once" do |sh|
sh.env = { :PATH => "/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" }
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eux -o pipefail
kubectl get node,all -A -o wide
btrfs subvolume list /var/lib/rancher/k3s/agent/containerd/io.containerd.snapshotter.v1.btrfs
SHELL
end
end

%w[hyperv libvirt virtualbox vmware_desktop].each do |p|
config.vm.provider p do |v|
v.cpus = ENV['CPUS'] || 2
v.memory = ENV['MEMORY'] || 2048
end
end

config.vm.provider :hyperv do |v,o|
o.vm.disk :disk, name: "btrfs", size: "8GB" # Requires VAGRANT_EXPERIMENTAL="disks"
end

config.vm.provider :libvirt do |v,o|
v.storage :file, :size => '8G'
end

config.vm.provider :virtualbox do |v,o|
v.gui = false
v.check_guest_additions = false
o.vm.disk :disk, name: "btrfs", size: "8GB" # Requires VAGRANT_EXPERIMENTAL="disks"
end

config.vm.synced_folder '../../../../dist/artifacts', '/vagrant', type: 'rsync', disabled: ['1', 'true'].include?(ENV['RSYNC_DISABLE']),
rsync__exclude: ENV['RSYNC_EXCLUDE'] || '*.tar.*'
end
28 changes: 28 additions & 0 deletions vendor/github.com/containerd/btrfs/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 702fe24

Please sign in to comment.