sigs.k8s.io/cluster-api-provider-aws@v1.5.5/scripts/ci-e2e-gc.sh (about) 1 #!/bin/bash 2 3 # Copyright 2022 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 ################################################################################ 18 # usage: e2e.sh 19 # This program runs the e2e tests. 20 # 21 # ENVIRONMENT VARIABLES 22 # JANITOR_ENABLED 23 # Set to 1 to run the aws-janitor command after running the e2e tests. 24 ################################################################################ 25 26 set -o nounset 27 set -o pipefail 28 29 REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. 30 cd "${REPO_ROOT}" || exit 1 31 32 # shellcheck source=../hack/ensure-go.sh 33 source "${REPO_ROOT}/hack/ensure-go.sh" 34 # shellcheck source=../hack/ensure-kind.sh 35 source "${REPO_ROOT}/hack/ensure-kind.sh" 36 # shellcheck source=../hack/ensure-kubectl.sh 37 source "${REPO_ROOT}/hack/ensure-kubectl.sh" 38 39 ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}" 40 mkdir -p "$ARTIFACTS/logs/" 41 42 # our exit handler (trap) 43 cleanup() { 44 # stop boskos heartbeat 45 [[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}" 46 } 47 trap cleanup EXIT 48 49 #Install requests module explicitly for HTTP calls 50 python3 -m pip install requests 51 52 # If BOSKOS_HOST is set then acquire an AWS account from Boskos. 53 if [ -n "${BOSKOS_HOST:-}" ]; then 54 # Check out the account from Boskos and store the produced environment 55 # variables in a temporary file. 56 account_env_var_file="$(mktemp)" 57 python3 hack/boskos.py --get 1>"${account_env_var_file}" 58 checkout_account_status="${?}" 59 60 # If the checkout process was a success then load the account's 61 # environment variables into this process. 62 # shellcheck disable=SC1090 63 [ "${checkout_account_status}" = "0" ] && . "${account_env_var_file}" 64 65 # Always remove the account environment variable file. It contains 66 # sensitive information. 67 rm -f "${account_env_var_file}" 68 69 if [ ! "${checkout_account_status}" = "0" ]; then 70 echo "error getting account from boskos" 1>&2 71 exit "${checkout_account_status}" 72 fi 73 74 # run the heart beat process to tell boskos that we are still 75 # using the checked out account periodically 76 python3 -u hack/boskos.py --heartbeat >>$ARTIFACTS/logs/boskos.log 2>&1 & 77 HEART_BEAT_PID=$(echo $!) 78 fi 79 80 # Prevent a disallowed AWS key from being used. 81 if grep -iqF "$(echo "${AWS_ACCESS_KEY_ID-}" | 82 { md5sum 2>/dev/null || md5; } | 83 awk '{print $1}')" hack/e2e-aws-disallowed.txt; then 84 echo "The provided AWS key is not allowed" 1>&2 85 exit 1 86 fi 87 88 EXP_EXTERNAL_RESOURCE_GC="true" GC_WORKLOAD="../../data/gcworkload.yaml" make test-e2e-gc ARTIFACTS=$ARTIFACTS 89 90 test_status="${?}" 91 92 # If Boskos is being used then release the AWS account back to Boskos. 93 [ -z "${BOSKOS_HOST:-}" ] || python3 -u hack/boskos.py --release 94 95 # The janitor is typically not run as part of the e2e process, but rather 96 # in a parallel process via a service on the same cluster that runs Prow and 97 # Boskos. 98 # 99 # However, setting JANITOR_ENABLED=1 tells this program to run the janitor 100 # after the e2e test is executed. 101 if [ "${JANITOR_ENABLED:-0}" = "1" ]; then 102 if ! command -v aws-janitor >/dev/null 2>&1; then 103 echo "skipping janitor; aws-janitor not found" 1>&2 104 else 105 aws-janitor -all -v 2 106 fi 107 else 108 echo "skipping janitor; JANITOR_ENABLED=${JANITOR_ENABLED:-0}" 1>&2 109 fi 110 111 exit "${test_status}"