github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/cleanup_env.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2018 Intel Corporation
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  # This script is used to reset the kubernetes cluster
     8  
     9  SCRIPT_PATH=$(dirname "$(readlink -f "$0")")
    10  source "${SCRIPT_PATH}/../../.ci/lib.sh"
    11  source "${SCRIPT_PATH}/../../lib/common.bash"
    12  
    13  BAREMETAL="${BAREMETAL:-false}"
    14  CRI_RUNTIME="${CRI_RUNTIME:-crio}"
    15  
    16  main () {
    17  	local cri_runtime_socket=""
    18  	local keep_cni_bin="${1:-false}"
    19  
    20  	case "${CRI_RUNTIME}" in
    21  	containerd)
    22  		cri_runtime_socket="unix:///run/containerd/containerd.sock"
    23  		;;
    24  	crio)
    25  		cri_runtime_socket="unix:///var/run/crio/crio.sock"
    26  		;;
    27  	*)
    28  		die "Runtime ${CRI_RUNTIME} not supported"
    29  		;;
    30  	esac
    31  
    32  	info "Reset Kubernetes"
    33  	export KUBECONFIG="$HOME/.kube/config"
    34  	sudo -E kubeadm reset -f --cri-socket="${cri_runtime_socket}"
    35  
    36  	info "Teardown the registry server"
    37  	[ "${container_engine}" == "docker" ] && restart_docker_service
    38  	registry_server_teardown
    39  
    40  	info "Stop ${CRI_RUNTIME} service"
    41  	sudo systemctl stop "${CRI_RUNTIME}"
    42  
    43  	info "Remove network devices"
    44  	for dev in cni0 flannel.1; do
    45  		info "remove device: $dev"
    46  		sudo ip link set dev "$dev" down || true
    47  		sudo ip link del "$dev" || true
    48  	done
    49  
    50  	# if CI run in bare-metal, we need a set of extra clean
    51  	if [ "${BAREMETAL}" == true ] && [ -f "${SCRIPT_PATH}/cleanup_bare_metal_env.sh" ]; then
    52  		bash -f "${SCRIPT_PATH}/cleanup_bare_metal_env.sh ${keep_cni_bin}"
    53  	fi
    54  
    55  	info "Check no kata processes are left behind after reseting kubernetes"
    56  	check_processes
    57  
    58  	info "Checks that pods were not left"
    59  	check_pods
    60  }
    61  
    62  main $@