test-integration.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/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}")/../..
  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. KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,authorization.k8s.io/v1beta1,autoscaling/v1,batch/v1,apps/v1alpha1,policy/v1alpha1,extensions/v1beta1,rbac.authorization.k8s.io/v1alpha1,certificates/v1alpha1"}
  28. # Give integration tests longer to run
  29. # TODO: allow a larger value to be passed in
  30. #KUBE_TIMEOUT=${KUBE_TIMEOUT:--timeout 240s}
  31. KUBE_TIMEOUT="-timeout 600s"
  32. KUBE_INTEGRATION_TEST_MAX_CONCURRENCY=${KUBE_INTEGRATION_TEST_MAX_CONCURRENCY:-"-1"}
  33. LOG_LEVEL=${LOG_LEVEL:-2}
  34. KUBE_TEST_ARGS=${KUBE_TEST_ARGS:-}
  35. kube::test::find_integration_test_dirs() {
  36. (
  37. cd ${KUBE_ROOT}
  38. find test/integration -name '*_test.go' -print0 \
  39. | xargs -0n1 dirname \
  40. | sort -u
  41. )
  42. }
  43. cleanup() {
  44. kube::log::status "Cleaning up etcd"
  45. kube::etcd::cleanup
  46. kube::log::status "Integration test cleanup complete"
  47. }
  48. runTests() {
  49. kube::log::status "Starting etcd instance"
  50. kube::etcd::start
  51. kube::log::status "Running integration test cases"
  52. # TODO: Re-enable race detection when we switch to a thread-safe etcd client
  53. # KUBE_RACE="-race"
  54. make -C "${KUBE_ROOT}" test \
  55. WHAT="$(kube::test::find_integration_test_dirs | paste -sd' ' -)" \
  56. KUBE_GOFLAGS="${KUBE_GOFLAGS:-} -tags 'integration no-docker'" \
  57. KUBE_TEST_ARGS="--vmodule=garbage*collector=6" \
  58. KUBE_RACE="" \
  59. KUBE_TIMEOUT="${KUBE_TIMEOUT}" \
  60. KUBE_TEST_API_VERSIONS="$1"
  61. cleanup
  62. }
  63. checkEtcdOnPath() {
  64. kube::log::status "Checking etcd is on PATH"
  65. which etcd && return
  66. kube::log::status "Cannot find etcd, cannot run integration tests."
  67. kube::log::status "Please see docs/devel/testing.md for instructions."
  68. return 1
  69. }
  70. checkEtcdOnPath
  71. # Run cleanup to stop etcd on interrupt or other kill signal.
  72. trap cleanup EXIT
  73. # If a test case is specified, just run once with v1 API version and exit
  74. if [[ -n "${KUBE_TEST_ARGS}" ]]; then
  75. runTests v1
  76. fi
  77. # Convert the CSV to an array of API versions to test
  78. IFS=';' read -a apiVersions <<< "${KUBE_TEST_API_VERSIONS}"
  79. for apiVersion in "${apiVersions[@]}"; do
  80. runTests "${apiVersion}"
  81. done