2021-10-30 06:31:33 +00:00
|
|
|
# -*- mode: ruby -*-
|
|
|
|
# vi: set ft=ruby :
|
|
|
|
#
|
2021-11-15 18:50:38 +00:00
|
|
|
# Vagrant box for testing k3s with the btrfs snapshotter. Usage:
|
|
|
|
# VAGRANT_EXPERIMENTAL=disks vagrant up
|
2021-10-30 06:31:33 +00:00
|
|
|
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vagrant.plugins = {
|
|
|
|
'vagrant-k3s' => {:version => '~> 0.1.3'},
|
|
|
|
}
|
2021-11-15 18:50:38 +00:00
|
|
|
config.vm.box = "opensuse/Leap-15.3.x86_64"
|
|
|
|
config.vm.boot_timeout = ENV['TEST_VM_BOOT_TIMEOUT'] || 600 # seconds
|
2022-03-15 17:29:56 +00:00
|
|
|
config.vm.synced_folder '../../../../dist/artifacts', '/vagrant', type: 'rsync', disabled: false,
|
2021-11-15 18:50:38 +00:00
|
|
|
rsync__exclude: ENV['RSYNC_EXCLUDE'] || '*.tar.*'
|
|
|
|
|
|
|
|
config.vm.define 'snapshotter-btrfs', primary: true do |test|
|
|
|
|
test.vm.hostname = 'smoke'
|
2021-10-30 06:31:33 +00:00
|
|
|
test.vm.provision 'k3s-prepare', type: 'shell', run: 'once', privileged: true do |sh|
|
|
|
|
sh.inline = <<~EOF
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -eu -o pipefail
|
2022-05-10 00:22:18 +00:00
|
|
|
zypper install -y apparmor-parser btrfsprogs hostname
|
2021-10-30 06:31:33 +00:00
|
|
|
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
|
2021-11-15 18:50:38 +00:00
|
|
|
# Install k3s binary
|
|
|
|
install -m 755 /vagrant/k3s /usr/local/bin
|
2021-10-30 06:31:33 +00:00
|
|
|
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
|
2021-11-15 18:50:38 +00:00
|
|
|
test.vm.provision "k3s-wait-for-node", type: "shell", run: ENV['CI'] == 'true' ? 'never' : 'once' do |sh|
|
2021-10-30 06:31:33 +00:00
|
|
|
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 ...'
|
2021-11-15 18:50:38 +00:00
|
|
|
time timeout 300 bash -c 'while ! (kubectl wait --for condition=ready node/$(hostnamectl --static) 2>/dev/null); do sleep 5; done'
|
|
|
|
kubectl get node,all -A -o wide
|
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
test.vm.provision "k3s-wait-for-coredns", type: "shell", run: ENV['CI'] == 'true' ? 'never' : '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
|
2021-10-30 06:31:33 +00:00
|
|
|
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
|
2021-11-15 18:50:38 +00:00
|
|
|
test.vm.provision "k3s-status", type: "shell", run: ENV['CI'] == 'true' ? 'never' : 'once' do |sh|
|
2021-10-30 06:31:33 +00:00
|
|
|
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
|
2021-11-15 18:50:38 +00:00
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
test.vm.provision "k3s-snapshots", type: "shell", run: ENV['CI'] == 'true' ? 'never' : '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
|
2021-10-30 06:31:33 +00:00
|
|
|
btrfs subvolume list /var/lib/rancher/k3s/agent/containerd/io.containerd.snapshotter.v1.btrfs
|
|
|
|
SHELL
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-15 18:50:38 +00:00
|
|
|
%w[libvirt virtualbox].each do |p|
|
2021-10-30 06:31:33 +00:00
|
|
|
config.vm.provider p do |v|
|
2021-11-15 18:50:38 +00:00
|
|
|
v.cpus = ENV['TEST_VM_CPUS'] || 2
|
|
|
|
v.memory = ENV['TEST_VM_MEMORY'] || 2048
|
2021-10-30 06:31:33 +00:00
|
|
|
end
|
|
|
|
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
|
|
|
|
end
|