init.sh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 reset to auto 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=auto
  26. # The root of the build/dist directory
  27. KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/../.." && 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. 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. # list of all available group versions. This should be used when generated code
  47. # or when starting an API server that you want to have everything.
  48. # most preferred version for a group should appear first
  49. KUBE_AVAILABLE_GROUP_VERSIONS="${KUBE_AVAILABLE_GROUP_VERSIONS:-\
  50. v1 \
  51. admissionregistration.k8s.io/v1beta1 \
  52. admission.k8s.io/v1beta1 \
  53. apps/v1 \
  54. apps/v1beta1 \
  55. apps/v1beta2 \
  56. auditregistration.k8s.io/v1alpha1 \
  57. authentication.k8s.io/v1 \
  58. authentication.k8s.io/v1beta1 \
  59. authorization.k8s.io/v1 \
  60. authorization.k8s.io/v1beta1 \
  61. autoscaling/v1 \
  62. autoscaling/v2beta1 \
  63. autoscaling/v2beta2 \
  64. batch/v1 \
  65. batch/v1beta1 \
  66. batch/v2alpha1 \
  67. certificates.k8s.io/v1beta1 \
  68. coordination.k8s.io/v1beta1 \
  69. coordination.k8s.io/v1 \
  70. extensions/v1beta1 \
  71. events.k8s.io/v1beta1 \
  72. imagepolicy.k8s.io/v1alpha1 \
  73. networking.k8s.io/v1 \
  74. networking.k8s.io/v1beta1 \
  75. node.k8s.io/v1alpha1 \
  76. node.k8s.io/v1beta1 \
  77. policy/v1beta1 \
  78. rbac.authorization.k8s.io/v1 \
  79. rbac.authorization.k8s.io/v1beta1 \
  80. rbac.authorization.k8s.io/v1alpha1 \
  81. scheduling.k8s.io/v1alpha1 \
  82. scheduling.k8s.io/v1beta1 \
  83. scheduling.k8s.io/v1 \
  84. settings.k8s.io/v1alpha1 \
  85. storage.k8s.io/v1beta1 \
  86. storage.k8s.io/v1 \
  87. storage.k8s.io/v1alpha1 \
  88. }"
  89. # not all group versions are exposed by the server. This list contains those
  90. # which are not available so we don't generate clients or swagger for them
  91. KUBE_NONSERVER_GROUP_VERSIONS="
  92. abac.authorization.kubernetes.io/v0 \
  93. abac.authorization.kubernetes.io/v1beta1 \
  94. componentconfig/v1alpha1 \
  95. imagepolicy.k8s.io/v1alpha1\
  96. admission.k8s.io/v1beta1\
  97. "
  98. # This emulates "readlink -f" which is not available on MacOS X.
  99. # Test:
  100. # T=/tmp/$$.$RANDOM
  101. # mkdir $T
  102. # touch $T/file
  103. # mkdir $T/dir
  104. # ln -s $T/file $T/linkfile
  105. # ln -s $T/dir $T/linkdir
  106. # function testone() {
  107. # X=$(readlink -f $1 2>&1)
  108. # Y=$(kube::readlinkdashf $1 2>&1)
  109. # if [ "$X" != "$Y" ]; then
  110. # echo readlinkdashf $1: expected "$X", got "$Y"
  111. # fi
  112. # }
  113. # testone /
  114. # testone /tmp
  115. # testone $T
  116. # testone $T/file
  117. # testone $T/dir
  118. # testone $T/linkfile
  119. # testone $T/linkdir
  120. # testone $T/nonexistant
  121. # testone $T/linkdir/file
  122. # testone $T/linkdir/dir
  123. # testone $T/linkdir/linkfile
  124. # testone $T/linkdir/linkdir
  125. function kube::readlinkdashf {
  126. # run in a subshell for simpler 'cd'
  127. (
  128. if [[ -d "${1}" ]]; then # This also catch symlinks to dirs.
  129. cd "${1}"
  130. pwd -P
  131. else
  132. cd "$(dirname "${1}")"
  133. local f
  134. f=$(basename "${1}")
  135. if [[ -L "${f}" ]]; then
  136. readlink "${f}"
  137. else
  138. echo "$(pwd -P)/${f}"
  139. fi
  140. fi
  141. )
  142. }
  143. # This emulates "realpath" which is not available on MacOS X
  144. # Test:
  145. # T=/tmp/$$.$RANDOM
  146. # mkdir $T
  147. # touch $T/file
  148. # mkdir $T/dir
  149. # ln -s $T/file $T/linkfile
  150. # ln -s $T/dir $T/linkdir
  151. # function testone() {
  152. # X=$(realpath $1 2>&1)
  153. # Y=$(kube::realpath $1 2>&1)
  154. # if [ "$X" != "$Y" ]; then
  155. # echo realpath $1: expected "$X", got "$Y"
  156. # fi
  157. # }
  158. # testone /
  159. # testone /tmp
  160. # testone $T
  161. # testone $T/file
  162. # testone $T/dir
  163. # testone $T/linkfile
  164. # testone $T/linkdir
  165. # testone $T/nonexistant
  166. # testone $T/linkdir/file
  167. # testone $T/linkdir/dir
  168. # testone $T/linkdir/linkfile
  169. # testone $T/linkdir/linkdir
  170. kube::realpath() {
  171. if [[ ! -e "${1}" ]]; then
  172. echo "${1}: No such file or directory" >&2
  173. return 1
  174. fi
  175. kube::readlinkdashf "${1}"
  176. }