update-swagger-spec.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # Copyright 2015 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. # Script to fetch latest swagger spec.
  16. # Puts the updated spec at api/swagger-spec/
  17. set -o errexit
  18. set -o nounset
  19. set -o pipefail
  20. cat << __EOF__
  21. Note: This assumes that the 'types_swagger_doc_generated.go' file has been
  22. updated for all API group versions. If you are unsure, please run
  23. hack/update-generated-swagger-docs.sh first.
  24. __EOF__
  25. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
  26. SWAGGER_ROOT_DIR="${KUBE_ROOT}/api/swagger-spec"
  27. source "${KUBE_ROOT}/hack/lib/init.sh"
  28. kube::golang::setup_env
  29. make -C "${KUBE_ROOT}" WHAT=cmd/kube-apiserver
  30. function cleanup()
  31. {
  32. [[ -n ${APISERVER_PID-} ]] && kill ${APISERVER_PID} 1>&2 2>/dev/null
  33. kube::etcd::cleanup
  34. kube::log::status "Clean up complete"
  35. }
  36. trap cleanup EXIT SIGINT
  37. kube::golang::setup_env
  38. apiserver=$(kube::util::find-binary "kube-apiserver")
  39. TMP_DIR=$(mktemp -d /tmp/update-swagger-spec.XXXX)
  40. ETCD_HOST=${ETCD_HOST:-127.0.0.1}
  41. ETCD_PORT=${ETCD_PORT:-2379}
  42. API_PORT=${API_PORT:-8050}
  43. API_HOST=${API_HOST:-127.0.0.1}
  44. kube::etcd::start
  45. # Start kube-apiserver
  46. kube::log::status "Starting kube-apiserver"
  47. "${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \
  48. --insecure-bind-address="${API_HOST}" \
  49. --bind-address="${API_HOST}" \
  50. --insecure-port="${API_PORT}" \
  51. --etcd-servers="http://${ETCD_HOST}:${ETCD_PORT}" \
  52. --advertise-address="10.10.10.10" \
  53. --cert-dir="${TMP_DIR}/certs" \
  54. --service-cluster-ip-range="10.0.0.0/24" >/tmp/swagger-api-server.log 2>&1 &
  55. APISERVER_PID=$!
  56. kube::util::wait_for_url "${API_HOST}:${API_PORT}/healthz" "apiserver: "
  57. SWAGGER_API_PATH="${API_HOST}:${API_PORT}/swaggerapi/"
  58. DEFAULT_GROUP_VERSIONS="v1 apps/v1alpha1 authentication.k8s.io/v1beta1 authorization.k8s.io/v1beta1 autoscaling/v1 batch/v1 batch/v2alpha1 extensions/v1beta1 certificates/v1alpha1 policy/v1alpha1 rbac.authorization.k8s.io/v1alpha1"
  59. VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS}
  60. kube::log::status "Updating " ${SWAGGER_ROOT_DIR}
  61. SWAGGER_API_PATH="${SWAGGER_API_PATH}" SWAGGER_ROOT_DIR="${SWAGGER_ROOT_DIR}" VERSIONS="${VERSIONS}" kube::util::fetch-swagger-spec
  62. kube::log::status "SUCCESS"
  63. # ex: ts=2 sw=2 et filetype=sh