From 3aceb85c22cc82ad2038898faebb04942e63ee87 Mon Sep 17 00:00:00 2001 From: Vitor Savian Date: Tue, 25 Jun 2024 12:05:28 -0300 Subject: [PATCH] Add a change for killall to not unmount server and agent directory Signed-off-by: Vitor Savian Add recursive search and deletion of unmounted/mounted dirs in killall Signed-off-by: Vitor Savian Only clean the server and agent directory if it is uninstall Signed-off-by: Vitor Savian Add uninstall test to check mount points Signed-off-by: Vitor Savian Add uninstall test in CI Signed-off-by: Vitor Savian --- .github/workflows/install.yaml | 10 +++++- install.sh | 22 ++++++++++-- install.sh.sha256sum | 2 +- tests/install/fedora/Vagrantfile | 9 +++++ tests/install/install_util.rb | 47 ++++++++++++++++++++++++- tests/install/opensuse-leap/Vagrantfile | 9 +++++ tests/install/rocky-8/Vagrantfile | 9 +++++ tests/install/rocky-9/Vagrantfile | 8 +++++ tests/install/ubuntu-2204/Vagrantfile | 9 +++++ 9 files changed, 120 insertions(+), 5 deletions(-) diff --git a/.github/workflows/install.yaml b/.github/workflows/install.yaml index 94a19cec247f..865cf14a905c 100644 --- a/.github/workflows/install.yaml +++ b/.github/workflows/install.yaml @@ -89,6 +89,14 @@ 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 @@ -96,4 +104,4 @@ jobs: if: ${{ failure() }} with: ## If no one connects after 5 minutes, shut down server. - wait-timeout-minutes: 5 \ No newline at end of file + wait-timeout-minutes: 5 diff --git a/install.sh b/install.sh index a1ed2c7b0eac..502c46196191 100755 --- a/install.sh +++ b/install.sh @@ -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-' @@ -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} diff --git a/install.sh.sha256sum b/install.sh.sha256sum index f3ddf5f71fd2..a9299f3af2c2 100644 --- a/install.sh.sha256sum +++ b/install.sh.sha256sum @@ -1 +1 @@ -937085bbac8e3b55209739762e05c2c1006c4f4fe65dba01908f3544dc47da27 install.sh +e10b36efb5e7e7692f144582d09f5909a91c5b5996965d643dbe13282befcfc1 install.sh diff --git a/tests/install/fedora/Vagrantfile b/tests/install/fedora/Vagrantfile index 09bf843dcfca..5c1c27b3cb9e 100644 --- a/tests/install/fedora/Vagrantfile +++ b/tests/install/fedora/Vagrantfile @@ -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' diff --git a/tests/install/install_util.rb b/tests/install/install_util.rb index c3012a609ec5..94766ee02c45 100644 --- a/tests/install/install_util.rb +++ b/tests/install/install_util.rb @@ -89,4 +89,49 @@ def checkCGroupV2(vm) k3s check-config | grep 'cgroups V2 mounted' SHELL end - end \ No newline at end of file + 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 diff --git a/tests/install/opensuse-leap/Vagrantfile b/tests/install/opensuse-leap/Vagrantfile index c37a9887c2a7..78c5b1f75f5a 100644 --- a/tests/install/opensuse-leap/Vagrantfile +++ b/tests/install/opensuse-leap/Vagrantfile @@ -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| diff --git a/tests/install/rocky-8/Vagrantfile b/tests/install/rocky-8/Vagrantfile index cc755ec89579..01ebf86026bb 100644 --- a/tests/install/rocky-8/Vagrantfile +++ b/tests/install/rocky-8/Vagrantfile @@ -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' diff --git a/tests/install/rocky-9/Vagrantfile b/tests/install/rocky-9/Vagrantfile index 9ec4bba82f0c..c4e9e8e32357 100644 --- a/tests/install/rocky-9/Vagrantfile +++ b/tests/install/rocky-9/Vagrantfile @@ -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' diff --git a/tests/install/ubuntu-2204/Vagrantfile b/tests/install/ubuntu-2204/Vagrantfile index 7b23ebeff657..48cef4ef36d5 100644 --- a/tests/install/ubuntu-2204/Vagrantfile +++ b/tests/install/ubuntu-2204/Vagrantfile @@ -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|