test-integration.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. # Lists of API Versions of each groups that should be tested, groups are
  21. # separated by comma, lists are separated by semicolon. e.g.,
  22. # "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3"
  23. # TODO: It's going to be:
  24. # KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1"}
  25. # FIXME: due to current implementation of a test client (see: pkg/api/testapi/testapi.go)
  26. # ONLY the last version is tested in each group.
  27. ALL_VERSIONS_CSV=$(IFS=',';echo "${KUBE_AVAILABLE_GROUP_VERSIONS[*]// /,}";IFS=$)
  28. KUBE_TEST_API_VERSIONS="${KUBE_TEST_API_VERSIONS:-${ALL_VERSIONS_CSV}}"
  29. # Give integration tests longer to run by default.
  30. KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 600s}
  31. KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"}
  32. LOG_LEVEL=${LOG_LEVEL:-2}
  33. KUBE_TEST_ARGS=${KUBE_TEST_ARGS:-}
  34. # Default glog module settings.
  35. KUBE_TEST_VMODULE=${KUBE_TEST_VMODULE:-"garbagecollector*=6,graph_builder*=6"}
  36. kube::test::find_integration_test_dirs() {
  37. (
  38. cd "${KUBE_ROOT}"
  39. find test/integration/ -name '*_test.go' -print0 \
  40. | xargs -0n1 dirname | sed "s|^|${KUBE_GO_PACKAGE}/|" \
  41. | LC_ALL=C sort -u
  42. find vendor/k8s.io/apiextensions-apiserver/test/integration/ -name '*_test.go' -print0 \
  43. | xargs -0n1 dirname | sed "s|^|${KUBE_GO_PACKAGE}/|" \
  44. | LC_ALL=C sort -u
  45. )
  46. }
  47. CLEANUP_REQUIRED=
  48. cleanup() {
  49. if [[ -z "${CLEANUP_REQUIRED}" ]]; then
  50. return
  51. fi
  52. kube::log::status "Cleaning up etcd"
  53. kube::etcd::cleanup
  54. CLEANUP_REQUIRED=
  55. kube::log::status "Integration test cleanup complete"
  56. }
  57. runTests() {
  58. kube::log::status "Starting etcd instance"
  59. CLEANUP_REQUIRED=1
  60. kube::etcd::start
  61. kube::log::status "Running integration test cases"
  62. # export KUBE_RACE
  63. #
  64. # Enable the Go race detector.
  65. export KUBE_RACE="-race"
  66. make -C "${KUBE_ROOT}" test \
  67. WHAT="${WHAT:-$(kube::test::find_integration_test_dirs | paste -sd' ' -)}" \
  68. GOFLAGS="${GOFLAGS:-}" \
  69. KUBE_TEST_ARGS="--alsologtostderr=true ${KUBE_TEST_ARGS:-} ${SHORT:--short=true} --vmodule=${KUBE_TEST_VMODULE}" \
  70. KUBE_RACE="" \
  71. KUBE_TIMEOUT="${KUBE_TIMEOUT}" \
  72. KUBE_TEST_API_VERSIONS="$1"
  73. cleanup
  74. }
  75. checkEtcdOnPath() {
  76. kube::log::status "Checking etcd is on PATH"
  77. which etcd && return
  78. kube::log::status "Cannot find etcd, cannot run integration tests."
  79. kube::log::status "Please see https://git.k8s.io/community/contributors/devel/sig-testing/integration-tests.md#install-etcd-dependency for instructions."
  80. kube::log::usage "You can use 'hack/install-etcd.sh' to install a copy in third_party/."
  81. return 1
  82. }
  83. checkEtcdOnPath
  84. # Run cleanup to stop etcd on interrupt or other kill signal.
  85. trap cleanup EXIT
  86. # Convert the CSV to an array of API versions to test
  87. IFS=';' read -ra apiVersions <<< "${KUBE_TEST_API_VERSIONS}"
  88. for apiVersion in "${apiVersions[@]}"; do
  89. runTests "${apiVersion}"
  90. done