github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/kubernetes/e2e_conformance/run.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2019 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 # This script runs the Sonobuoy e2e Conformance tests. 8 # Run this script once your K8s cluster is running. 9 # WARNING: it is prefered to use containerd as the 10 # runtime interface instead of cri-o as we have seen 11 # errors with cri-o that still need to be debugged. 12 13 set -o errexit 14 set -o nounset 15 set -o pipefail 16 17 DEBUG=${DEBUG:-} 18 [ -n "$DEBUG" ] && set -o xtrace 19 20 export KUBECONFIG=$HOME/.kube/config 21 SCRIPT_PATH=$(dirname "$(readlink -f "$0")") 22 source "${SCRIPT_PATH}/../../../lib/common.bash" 23 source "${SCRIPT_PATH}/../../../.ci/lib.sh" 24 25 CI=${CI:-false} 26 RUNTIME="${RUNTIME:-containerd-shim-kata-v2}" 27 CRI_RUNTIME="${CRI_RUNTIME:-containerd}" 28 MINIMAL_K8S_E2E="${MINIMAL_K8S_E2E:-false}" 29 KATA_HYPERVISOR="${KATA_HYPERVISOR:-}" 30 31 # Overall Sonobuoy timeout in minutes. 32 WAIT_TIME=${WAIT_TIME:-180} 33 34 JOBS_FILE="${SCRIPT_PATH}/e2e_k8s_jobs.yaml" 35 36 create_kata_webhook() { 37 pushd "${SCRIPT_PATH}/../../../kata-webhook" >> /dev/null 38 # Create certificates for the kata webhook 39 ./create-certs.sh 40 41 # Apply kata-webhook deployment 42 kubectl apply -f deploy/ 43 popd 44 } 45 46 get_sonobuoy() { 47 sonobuoy_repo=$(get_test_version "externals.sonobuoy.url") 48 version=$(get_test_version "externals.sonobuoy.version") 49 arch="$(${SCRIPT_PATH}/../../../.ci/kata-arch.sh --golang)" 50 sonobuoy_tar="sonobuoy_${version}_linux_${arch}.tar.gz" 51 install_path="/usr/bin" 52 53 curl -LO "${sonobuoy_repo}/releases/download/v${version}/${sonobuoy_tar}" 54 sudo tar -xzf "${sonobuoy_tar}" -C "$install_path" 55 sudo chmod +x "${install_path}/sonobuoy" 56 rm -f "${sonobuoy_tar}" 57 } 58 59 # Input: 60 # - yaml list key 61 # - yaml file 62 # Output 63 # - string: | separated values of the list 64 yaml_list_to_str_regex() { 65 local list="${1}" 66 local yaml_file=${2:-"|"} 67 local query=".${list}" 68 query+=' | join("|")?' 69 "${GOPATH}/bin/yq" -j read "${yaml_file}" | jq -r "${query}" 70 } 71 72 run_sonobuoy() { 73 # Run Sonobuoy e2e tests 74 info "Starting sonobuoy execution." 75 info "When using kata as k8s runtime, the tests take around 2 hours to finish." 76 77 local skipped_tests_file="${SCRIPT_PATH}/skipped_tests_e2e.yaml" 78 local skipped_tests=$("${GOPATH}/bin/yq" read "${skipped_tests_file}" "${CRI_RUNTIME}") 79 80 # Default skipped tests for Conformance testing: 81 skip_options="Alpha|\[(Disruptive|Feature:[^\]]+|Flaky)\]" 82 local skip_list 83 skip_list=$(yaml_list_to_str_regex "\"${CRI_RUNTIME}\"" "${skipped_tests_file}") 84 if [ "${skip_list}" != "" ];then 85 skip_options+="|${skip_list}" 86 fi 87 88 skip_list=$(yaml_list_to_str_regex "hypervisor.\"${KATA_HYPERVISOR}\"" "${skipped_tests_file}") 89 if [ "${skip_list}" != "" ];then 90 skip_options+="|${skip_list}" 91 fi 92 93 local cmd="sonobuoy" 94 cmd+=" run" 95 cmd+=" --wait=${WAIT_TIME}" 96 97 if [ "${MINIMAL_K8S_E2E}" == "true" ]; then 98 minimal_focus=$(yaml_list_to_str_regex "jobs.minimal.focus" "${JOBS_FILE}") 99 # Not required to skip as only what is defined in toml should be executed. 100 if [ "${minimal_focus}" != "" ]; then 101 cmd+=" --e2e-focus=\"${minimal_focus}\"" 102 else 103 # For MINIMAL_K8S_E2E focus list should not be empty 104 die "minimal focus query returned empty list" 105 fi 106 else 107 if [ "${skip_options}" != "" ]; then 108 cmd+=" --e2e-skip=\"${skip_options}\"" 109 fi 110 fi 111 echo "running: ${cmd}" 112 eval "${cmd}" 113 114 e2e_result_dir="$(mktemp -d /tmp/kata_e2e_results.XXXXX)" 115 { 116 sonobuoy status --json 117 if ! results=$(sonobuoy retrieve "${e2e_result_dir}"); then 118 die "failed to retrieve results" 119 fi 120 121 sonobuoy results "${results}" --mode=dump 122 123 pushd "${e2e_result_dir}" 124 tar -xvf "${results}" 125 e2e_result_log=$(find "${e2e_result_dir}/plugins/e2e" -name "e2e.log") 126 info "Results of the e2e tests can be found on: $e2e_result_log" 127 popd 128 129 failed_query='.plugins | .[] | select( ."result-status" | contains("failed"))' 130 failed=$(sonobuoy status --json | jq "${failed_query}") 131 if [ "${failed}" != "" ]; then 132 if [ "$CI" == true ]; then 133 cat "$e2e_result_log" 134 fi 135 sonobuoy status --json | jq "${failed_query}" 136 die "Found failed tests in end-to-end k8s test" 137 fi 138 local expected_passed_query="jobs.${CI_JOB:-}.passed" 139 local expected_passed=$("${GOPATH}/bin/yq" read "${JOBS_FILE}" "${expected_passed_query}") 140 if [ "${expected_passed}" != "" ];then 141 passed_query='.plugins | [ .[]."result-counts".passed] | add' 142 passed=$(sonobuoy status --json | jq "${passed_query}") 143 if [ "${expected_passed}" != "${passed}" ];then 144 die "expected ${expected_passed} tests to pass, but ${passed} passed" 145 else 146 info "All ${passed} tests passed as expected" 147 fi 148 else 149 info "Not found ${expected_passed_query} for job ${CI_JOB:-} in ${JOBS_FILE}" 150 fi 151 } | tee "${e2e_result_dir}/summary" 152 } 153 154 cleanup() { 155 if [ -d "${e2e_result_dir:-}" ]; then 156 info "Results directory "${e2e_result_dir}" will not be deleted" 157 log_file="${e2e_result_dir}/plugins/e2e/results/global/e2e.log" 158 if [ -f "${log_file}" ]; then 159 info "View results" 160 cat ${log_file} 161 else 162 warn "Tests results file ${log_file} not found" 163 fi 164 fi 165 { 166 info "View sonobuoy status" 167 sonobuoy status 168 # Remove sonobuoy execution pods 169 sonobuoy delete 170 } || true 171 } 172 173 trap "{ cleanup; }" EXIT 174 175 main() { 176 if [ "$RUNTIME" == "containerd-shim-kata-v2" ]; then 177 create_kata_webhook 178 fi 179 180 get_sonobuoy 181 run_sonobuoy 182 } 183 184 main