init.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. # Unset CDPATH so that path interpolation can work correctly
  19. # https://github.com/kubernetes/kubernetes/issues/52255
  20. unset CDPATH
  21. # Until all GOPATH references are removed from all build scripts as well,
  22. # explicitly disable module mode to avoid picking up user-set GO111MODULE preferences.
  23. # As individual scripts (like hack/update-vendor.sh) make use of go modules,
  24. # they can explicitly set GO111MODULE=on
  25. export GO111MODULE=off
  26. # The root of the build/dist directory
  27. KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
  28. KUBE_OUTPUT_SUBPATH="${KUBE_OUTPUT_SUBPATH:-_output/local}"
  29. KUBE_OUTPUT="${KUBE_ROOT}/${KUBE_OUTPUT_SUBPATH}"
  30. KUBE_OUTPUT_BINPATH="${KUBE_OUTPUT}/bin"
  31. # This controls rsync compression. Set to a value > 0 to enable rsync
  32. # compression for build container
  33. KUBE_RSYNC_COMPRESS="${KUBE_RSYNC_COMPRESS:-0}"
  34. # Set no_proxy for localhost if behind a proxy, otherwise,
  35. # the connections to localhost in scripts will time out
  36. export no_proxy=127.0.0.1,localhost
  37. # This is a symlink to binaries for "this platform", e.g. build tools.
  38. export THIS_PLATFORM_BIN="${KUBE_ROOT}/_output/bin"
  39. source "${KUBE_ROOT}/hack/lib/util.sh"
  40. source "${KUBE_ROOT}/hack/lib/logging.sh"
  41. kube::log::install_errexit
  42. source "${KUBE_ROOT}/hack/lib/version.sh"
  43. source "${KUBE_ROOT}/hack/lib/golang.sh"
  44. source "${KUBE_ROOT}/hack/lib/etcd.sh"
  45. KUBE_OUTPUT_HOSTBIN="${KUBE_OUTPUT_BINPATH}/$(kube::util::host_platform)"
  46. export KUBE_OUTPUT_HOSTBIN
  47. # list of all available group versions. This should be used when generated code
  48. # or when starting an API server that you want to have everything.
  49. # most preferred version for a group should appear first
  50. KUBE_AVAILABLE_GROUP_VERSIONS="${KUBE_AVAILABLE_GROUP_VERSIONS:-\
  51. v1 \
  52. admissionregistration.k8s.io/v1 \
  53. admissionregistration.k8s.io/v1beta1 \
  54. admission.k8s.io/v1 \
  55. admission.k8s.io/v1beta1 \
  56. apps/v1 \
  57. apps/v1beta1 \
  58. apps/v1beta2 \
  59. auditregistration.k8s.io/v1alpha1 \
  60. authentication.k8s.io/v1 \
  61. authentication.k8s.io/v1beta1 \
  62. authorization.k8s.io/v1 \
  63. authorization.k8s.io/v1beta1 \
  64. autoscaling/v1 \
  65. autoscaling/v2beta1 \
  66. autoscaling/v2beta2 \
  67. batch/v1 \
  68. batch/v1beta1 \
  69. batch/v2alpha1 \
  70. certificates.k8s.io/v1beta1 \
  71. coordination.k8s.io/v1beta1 \
  72. coordination.k8s.io/v1 \
  73. discovery.k8s.io/v1alpha1 \
  74. discovery.k8s.io/v1beta1 \
  75. extensions/v1beta1 \
  76. events.k8s.io/v1beta1 \
  77. imagepolicy.k8s.io/v1alpha1 \
  78. networking.k8s.io/v1 \
  79. networking.k8s.io/v1beta1 \
  80. node.k8s.io/v1alpha1 \
  81. node.k8s.io/v1beta1 \
  82. policy/v1beta1 \
  83. rbac.authorization.k8s.io/v1 \
  84. rbac.authorization.k8s.io/v1beta1 \
  85. rbac.authorization.k8s.io/v1alpha1 \
  86. scheduling.k8s.io/v1alpha1 \
  87. scheduling.k8s.io/v1beta1 \
  88. scheduling.k8s.io/v1 \
  89. settings.k8s.io/v1alpha1 \
  90. storage.k8s.io/v1beta1 \
  91. storage.k8s.io/v1 \
  92. storage.k8s.io/v1alpha1 \
  93. flowcontrol.apiserver.k8s.io/v1alpha1 \
  94. }"
  95. # not all group versions are exposed by the server. This list contains those
  96. # which are not available so we don't generate clients or swagger for them
  97. KUBE_NONSERVER_GROUP_VERSIONS="
  98. abac.authorization.kubernetes.io/v0 \
  99. abac.authorization.kubernetes.io/v1beta1 \
  100. componentconfig/v1alpha1 \
  101. imagepolicy.k8s.io/v1alpha1\
  102. admission.k8s.io/v1\
  103. admission.k8s.io/v1beta1\
  104. "
  105. export KUBE_NONSERVER_GROUP_VERSIONS
  106. # This emulates "readlink -f" which is not available on MacOS X.
  107. # Test:
  108. # T=/tmp/$$.$RANDOM
  109. # mkdir $T
  110. # touch $T/file
  111. # mkdir $T/dir
  112. # ln -s $T/file $T/linkfile
  113. # ln -s $T/dir $T/linkdir
  114. # function testone() {
  115. # X=$(readlink -f $1 2>&1)
  116. # Y=$(kube::readlinkdashf $1 2>&1)
  117. # if [ "$X" != "$Y" ]; then
  118. # echo readlinkdashf $1: expected "$X", got "$Y"
  119. # fi
  120. # }
  121. # testone /
  122. # testone /tmp
  123. # testone $T
  124. # testone $T/file
  125. # testone $T/dir
  126. # testone $T/linkfile
  127. # testone $T/linkdir
  128. # testone $T/nonexistant
  129. # testone $T/linkdir/file
  130. # testone $T/linkdir/dir
  131. # testone $T/linkdir/linkfile
  132. # testone $T/linkdir/linkdir
  133. function kube::readlinkdashf {
  134. # run in a subshell for simpler 'cd'
  135. (
  136. if [[ -d "${1}" ]]; then # This also catch symlinks to dirs.
  137. cd "${1}"
  138. pwd -P
  139. else
  140. cd "$(dirname "${1}")"
  141. local f
  142. f=$(basename "${1}")
  143. if [[ -L "${f}" ]]; then
  144. readlink "${f}"
  145. else
  146. echo "$(pwd -P)/${f}"
  147. fi
  148. fi
  149. )
  150. }
  151. # This emulates "realpath" which is not available on MacOS X
  152. # Test:
  153. # T=/tmp/$$.$RANDOM
  154. # mkdir $T
  155. # touch $T/file
  156. # mkdir $T/dir
  157. # ln -s $T/file $T/linkfile
  158. # ln -s $T/dir $T/linkdir
  159. # function testone() {
  160. # X=$(realpath $1 2>&1)
  161. # Y=$(kube::realpath $1 2>&1)
  162. # if [ "$X" != "$Y" ]; then
  163. # echo realpath $1: expected "$X", got "$Y"
  164. # fi
  165. # }
  166. # testone /
  167. # testone /tmp
  168. # testone $T
  169. # testone $T/file
  170. # testone $T/dir
  171. # testone $T/linkfile
  172. # testone $T/linkdir
  173. # testone $T/nonexistant
  174. # testone $T/linkdir/file
  175. # testone $T/linkdir/dir
  176. # testone $T/linkdir/linkfile
  177. # testone $T/linkdir/linkdir
  178. kube::realpath() {
  179. if [[ ! -e "${1}" ]]; then
  180. echo "${1}: No such file or directory" >&2
  181. return 1
  182. fi
  183. kube::readlinkdashf "${1}"
  184. }