test-cmd.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. # This command checks that the built commands can function together for
  16. # simple scenarios. It does not require Docker.
  17. set -o errexit
  18. set -o nounset
  19. set -o pipefail
  20. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
  21. source "${KUBE_ROOT}/hack/lib/init.sh"
  22. source "${KUBE_ROOT}/hack/lib/test.sh"
  23. source "${KUBE_ROOT}/test/cmd/legacy-script.sh"
  24. # Runs kube-apiserver
  25. #
  26. # Exports:
  27. # APISERVER_PID
  28. function run_kube_apiserver() {
  29. kube::log::status "Building kube-apiserver"
  30. make -C "${KUBE_ROOT}" WHAT="cmd/kube-apiserver"
  31. # Start kube-apiserver
  32. kube::log::status "Starting kube-apiserver"
  33. # Admission Controllers to invoke prior to persisting objects in cluster
  34. ENABLE_ADMISSION_PLUGINS="LimitRanger,ResourceQuota"
  35. DISABLE_ADMISSION_PLUGINS="ServiceAccount,PersistentVolumeLabel,DefaultStorageClass,DefaultTolerationSeconds,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,StorageObjectInUseProtection"
  36. # Include RBAC (to exercise bootstrapping), and AlwaysAllow to allow all actions
  37. AUTHORIZATION_MODE="RBAC,AlwaysAllow"
  38. # Enable features
  39. ENABLE_FEATURE_GATES="ServerSideApply=true"
  40. "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \
  41. --insecure-bind-address="127.0.0.1" \
  42. --bind-address="127.0.0.1" \
  43. --insecure-port="${API_PORT}" \
  44. --authorization-mode="${AUTHORIZATION_MODE}" \
  45. --secure-port="${SECURE_API_PORT}" \
  46. --feature-gates="${ENABLE_FEATURE_GATES}" \
  47. --enable-admission-plugins="${ENABLE_ADMISSION_PLUGINS}" \
  48. --disable-admission-plugins="${DISABLE_ADMISSION_PLUGINS}" \
  49. --etcd-servers="http://${ETCD_HOST}:${ETCD_PORT}" \
  50. --runtime-config=api/v1 \
  51. --storage-media-type="${KUBE_TEST_API_STORAGE_TYPE-}" \
  52. --cert-dir="${TMPDIR:-/tmp/}" \
  53. --service-cluster-ip-range="10.0.0.0/24" \
  54. --token-auth-file=hack/testdata/auth-tokens.csv 1>&2 &
  55. export APISERVER_PID=$!
  56. kube::util::wait_for_url "http://127.0.0.1:${API_PORT}/healthz" "apiserver"
  57. }
  58. # Runs run_kube_controller_manager
  59. #
  60. # Exports:
  61. # CTLRMGR_PID
  62. function run_kube_controller_manager() {
  63. kube::log::status "Building kube-controller-manager"
  64. make -C "${KUBE_ROOT}" WHAT="cmd/kube-controller-manager"
  65. # Start controller manager
  66. kube::log::status "Starting controller-manager"
  67. "${KUBE_OUTPUT_HOSTBIN}/kube-controller-manager" \
  68. --port="${CTLRMGR_PORT}" \
  69. --kube-api-content-type="${KUBE_TEST_API_TYPE-}" \
  70. --master="127.0.0.1:${API_PORT}" 1>&2 &
  71. export CTLRMGR_PID=$!
  72. kube::util::wait_for_url "http://127.0.0.1:${CTLRMGR_PORT}/healthz" "controller-manager"
  73. }
  74. # Creates a node object with name 127.0.0.1. This is required because we do not
  75. # run kubelet.
  76. #
  77. # Exports:
  78. # SUPPORTED_RESOURCES(Array of all resources supported by the apiserver).
  79. function create_node() {
  80. kubectl create -f - -s "http://127.0.0.1:${API_PORT}" << __EOF__
  81. {
  82. "kind": "Node",
  83. "apiVersion": "v1",
  84. "metadata": {
  85. "name": "127.0.0.1"
  86. },
  87. "status": {
  88. "capacity": {
  89. "memory": "1Gi"
  90. }
  91. }
  92. }
  93. __EOF__
  94. }
  95. # Run it if:
  96. # 1) $WHAT is empty
  97. # 2) $WHAT is not empty and kubeadm is part of $WHAT
  98. WHAT=${WHAT:-}
  99. if [[ ${WHAT} == "" || ${WHAT} =~ .*kubeadm.* ]] ; then
  100. kube::log::status "Running kubeadm tests"
  101. run_kubeadm_tests
  102. # if we ONLY want to run kubeadm, then exit here.
  103. if [[ ${WHAT} == "kubeadm" ]]; then
  104. kube::log::status "TESTS PASSED"
  105. exit 0
  106. fi
  107. fi
  108. kube::log::status "Running kubectl tests for kube-apiserver"
  109. setup
  110. run_kube_apiserver
  111. run_kube_controller_manager
  112. create_node
  113. export SUPPORTED_RESOURCES=("*")
  114. # WARNING: Do not wrap this call in a subshell to capture output, e.g. output=$(runTests)
  115. # Doing so will suppress errexit behavior inside runTests
  116. runTests
  117. kube::log::status "TESTS PASSED"