github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/kubernetes/cleanup_bare_metal_env.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2019 ARM Limited 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 7 set -o errexit 8 set -o nounset 9 set -o pipefail 10 11 SCRIPT_PATH=$(dirname "$(readlink -f "$0")") 12 source "${SCRIPT_PATH}/../../lib/common.bash" 13 14 iptables_cache="${KATA_TESTS_DATADIR}/iptables_cache" 15 16 # The kubeadm reset process does not reset or clean up iptables rules 17 # you must do it manually 18 # Here, we restore the iptables based on the previously cached file. 19 sudo iptables-restore < "$iptables_cache" 20 21 # The kubeadm reset process does not clean your kubeconfig files. 22 # you must remove them manually. 23 sudo -E rm -rf "$HOME/.kube" 24 25 # Remove existing CNI configurations and binaries. 26 sudo sh -c 'rm -rf /var/lib/cni' 27 sudo sh -c 'rm -rf /opt/cni/bin/*' 28 29 #cleanup stale file under /run 30 sudo sh -c 'rm -rf /run/flannel' 31 32 # delete containers resource created by runc 33 cri_runtime="${CRI_RUNTIME:-crio}" 34 case "${cri_runtime}" in 35 containerd) 36 readonly runc_path=$(command -v runc) 37 ;; 38 crio) 39 readonly runc_path="/usr/local/bin/crio-runc" 40 ;; 41 *) 42 echo "Runtime ${cri_runtime} not supported" 43 exit 0 44 ;; 45 esac 46 47 runc_container_union="$($runc_path list)" 48 if [ -n "$runc_container_union" ]; then 49 while IFS='$\n' read runc_container; do 50 container_id="$(echo "$runc_container" | awk '{print $1}')" 51 if [ "$container_id" != "ID" ]; then 52 $runc_path delete -f $container_id 53 fi 54 done <<< "${runc_container_union}" 55 fi 56 57 # when pipeline consists of grep, it may fail unnecessarily 58 # when no line selected. 59 veth_interfaces_union=$(set +o pipefail; sudo ip link | grep "veth" | awk '{print $2}' | cut -d '@' -f1) 60 61 # delete stale veth interfaces, which is named after vethXXX. 62 if [ -n "$veth_interfaces_union" ]; then 63 while read veth_interface; do 64 sudo ip link set dev $veth_interface down 65 sudo ip link del $veth_interface 66 done <<< "$veth_interfaces_union" 67 fi