Skip to content

Commit

Permalink
Add a change for killall to not unmount server and agent directory
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Savian <vitor.savian@suse.com>

Add recursive search and deletion of unmounted/mounted dirs in killall

Signed-off-by: Vitor Savian <vitor.savian@suse.com>

Only clean the server and agent directory if it is uninstall

Signed-off-by: Vitor Savian <vitor.savian@suse.com>

Add uninstall test to check mount points

Signed-off-by: Vitor Savian <vitor.savian@suse.com>

Add uninstall test in CI

Signed-off-by: Vitor Savian <vitor.savian@suse.com>
  • Loading branch information
vitorsavian committed Aug 7, 2024
1 parent 82ba778 commit 3aceb85
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 5 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,19 @@ jobs:
run: vagrant provision --provision-with=k3s-status
- name: "k3s-procps"
run: vagrant provision --provision-with=k3s-procps
- name: "k3s-mount-directory"
run: vagrant provision --provision-with=k3s-mount-directory
- name: "k3s-uninstall"
run: vagrant provision --provision-with=k3s-uninstall
- name: "k3s-check-mount"
run: vagrant provision --provision-with=k3s-check-mount
- name: "k3s-unmount-dir"
run: vagrant provision --provision-with=k3s-unmount-dir
- name: Cleanup VM
run: vagrant destroy -f
- name: On Failure, launch debug session
uses: lhotari/action-upterm@v1
if: ${{ failure() }}
with:
## If no one connects after 5 minutes, shut down server.
wait-timeout-minutes: 5
wait-timeout-minutes: 5
22 changes: 20 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,6 @@ do_unmount_and_remove() {
}
do_unmount_and_remove '/run/k3s'
do_unmount_and_remove "${K3S_DATA_DIR}"
do_unmount_and_remove '/var/lib/kubelet/pods'
do_unmount_and_remove '/var/lib/kubelet/plugins'
do_unmount_and_remove '/run/netns/cni-'
Expand Down Expand Up @@ -902,10 +901,29 @@ for cmd in kubectl crictl ctr; do
fi
done
clean_mounted_directory() {
if ! grep -q " \$1" /proc/mounts; then
rm -rf "\$1"
return 0
fi
for path in "\$1"/*; do
if [ -d "\$path" ]; then
if grep -q " \$path" /proc/mounts; then
clean_mounted_directory "\$path"
else
rm -rf "\$path"
fi
else
rm "\$path"
fi
done
}
rm -rf /etc/rancher/k3s
rm -rf /run/k3s
rm -rf /run/flannel
rm -rf \${K3S_DATA_DIR}
clean_mounted_directory \${K3S_DATA_DIR}
rm -rf /var/lib/kubelet
rm -f ${BIN_DIR}/k3s
rm -f ${KILLALL_K3S_SH}
Expand Down
2 changes: 1 addition & 1 deletion install.sh.sha256sum
Original file line number Diff line number Diff line change
@@ -1 +1 @@
937085bbac8e3b55209739762e05c2c1006c4f4fe65dba01908f3544dc47da27 install.sh
e10b36efb5e7e7692f144582d09f5909a91c5b5996965d643dbe13282befcfc1 install.sh
9 changes: 9 additions & 0 deletions tests/install/fedora/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ Vagrant.configure("2") do |config|

checkK3sProcesses(test.vm)

mountDirs(test.vm)

checkMountPoint(test.vm)

runUninstall(test.vm)

checkMountPoint(test.vm)

unmountDir(test.vm)
end

config.vm.provision 'selinux-status', type: 'shell', run: 'once', inline: 'sestatus'
Expand Down
47 changes: 46 additions & 1 deletion tests/install/install_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,49 @@ def checkCGroupV2(vm)
k3s check-config | grep 'cgroups V2 mounted'
SHELL
end
end
end

def mountDirs(vm)
vm.provision "k3s-mount-directory", type: "shell", run: ENV['CI'] == 'true' ? 'never' : 'once' do |sh|
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eu -o pipefail
echo 'Mounting server dir'
mount --bind /var/lib/rancher/k3s/server /var/lib/rancher/k3s/server
SHELL
end
end

def runUninstall(vm)
vm.provision "k3s-uninstall", type: "shell", run: ENV['CI'] == 'true' ? 'never' : 'once' do |sh|
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eu -o pipefail
echo 'Uninstall k3s'
k3s-server-uninstall.sh
SHELL
end
end

def checkMountPoint(vm)
vm.provision "k3s-check-mount", type: "shell", run: ENV['CI'] == 'true' ? 'never' : 'once' do |sh|
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eu -o pipefail
echo 'Check the mount'
mount | grep /var/lib/rancher/k3s/server
SHELL
end
end

def unmountDir(vm)
vm.provision "k3s-unmount-dir", type: "shell", run: ENV['CI'] == 'true' ? 'never' : 'once' do |sh|
sh.inline = <<~SHELL
#!/usr/bin/env bash
set -eu -o pipefail
echo 'unmount the mount'
umount /var/lib/rancher/k3s/server
rm -rf /var/lib/rancher
SHELL
end
end
9 changes: 9 additions & 0 deletions tests/install/opensuse-leap/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ Vagrant.configure("2") do |config|

checkK3sProcesses(test.vm)

mountDirs(test.vm)

checkMountPoint(test.vm)

runUninstall(test.vm)

checkMountPoint(test.vm)

unmountDir(test.vm)
end

%w[libvirt virtualbox vmware_desktop].each do |p|
Expand Down
9 changes: 9 additions & 0 deletions tests/install/rocky-8/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ Vagrant.configure("2") do |config|

checkK3sProcesses(test.vm)

mountDirs(test.vm)

checkMountPoint(test.vm)

runUninstall(test.vm)

checkMountPoint(test.vm)

unmountDir(test.vm)
end

config.vm.provision 'selinux-status', type: 'shell', run: 'once', inline: 'sestatus'
Expand Down
8 changes: 8 additions & 0 deletions tests/install/rocky-9/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ Vagrant.configure("2") do |config|
checkK3sProcesses(test.vm)

checkCGroupV2(test.vm)

mountDirs(test.vm)

runUninstall(test.vm)

checkMountPoint(test.vm)

unmountDir(test.vm)
end

config.vm.provision 'selinux-status', type: 'shell', run: 'once', inline: 'sestatus'
Expand Down
9 changes: 9 additions & 0 deletions tests/install/ubuntu-2204/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ Vagrant.configure("2") do |config|

checkCGroupV2(test.vm)

mountDirs(test.vm)

checkMountPoint(test.vm)

runUninstall(test.vm)

checkMountPoint(test.vm)

unmountDir(test.vm)
end

%w[libvirt virtualbox vmware_desktop].each do |p|
Expand Down

0 comments on commit 3aceb85

Please sign in to comment.