k3s/tests/snapshotter/btrfs/opensuse-leap/Vagrantfile

101 lines
4.0 KiB
Ruby
Raw Normal View History

# -*- 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