github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/run_kubernetes_tests.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2018 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 8 set -e 9 10 source /etc/os-release || source /usr/lib/os-release 11 kubernetes_dir=$(dirname "$(readlink -f "$0")") 12 cidir="${kubernetes_dir}/../../.ci/" 13 source "${cidir}/lib.sh" 14 15 arch="$(uname -m)" 16 17 KATA_HYPERVISOR="${KATA_HYPERVISOR:-qemu}" 18 K8S_TEST_DEBUG="${K8S_TEST_DEBUG:-false}" 19 20 if [ -n "${K8S_TEST_UNION:-}" ]; then 21 K8S_TEST_UNION=($K8S_TEST_UNION) 22 else 23 K8S_TEST_UNION=("k8s-attach-handlers.bats" \ 24 "k8s-block-volume.bats" \ 25 "k8s-caps.bats" \ 26 "k8s-configmap.bats" \ 27 "k8s-copy-file.bats" \ 28 "k8s-cpu-ns.bats" \ 29 "k8s-credentials-secrets.bats" \ 30 "k8s-custom-dns.bats" \ 31 "k8s-empty-dirs.bats" \ 32 "k8s-env.bats" \ 33 "k8s-exec.bats" \ 34 "k8s-expose-ip.bats" \ 35 "k8s-file-volume.bats" \ 36 "k8s-inotify.bats" \ 37 "k8s-job.bats" \ 38 "k8s-kill-all-process-in-container.bats" \ 39 "k8s-limit-range.bats" \ 40 "k8s-liveness-probes.bats" \ 41 "k8s-memory.bats" \ 42 "k8s-nested-configmap-secret.bats" \ 43 "k8s-number-cpus.bats" \ 44 "k8s-oom.bats" \ 45 "k8s-optional-empty-configmap.bats" \ 46 "k8s-optional-empty-secret.bats" \ 47 "k8s-parallel.bats" \ 48 "k8s-pid-ns.bats" \ 49 "k8s-pod-quota.bats" \ 50 "k8s-port-forward.bats" \ 51 "k8s-projected-volume.bats" \ 52 "k8s-qos-pods.bats" \ 53 "k8s-replication.bats" \ 54 "k8s-scale-nginx.bats" \ 55 "k8s-seccomp.bats" \ 56 "k8s-sysctls.bats" \ 57 "k8s-security-context.bats" \ 58 "k8s-shared-volume.bats" \ 59 "k8s-volume.bats" \ 60 "k8s-ro-volume.bats" \ 61 "k8s-nginx-connectivity.bats" \ 62 "k8s-hugepages.bats") 63 # TODO: runtime-rs doesn't support the following test cases, and will be fixed/improved in the future: 64 # k8s-block-volume.bats, k8s-cpu-ns.bats, k8s-hugepages.bats 65 if [ "$KATA_HYPERVISOR" == "dragonball" ]; then 66 K8S_TEST_UNION=("k8s-attach-handlers.bats" \ 67 "k8s-caps.bats" \ 68 "k8s-configmap.bats" \ 69 "k8s-copy-file.bats" \ 70 "k8s-credentials-secrets.bats" \ 71 "k8s-custom-dns.bats" \ 72 "k8s-empty-dirs.bats" \ 73 "k8s-env.bats" \ 74 "k8s-exec.bats" \ 75 "k8s-expose-ip.bats" \ 76 "k8s-file-volume.bats" \ 77 "k8s-footloose.bats" \ 78 "k8s-inotify.bats" \ 79 "k8s-job.bats" \ 80 "k8s-limit-range.bats" \ 81 "k8s-liveness-probes.bats" \ 82 "k8s-memory.bats" \ 83 "k8s-nested-configmap-secret.bats" \ 84 "k8s-number-cpus.bats" \ 85 "k8s-oom.bats" \ 86 "k8s-optional-empty-configmap.bats" \ 87 "k8s-optional-empty-secret.bats" \ 88 "k8s-parallel.bats" \ 89 "k8s-pod-quota.bats" \ 90 "k8s-port-forward.bats" \ 91 "k8s-projected-volume.bats" \ 92 "k8s-qos-pods.bats" \ 93 "k8s-replication.bats" \ 94 "k8s-scale-nginx.bats" \ 95 "k8s-seccomp.bats" \ 96 "k8s-sysctls.bats" \ 97 "k8s-security-context.bats" \ 98 "k8s-shared-volume.bats" \ 99 "k8s-volume.bats" \ 100 "k8s-nginx-connectivity.bats" \ 101 "k8s-ro-volume.bats" \ 102 "k8s-pid-ns.bats" \ 103 ) 104 fi 105 fi 106 107 cleanup() { 108 if [ ${K8S_TEST_DEBUG} == "true" ]; then 109 info "Running on debug mode so skip the cleanup routine" 110 info "You can access kubernetes with:\n\tkubectl <command>" 111 info "Run the cleanup routine when you are done debugging:\n\t${kubernetes_dir}/cleanup_env.sh" 112 return 113 fi 114 115 info "Run the cleanup routine" 116 ${kubernetes_dir}/cleanup_env.sh 117 } 118 119 # Using trap to ensure the cleanup occurs when the script exists. 120 trap_on_exit() { 121 trap 'cleanup' EXIT 122 } 123 124 # we may need to skip a few test cases when running on non-x86_64 arch 125 if [ -f "${cidir}/${arch}/configuration_${arch}.yaml" ]; then 126 config_file="${cidir}/${arch}/configuration_${arch}.yaml" 127 arch_k8s_test_union=$(${cidir}/filter/filter_k8s_test.sh ${config_file} "${K8S_TEST_UNION[*]}") 128 mapfile -d " " -t K8S_TEST_UNION <<< "${arch_k8s_test_union}" 129 fi 130 131 pushd "$kubernetes_dir" 132 info "Initialize the test environment" 133 wait_init_retry="30" 134 if ! bash ./init.sh; then 135 info "Environment initialization failed. Clean up and try again." 136 if ! bash ./cleanup_env.sh "true"; then 137 die "Failed on cleanup, it won't retry. Bailing out..." 138 else 139 # trap on exit should be added only if cleanup_env.sh returned 140 # success otherwise it will run twice (thus, fail twice). 141 trap_on_exit 142 fi 143 info "Wait ${wait_init_retry} seconds before retry" 144 sleep "${wait_init_retry}" 145 info "Retry to initialize the test environment..." 146 bash ./init.sh 147 fi 148 trap_on_exit 149 150 info "Run tests" 151 for K8S_TEST_ENTRY in ${K8S_TEST_UNION[@]} 152 do 153 bats "${K8S_TEST_ENTRY}" 154 done 155 popd