sigs.k8s.io/cluster-api-provider-aws@v1.5.5/scripts/ci-e2e.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2019 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  
    40  ARTIFACTS="${ARTIFACTS:-${PWD}/_artifacts}"
    41  mkdir -p "$ARTIFACTS/logs/"
    42  
    43  # our exit handler (trap)
    44  cleanup() {
    45    # stop boskos heartbeat
    46    [[ -z ${HEART_BEAT_PID:-} ]] || kill -9 "${HEART_BEAT_PID}"
    47  }
    48  trap cleanup EXIT
    49  
    50  #Install requests module explicitly for HTTP calls
    51  python3 -m pip install requests
    52  
    53  # If BOSKOS_HOST is set then acquire an AWS account from Boskos.
    54  if [ -n "${BOSKOS_HOST:-}" ]; then
    55    # Check out the account from Boskos and store the produced environment
    56    # variables in a temporary file.
    57    account_env_var_file="$(mktemp)"
    58    python3 hack/boskos.py --get 1>"${account_env_var_file}"
    59    checkout_account_status="${?}"
    60  
    61    # If the checkout process was a success then load the account's
    62    # environment variables into this process.
    63    # shellcheck disable=SC1090
    64    [ "${checkout_account_status}" = "0" ] && . "${account_env_var_file}"
    65  
    66    # Always remove the account environment variable file. It contains
    67    # sensitive information.
    68    rm -f "${account_env_var_file}"
    69  
    70    if [ ! "${checkout_account_status}" = "0" ]; then
    71      echo "error getting account from boskos" 1>&2
    72      exit "${checkout_account_status}"
    73    fi
    74  
    75    # run the heart beat process to tell boskos that we are still
    76    # using the checked out account periodically
    77    python3 -u hack/boskos.py --heartbeat >>$ARTIFACTS/logs/boskos.log 2>&1 &
    78    HEART_BEAT_PID=$(echo $!)
    79  fi
    80  
    81  # Prevent a disallowed AWS key from being used.
    82  if grep -iqF "$(echo "${AWS_ACCESS_KEY_ID-}" |
    83    { md5sum 2>/dev/null || md5; } |
    84    awk '{print $1}')" hack/e2e-aws-disallowed.txt; then
    85    echo "The provided AWS key is not allowed" 1>&2
    86    exit 1
    87  fi
    88  
    89  make test-e2e ARTIFACTS=$ARTIFACTS
    90  
    91  test_status="${?}"
    92  
    93  # If Boskos is being used then release the AWS account back to Boskos.
    94  [ -z "${BOSKOS_HOST:-}" ] || python3 -u hack/boskos.py --release
    95  
    96  # The janitor is typically not run as part of the e2e process, but rather
    97  # in a parallel process via a service on the same cluster that runs Prow and
    98  # Boskos.
    99  #
   100  # However, setting JANITOR_ENABLED=1 tells this program to run the janitor
   101  # after the e2e test is executed.
   102  if [ "${JANITOR_ENABLED:-0}" = "1" ]; then
   103    if ! command -v aws-janitor >/dev/null 2>&1; then
   104      echo "skipping janitor; aws-janitor not found" 1>&2
   105    else
   106      aws-janitor -all -v 2
   107    fi
   108  else
   109    echo "skipping janitor; JANITOR_ENABLED=${JANITOR_ENABLED:-0}" 1>&2
   110  fi
   111  
   112  exit "${test_status}"