k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/make-rules/test-integration.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2014 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 nounset
    19  set -o pipefail
    20  
    21  KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
    22  source "${KUBE_ROOT}/hack/lib/init.sh"
    23  
    24  # start the cache mutation detector by default so that cache mutators will be found
    25  KUBE_CACHE_MUTATION_DETECTOR="${KUBE_CACHE_MUTATION_DETECTOR:-true}"
    26  export KUBE_CACHE_MUTATION_DETECTOR
    27  
    28  # panic the server on watch decode errors since they are considered coder mistakes
    29  KUBE_PANIC_WATCH_DECODE_ERROR="${KUBE_PANIC_WATCH_DECODE_ERROR:-true}"
    30  export KUBE_PANIC_WATCH_DECODE_ERROR
    31  
    32  KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"}
    33  if [[ ${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY} -gt 0 ]]; then
    34    GOMAXPROCS=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY}
    35    export GOMAXPROCS
    36    kube::log::status "Setting parallelism to ${GOMAXPROCS}"
    37  fi
    38  
    39  # Give integration tests longer to run by default.
    40  KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout=600s}
    41  LOG_LEVEL=${LOG_LEVEL:-2}
    42  KUBE_TEST_ARGS=${KUBE_TEST_ARGS:-}
    43  # Default glog module settings.
    44  KUBE_TEST_VMODULE=${KUBE_TEST_VMODULE:-""}
    45  
    46  kube::test::find_integration_test_dirs() {
    47    (
    48      cd "${KUBE_ROOT}"
    49      # The "./" syntax here produces Go-compatible package names.
    50      find ./test/integration/ -name '*_test.go' -print0 \
    51        | xargs -0n1 dirname \
    52        | LC_ALL=C sort -u
    53      find ./staging/src/k8s.io/apiextensions-apiserver/test/integration/ -name '*_test.go' -print0 \
    54        | xargs -0n1 dirname \
    55        | LC_ALL=C sort -u
    56    )
    57  }
    58  
    59  CLEANUP_REQUIRED=
    60  cleanup() {
    61    if [[ -z "${CLEANUP_REQUIRED}" ]]; then
    62      return
    63    fi
    64    kube::log::status "Cleaning up etcd"
    65    kube::etcd::cleanup
    66    CLEANUP_REQUIRED=
    67    kube::log::status "Integration test cleanup complete"
    68  }
    69  
    70  runTests() {
    71    kube::log::status "Starting etcd instance"
    72    CLEANUP_REQUIRED=1
    73    kube::etcd::start
    74    # shellcheck disable=SC2034
    75    local ETCD_SCRAPE_PID # Set in kube::etcd::start_scraping, used in cleanup
    76    kube::etcd::start_scraping
    77    kube::log::status "Running integration test cases"
    78  
    79    # shellcheck disable=SC2034
    80    # KUBE_RACE and MAKEFLAGS are used in the downstream make, and we set them to
    81    # empty here to ensure that we aren't unintentionally consuming them from the
    82    # previous make invocation.
    83    KUBE_TEST_ARGS="${SHORT:--short=true} --vmodule=${KUBE_TEST_VMODULE} ${KUBE_TEST_ARGS}" \
    84        WHAT="${WHAT:-$(kube::test::find_integration_test_dirs | paste -sd' ' -)}" \
    85        GOFLAGS="${GOFLAGS:-}" \
    86        KUBE_TIMEOUT="${KUBE_TIMEOUT}" \
    87        KUBE_RACE="" \
    88        MAKEFLAGS="" \
    89        make -C "${KUBE_ROOT}" test
    90  
    91    cleanup
    92  }
    93  
    94  checkEtcdOnPath() {
    95    kube::log::status "Checking etcd is on PATH"
    96    which etcd && return
    97    kube::log::status "Cannot find etcd, cannot run integration tests."
    98    kube::log::status "Please see https://git.k8s.io/community/contributors/devel/sig-testing/integration-tests.md#install-etcd-dependency for instructions."
    99    kube::log::usage "You can use 'hack/install-etcd.sh' to install a copy in third_party/."
   100    return 1
   101  }
   102  
   103  checkEtcdOnPath
   104  
   105  # Run cleanup to stop etcd on interrupt or other kill signal.
   106  trap cleanup EXIT
   107  
   108  runTests