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 "
2024-09-24 15:02:54 -04:00
kube::golang::setup_env
kube::util::require-jq
2025-08-18 08:33:57 -04:00
set -x
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
2025-08-13 07:27:30 -04:00
# default set to "false" to avoid panic on decode errors.
# integration tests intentionally insert data that cannot be decoded.
KUBE_PANIC_WATCH_DECODE_ERROR = " ${ KUBE_PANIC_WATCH_DECODE_ERROR :- false } "
2019-11-15 10:38:18 -05:00
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
2025-08-18 08:33:57 -04:00
set +x
2024-09-24 15:02:54 -04:00
kube::test::find_integration_test_pkgs( ) {
2016-05-24 11:40:44 -04:00
(
2019-04-11 13:47:34 -04:00
cd " ${ KUBE_ROOT } "
2024-09-24 15:02:54 -04:00
# Get a list of all the modules in this workspace.
local -a workspace_module_patterns
kube::util::read-array workspace_module_patterns < <(
go list -m -json | jq -r '.Dir' \
| while read -r D; do
SUB = " ${ D } /test/integration " ;
test -d " ${ SUB } " && echo " ${ SUB } /... " ;
done )
# Get a list of all packages which have test files.
go list -find \
-f '{{if or (gt (len .TestGoFiles) 0) (gt (len .XTestGoFiles) 0)}}{{.ImportPath}}{{end}}' \
" ${ workspace_module_patterns [@] } "
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 } " \
2024-09-24 15:02:54 -04:00
WHAT = " ${ WHAT :- $( kube::test::find_integration_test_pkgs | paste -sd' ' -) } " \
2017-06-03 22:07:59 -04:00
GOFLAGS = " ${ GOFLAGS :- } " \
2024-02-26 18:46:38 -05:00
KUBE_TIMEOUT = " ${ KUBE_TIMEOUT } " \
2025-06-02 05:47:42 -04:00
KUBE_RACE = ${ KUBE_RACE :- "" } \
2024-02-26 12:01:04 -05:00
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