Skip to content

Commit

Permalink
Only clean the server and agent directory if it is uninstall
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Savian <[email protected]>
  • Loading branch information
vitorsavian committed Jul 10, 2024
1 parent 90761e0 commit 872c6f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 20 additions & 18 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -833,27 +833,10 @@ do_unmount_and_remove() {
set -x
}
clean_mounted_directory() {
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
}
do_unmount_and_remove '/run/k3s'
do_unmount_and_remove '/var/lib/rancher/k3s/data'
do_unmount_and_remove '/var/lib/rancher/k3s/storage'
do_unmount_and_remove '/var/lib/kubelet/pods'
do_unmount_and_remove '/var/lib/kubelet/plugins'
do_unmount_and_remove '/run/netns/cni-'
clean_mounted_directory '/var/lib/rancher/k3s'
# Remove CNI namespaces
ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete
Expand Down Expand Up @@ -907,10 +890,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 /var/lib/rancher/k3s
clean_mounted_directory /var/lib/rancher/k3s
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 @@
2ddff0688ce2cc7b85b2fa1475c5fc638c6b985c65640f2271d61e9a43b9248f install.sh
4b2436ec6c45a428aa871caa9b5e480484e9551f057273b95cda6ef434d41dc0 install.sh

0 comments on commit 872c6f6

Please sign in to comment.