mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
112 lines
4.8 KiB
Ruby
112 lines
4.8 KiB
Ruby
|
# -*- mode: ruby -*-
|
||
|
# vi: set ft=ruby :
|
||
|
#
|
||
|
|
||
|
ENV['TEST_INSTALL_SH'] ||= '../../../install.sh'
|
||
|
|
||
|
Vagrant.configure("2") do |config|
|
||
|
config.vagrant.plugins = {
|
||
|
'vagrant-k3s' => {:version => '~> 0.1.2'},
|
||
|
'vagrant-reload' => {},
|
||
|
}
|
||
|
|
||
|
config.vm.define 'install-microos', primary: true do |test|
|
||
|
test.vm.box = 'opensuse/MicroOS.x86_64'
|
||
|
test.vm.hostname = 'install'
|
||
|
# microos does not ship selinux-enabled but such is just an update + reboot away
|
||
|
test.vm.provision 'selinux-setup', type: 'shell', run: 'once' do |sh|
|
||
|
sh.inline = <<~EOF
|
||
|
transactional-update -n \
|
||
|
setup-selinux \
|
||
|
pkg install -y apparmor-parser
|
||
|
EOF
|
||
|
end
|
||
|
# reboot to have the snapshot from the previous step as the rootfs
|
||
|
test.vm.provision 'selinux-reload', type: 'reload', run: 'once'
|
||
|
test.vm.provision 'selinux-status', type: 'shell', run: 'once', inline: 'sestatus'
|
||
|
test.vm.provision 'k3s-upload', type: 'file', run: 'always', source: ENV['TEST_INSTALL_SH'], destination: 'install.sh'
|
||
|
test.vm.provision 'k3s-install', type: 'k3s', run: 'once' do |k3s|
|
||
|
k3s.installer_url = 'file:///home/vagrant/install.sh'
|
||
|
k3s.args = %w[server]
|
||
|
k3s.env = %w[INSTALL_K3S_NAME=server]
|
||
|
k3s.config = {
|
||
|
:selinux => true,
|
||
|
:token => 'vagrant',
|
||
|
}
|
||
|
k3s.config_mode = '0644' # side-step https://github.com/k3s-io/k3s/issues/4321
|
||
|
end
|
||
|
# install.sh will move the snapshot forward when installing k3s-selinux policy, so, we reboot to pick that up
|
||
|
test.vm.provision 'k3s-reload', type: 'reload', run: 'once'
|
||
|
test.vm.provision "k3s-wait-for-node", 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/$(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: "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
|
||
|
time timeout 180 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-wait-for-local-storage", 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
|
||
|
time timeout 180 bash -c 'while ! (kubectl --namespace kube-system rollout status --timeout 10s deploy/local-path-provisioner 2>/dev/null); do sleep 5; done'
|
||
|
SHELL
|
||
|
end
|
||
|
test.vm.provision "k3s-wait-for-metrics-server", 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
|
||
|
time timeout 180 bash -c 'while ! (kubectl --namespace kube-system rollout status --timeout 10s deploy/metrics-server 2>/dev/null); do sleep 5; done'
|
||
|
SHELL
|
||
|
end
|
||
|
test.vm.provision "k3s-wait-for-traefik", 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
|
||
|
time timeout 180 bash -c 'while ! (kubectl --namespace kube-system rollout status --timeout 10s deploy/traefik 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
|
||
|
SHELL
|
||
|
end
|
||
|
test.vm.provision "k3s-status-selinux", 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
|
||
|
ps auxZ | grep container_ | grep -v grep
|
||
|
SHELL
|
||
|
end
|
||
|
end
|
||
|
|
||
|
%w[hyperv libvirt virtualbox vmware_desktop].each do |p|
|
||
|
config.vm.provider p do |v|
|
||
|
v.cpus = ENV['TEST_VM_CPUS'] || 2
|
||
|
v.memory = ENV['TEST_VM_MEMORY'] || 2048
|
||
|
end
|
||
|
end
|
||
|
config.vm.provider :virtualbox do |v,o|
|
||
|
v.gui = false
|
||
|
v.check_guest_additions = false
|
||
|
end
|
||
|
|
||
|
config.vm.synced_folder '.', '/vagrant', disabled: true
|
||
|
end
|