test-integration.sh 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env bash
  2. # Copyright 2014 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
  19. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. # start the cache mutation detector by default so that cache mutators will be found
  21. KUBE_CACHE_MUTATION_DETECTOR="${KUBE_CACHE_MUTATION_DETECTOR:-true}"
  22. export KUBE_CACHE_MUTATION_DETECTOR
  23. # panic the server on watch decode errors since they are considered coder mistakes
  24. KUBE_PANIC_WATCH_DECODE_ERROR="${KUBE_PANIC_WATCH_DECODE_ERROR:-true}"
  25. export KUBE_PANIC_WATCH_DECODE_ERROR
  26. # Give integration tests longer to run by default.
  27. KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout=600s}
  28. KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"}
  29. LOG_LEVEL=${LOG_LEVEL:-2}
  30. KUBE_TEST_ARGS=${KUBE_TEST_ARGS:-}
  31. # Default glog module settings.
  32. KUBE_TEST_VMODULE=${KUBE_TEST_VMODULE:-"garbagecollector*=6,graph_builder*=6"}
  33. kube::test::find_integration_test_dirs() {
  34. (
  35. cd "${KUBE_ROOT}"
  36. find test/integration/ -name '*_test.go' -print0 \
  37. | xargs -0n1 dirname | sed "s|^|${KUBE_GO_PACKAGE}/|" \
  38. | LC_ALL=C sort -u
  39. find vendor/k8s.io/apiextensions-apiserver/test/integration/ -name '*_test.go' -print0 \
  40. | xargs -0n1 dirname | sed "s|^|${KUBE_GO_PACKAGE}/|" \
  41. | LC_ALL=C sort -u
  42. )
  43. }
  44. CLEANUP_REQUIRED=
  45. cleanup() {
  46. if [[ -z "${CLEANUP_REQUIRED}" ]]; then
  47. return
  48. fi
  49. kube::log::status "Cleaning up etcd"
  50. kube::etcd::cleanup
  51. CLEANUP_REQUIRED=
  52. kube::log::status "Integration test cleanup complete"
  53. }
  54. runTests() {
  55. kube::log::status "Starting etcd instance"
  56. CLEANUP_REQUIRED=1
  57. kube::etcd::start
  58. kube::log::status "Running integration test cases"
  59. # export KUBE_RACE
  60. #
  61. # Enable the Go race detector.
  62. export KUBE_RACE="-race"
  63. make -C "${KUBE_ROOT}" test \
  64. WHAT="${WHAT:-$(kube::test::find_integration_test_dirs | paste -sd' ' -)}" \
  65. GOFLAGS="${GOFLAGS:-}" \
  66. KUBE_TEST_ARGS="--alsologtostderr=true ${KUBE_TEST_ARGS:-} ${SHORT:--short=true} --vmodule=${KUBE_TEST_VMODULE}" \
  67. KUBE_RACE="" \
  68. KUBE_TIMEOUT="${KUBE_TIMEOUT}"
  69. cleanup
  70. }
  71. checkEtcdOnPath() {
  72. kube::log::status "Checking etcd is on PATH"
  73. which etcd && return
  74. kube::log::status "Cannot find etcd, cannot run integration tests."
  75. kube::log::status "Please see https://git.k8s.io/community/contributors/devel/sig-testing/integration-tests.md#install-etcd-dependency for instructions."
  76. kube::log::usage "You can use 'hack/install-etcd.sh' to install a copy in third_party/."
  77. return 1
  78. }
  79. checkEtcdOnPath
  80. # Run cleanup to stop etcd on interrupt or other kill signal.
  81. trap cleanup EXIT
  82. runTests