From d968e64de0f5bca758646ea42bff1b3aeed8955d Mon Sep 17 00:00:00 2001 From: Manuel Buil Date: Wed, 14 Jun 2023 11:56:42 +0200 Subject: [PATCH] Add commands to logout from tailscale Signed-off-by: Manuel Buil --- install.sh | 34 +++++++++++++++++++++++----------- package/rpm/install.sh | 34 +++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/install.sh b/install.sh index ae917becaba0..e96f474da2f2 100755 --- a/install.sh +++ b/install.sh @@ -739,6 +739,27 @@ killtree() { ) 2>/dev/null } +remove_interfaces() { + # Delete network interface(s) that match 'master cni0' + ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do + iface=${iface%%@*} + [ -z "$iface" ] || ip link delete $iface + done + + # Delete cni related interfaces + ip link delete cni0 + ip link delete flannel.1 + ip link delete flannel-v6.1 + ip link delete kube-ipvs0 + ip link delete flannel-wg + ip link delete flannel-wg-v6 + + # Restart tailscale + if [ -n "$(command -v tailscale)" ]; then + tailscale set --advertise-routes= + fi +} + getshims() { ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1 } @@ -762,17 +783,8 @@ do_unmount_and_remove '/run/netns/cni-' # Remove CNI namespaces ip netns show 2>/dev/null | grep cni- | xargs -r -t -n 1 ip netns delete -# Delete network interface(s) that match 'master cni0' -ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do - iface=${iface%%@*} - [ -z "$iface" ] || ip link delete $iface -done -ip link delete cni0 -ip link delete flannel.1 -ip link delete flannel-v6.1 -ip link delete kube-ipvs0 -ip link delete flannel-wg -ip link delete flannel-wg-v6 +remove_interfaces + rm -rf /var/lib/cni/ iptables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | iptables-restore ip6tables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | ip6tables-restore diff --git a/package/rpm/install.sh b/package/rpm/install.sh index 93b79a1abadf..f53b6c142ff0 100755 --- a/package/rpm/install.sh +++ b/package/rpm/install.sh @@ -543,6 +543,27 @@ killtree() { ) 2>/dev/null } +remove_interfaces() { + # Delete network interface(s) that match 'master cni0' + ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do + iface=${iface%%@*} + [ -z "$iface" ] || ip link delete $iface + done + + # Delete cni related interfaces + ip link delete cni0 + ip link delete flannel.1 + ip link delete flannel-v6.1 + ip link delete kube-ipvs0 + ip link delete flannel-wg + ip link delete flannel-wg-v6 + + # Remove advertised routes in tailscale + if [[ -n $(command -v tailscale) ]]; then + tailscale set --advertise-routes= + fi +} + getshims() { ps -e -o pid= -o args= | sed -e 's/^ *//; s/\s\s*/\t/;' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1 } @@ -558,17 +579,8 @@ do_unmount '/var/lib/rancher/k3s' do_unmount '/var/lib/kubelet/pods' do_unmount '/run/netns/cni-' -# Delete network interface(s) that match 'master cni0' -ip link show 2>/dev/null | grep 'master cni0' | while read ignore iface ignore; do - iface=${iface%%@*} - [ -z "$iface" ] || ip link delete $iface -done -ip link delete cni0 -ip link delete flannel.1 -ip link delete flannel-v6.1 -ip link delete flannel-wg -ip link delete flannel-wg-v6 -ip link delete kube-ipvs0 +remove_interfaces + rm -rf /var/lib/cni/ iptables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | iptables-restore ip6tables-save | grep -v KUBE- | grep -v CNI- | grep -iv flannel | ip6tables-restore