2018-04-16 12:31:44 -04:00
#!/usr/bin/env bash
2016-05-24 11:40:44 -04:00
# Copyright 2014 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
2019-04-11 13:47:34 -04:00
KUBE_ROOT = $( dirname " ${ BASH_SOURCE [0] } " ) /../..
2016-05-24 11:40:44 -04:00
source " ${ KUBE_ROOT } /hack/lib/init.sh "
2019-11-15 10:38:18 -05:00
# start the cache mutation detector by default so that cache mutators will be found
KUBE_CACHE_MUTATION_DETECTOR = " ${ KUBE_CACHE_MUTATION_DETECTOR :- true } "
export KUBE_CACHE_MUTATION_DETECTOR
# panic the server on watch decode errors since they are considered coder mistakes
KUBE_PANIC_WATCH_DECODE_ERROR = " ${ KUBE_PANIC_WATCH_DECODE_ERROR :- true } "
export KUBE_PANIC_WATCH_DECODE_ERROR
2022-04-01 11:39:42 -04:00
KUBE_INTEGRATION_TEST_MAX_CONCURRENCY = ${ KUBE_INTEGRATION_TEST_MAX_CONCURRENCY :- "-1" }
if [ [ ${ KUBE_INTEGRATION_TEST_MAX_CONCURRENCY } -gt 0 ] ] ; then
GOMAXPROCS = ${ KUBE_INTEGRATION_TEST_MAX_CONCURRENCY }
export GOMAXPROCS
kube::log::status " Setting parallelism to ${ GOMAXPROCS } "
fi
2017-12-21 12:42:54 -05:00
# Give integration tests longer to run by default.
2019-05-09 04:47:12 -04:00
KUBE_TIMEOUT = ${ KUBE_TIMEOUT :- -timeout=600s }
2016-05-24 11:40:44 -04:00
LOG_LEVEL = ${ LOG_LEVEL :- 2 }
KUBE_TEST_ARGS = ${ KUBE_TEST_ARGS :- }
2017-07-31 14:06:46 -04:00
# Default glog module settings.
2023-05-23 15:13:39 -04:00
KUBE_TEST_VMODULE = ${ KUBE_TEST_VMODULE :- "" }
2016-05-24 11:40:44 -04:00
kube::test::find_integration_test_dirs( ) {
(
2019-04-11 13:47:34 -04:00
cd " ${ KUBE_ROOT } "
2017-02-16 13:53:58 -05:00
find test/integration/ -name '*_test.go' -print0 \
2017-01-04 11:20:01 -05:00
| xargs -0n1 dirname | sed " s|^| ${ KUBE_GO_PACKAGE } /| " \
2016-10-19 11:03:12 -04:00
| LC_ALL = C sort -u
2017-06-01 08:12:43 -04:00
find vendor/k8s.io/apiextensions-apiserver/test/integration/ -name '*_test.go' -print0 \
2017-05-01 15:49:03 -04:00
| xargs -0n1 dirname | sed " s|^| ${ KUBE_GO_PACKAGE } /| " \
| LC_ALL = C sort -u
2016-05-24 11:40:44 -04:00
)
}
2017-02-15 18:21:24 -05:00
CLEANUP_REQUIRED =
2016-05-24 11:40:44 -04:00
cleanup( ) {
2017-02-15 18:21:24 -05:00
if [ [ -z " ${ CLEANUP_REQUIRED } " ] ] ; then
return
fi
2016-05-24 11:40:44 -04:00
kube::log::status "Cleaning up etcd"
kube::etcd::cleanup
2017-02-15 18:21:24 -05:00
CLEANUP_REQUIRED =
2016-05-24 11:40:44 -04:00
kube::log::status "Integration test cleanup complete"
}
runTests( ) {
kube::log::status "Starting etcd instance"
2017-02-15 18:21:24 -05:00
CLEANUP_REQUIRED = 1
2016-05-24 11:40:44 -04:00
kube::etcd::start
2021-11-05 15:58:48 -04:00
# shellcheck disable=SC2034
local ETCD_SCRAPE_PID # Set in kube::etcd::start_scraping, used in cleanup
kube::etcd::start_scraping
2016-05-24 11:40:44 -04:00
kube::log::status "Running integration test cases"
2024-02-26 12:01:04 -05:00
# shellcheck disable=SC2034
# KUBE_RACE and MAKEFLAGS are used in the downstream make, and we set them to
# empty here to ensure that we aren't unintentionally consuming them from the
# previous make invocation.
KUBE_TEST_ARGS = " ${ SHORT :- -short=true } --vmodule= ${ KUBE_TEST_VMODULE } ${ KUBE_TEST_ARGS } " \
2017-02-16 13:53:58 -05:00
WHAT = " ${ WHAT :- $( kube::test::find_integration_test_dirs | paste -sd' ' -) } " \
2017-06-03 22:07:59 -04:00
GOFLAGS = " ${ GOFLAGS :- } " \
2024-02-26 18:46:38 -05:00
KUBE_TIMEOUT = " ${ KUBE_TIMEOUT } " \
2024-02-26 12:01:04 -05:00
KUBE_RACE = "" \
MAKEFLAGS = "" \
make -C " ${ KUBE_ROOT } " test
2016-05-24 11:40:44 -04:00
cleanup
}
checkEtcdOnPath( ) {
kube::log::status "Checking etcd is on PATH"
which etcd && return
kube::log::status "Cannot find etcd, cannot run integration tests."
2019-03-26 13:31:59 -04:00
kube::log::status "Please see https://git.k8s.io/community/contributors/devel/sig-testing/integration-tests.md#install-etcd-dependency for instructions."
2017-05-12 03:55:09 -04:00
kube::log::usage "You can use 'hack/install-etcd.sh' to install a copy in third_party/."
2016-05-24 11:40:44 -04:00
return 1
}
checkEtcdOnPath
# Run cleanup to stop etcd on interrupt or other kill signal.
trap cleanup EXIT
2019-06-26 11:55:50 -04:00
runTests