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 3, 2024
1 parent 50cb1c5 commit d09a327
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
36 changes: 20 additions & 16 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -829,27 +829,12 @@ 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 @@ -903,10 +888,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 @@
a2b1e04080530d80c0446df5d1504ce4e58ce3ff3c1f3347eeb6198575124851 install.sh
ed4fc439291dcd5de38085ce2ab13dfec5ca17662a3ab9d2925b478edb5a10cc install.sh

0 comments on commit d09a327

Please sign in to comment.