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

     1  #!/bin/bash
     2  
     3  # Copyright 2018 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  set -o errexit
    18  set -o pipefail
    19  
    20  
    21  REPO_ROOT=$(git rev-parse --show-toplevel)
    22  cd "${REPO_ROOT}" || exit 1
    23  
    24  # shellcheck source=./scripts/ci-e2e-lib.sh
    25  source "${REPO_ROOT}/scripts/ci-e2e-lib.sh"
    26  
    27  # shellcheck source=./hack/ensure-go.sh
    28  source "${REPO_ROOT}/hack/ensure-go.sh"
    29  # shellcheck source=./hack/ensure-kubectl.sh
    30  source "${REPO_ROOT}/hack/ensure-kubectl.sh"
    31  # shellcheck source=./hack/ensure-kind.sh
    32  source "${REPO_ROOT}/hack/ensure-kind.sh"
    33  
    34  # Make sure the tools binaries are on the path.
    35  export PATH="${REPO_ROOT}/hack/tools/bin:${PATH}"
    36  
    37  # Builds CAPI (and CAPD) images.
    38  capi:buildDockerImages
    39  
    40  # Configure e2e tests
    41  export GINKGO_NODES=3
    42  export GINKGO_NOCOLOR=true
    43  export GINKGO_ARGS="${GINKGO_ARGS:-""}"
    44  export E2E_CONF_FILE="${REPO_ROOT}/test/e2e/config/docker.yaml"
    45  export ARTIFACTS="${ARTIFACTS:-${REPO_ROOT}/_artifacts}"
    46  export SKIP_RESOURCE_CLEANUP=${SKIP_RESOURCE_CLEANUP:-"false"}
    47  export USE_EXISTING_CLUSTER=false
    48  
    49  # Prepare kindest/node images for all the required Kubernetes version; this implies
    50  # 1. Kubernetes version labels (e.g. latest) to the corresponding version numbers.
    51  # 2. Pre-pulling the corresponding kindest/node image if available; if not, building the image locally.
    52  # Following variables are currently checked (if defined):
    53  # - KUBERNETES_VERSION
    54  # - KUBERNETES_VERSION_UPGRADE_TO
    55  # - KUBERNETES_VERSION_UPGRADE_FROM
    56  # - KUBERNETES_VERSION_LATEST_CI
    57  k8s::prepareKindestImagesVariables
    58  k8s::prepareKindestImages
    59  
    60  # pre-pull all the images that will be used in the e2e, thus making the actual test run
    61  # less sensible to the network speed. This includes:
    62  # - cert-manager images
    63  kind:prepullAdditionalImages
    64  
    65  # Setup local output directory
    66  ARTIFACTS_LOCAL="${ARTIFACTS}/localhost"
    67  mkdir -p "${ARTIFACTS_LOCAL}"
    68  echo "This folder contains logs from the local host where the tests ran." > "${ARTIFACTS_LOCAL}/README.md"
    69  
    70  # Configure the containerd socket, otherwise 'ctr' would not work
    71  export CONTAINERD_ADDRESS=/var/run/docker/containerd/containerd.sock
    72  
    73  # ensure we retrieve additional info for debugging when we leave the script
    74  cleanup() {
    75    # shellcheck disable=SC2046
    76    kill $(pgrep -f 'docker events') || true
    77    # shellcheck disable=SC2046
    78    kill $(pgrep -f 'ctr -n moby events') || true
    79  
    80    cp /var/log/docker.log "${ARTIFACTS_LOCAL}/docker.log" || true
    81    docker ps -a > "${ARTIFACTS_LOCAL}/docker-ps.txt" || true
    82    docker images > "${ARTIFACTS_LOCAL}/docker-images.txt" || true
    83    docker info > "${ARTIFACTS_LOCAL}/docker-info.txt" || true
    84    docker system df > "${ARTIFACTS_LOCAL}/docker-system-df.txt" || true
    85    docker version > "${ARTIFACTS_LOCAL}/docker-version.txt" || true
    86  
    87    ctr namespaces list > "${ARTIFACTS_LOCAL}/containerd-namespaces.txt" || true
    88    ctr -n moby tasks list > "${ARTIFACTS_LOCAL}/containerd-tasks.txt" || true
    89    ctr -n moby containers list > "${ARTIFACTS_LOCAL}/containerd-containers.txt" || true
    90    ctr -n moby images list > "${ARTIFACTS_LOCAL}/containerd-images.txt" || true
    91    ctr -n moby version > "${ARTIFACTS_LOCAL}/containerd-version.txt" || true
    92  
    93    ps -ef > "${ARTIFACTS_LOCAL}/processes-ps-ef.txt" || true
    94  
    95    for PID in $(ps -eo pid=); do
    96      echo "> PID=$PID"
    97      echo ">> /proc/${PID}/status" 
    98      cat "/proc/${PID}/status" || true
    99      echo ">> /proc/${PID}/stack" 
   100      cat "/proc/${PID}/stack" || true
   101    done >> "${ARTIFACTS_LOCAL}/processes-proc-information.txt"
   102  
   103    # Verify that no containers are running at this time
   104    # Note: This verifies that all our tests clean up clusters correctly.
   105    if [[ ! "$(docker ps -q | wc -l)" -eq "0" ]]
   106    then
   107       echo "ERROR: Found unexpected running containers:"
   108       echo ""
   109       docker ps
   110       exit 1
   111    fi
   112  }
   113  trap "cleanup" EXIT SIGINT
   114  
   115  docker events > "${ARTIFACTS_LOCAL}/docker-events.txt" 2>&1 &
   116  ctr -n moby events > "${ARTIFACTS_LOCAL}/containerd-events.txt" 2>&1 &
   117  
   118  # Run e2e tests
   119  mkdir -p "$ARTIFACTS"
   120  echo "+ run tests!"
   121  make test-e2e