k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/lib/init.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2014 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 # Short-circuit if init.sh has already been sourced 22 [[ $(type -t kube::init::loaded) == function ]] && return 0 23 24 # Unset CDPATH so that path interpolation can work correctly 25 # https://github.com/kubernetes/kubernetes/issues/52255 26 unset CDPATH 27 28 # FIXME(dims): Note that here we assume that if GOFLAGS are already set we 29 # leave them as-is and not try to add providerless to it. So if you 30 # really need to set your own GOFLAGS, ensure you add "providerless" explicitly 31 if [[ "${KUBE_PROVIDERLESS:-"n"}" == "y" ]]; then 32 export GOFLAGS=${GOFLAGS:-"-tags=providerless"} 33 fi 34 35 # The root of the build/dist directory 36 KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" 37 38 # Where output goes. We should avoid redefining these anywhere else. 39 # 40 # KUBE_OUTPUT: the root directory (absolute) where this build should drop any 41 # files (subdirs are encouraged). 42 # KUBE_OUTPUT_BIN: the directory in which compiled binaries will be placed, 43 # under OS/ARCH specific subdirs 44 # THIS_PLATFORM_BIN: a symlink to the output directory for binaries built for 45 # the current host platform (e.g. build/test tools). 46 # 47 # Compat: The KUBE_OUTPUT_SUBPATH variable is sometimes passed in by callers. 48 # If it is specified, we'll use it in KUBE_OUTPUT. 49 _KUBE_OUTPUT_SUBPATH="${KUBE_OUTPUT_SUBPATH:-_output/local}" 50 export KUBE_OUTPUT="${KUBE_ROOT}/${_KUBE_OUTPUT_SUBPATH}" 51 export KUBE_OUTPUT_BIN="${KUBE_OUTPUT}/bin" 52 export THIS_PLATFORM_BIN="${KUBE_ROOT}/_output/bin" 53 54 # This controls rsync compression. Set to a value > 0 to enable rsync 55 # compression for build container 56 KUBE_RSYNC_COMPRESS="${KUBE_RSYNC_COMPRESS:-0}" 57 58 # Set no_proxy for localhost if behind a proxy, otherwise, 59 # the connections to localhost in scripts will time out 60 export no_proxy="127.0.0.1,localhost${no_proxy:+,${no_proxy}}" 61 62 source "${KUBE_ROOT}/hack/lib/util.sh" 63 source "${KUBE_ROOT}/hack/lib/logging.sh" 64 65 kube::log::install_errexit 66 kube::util::ensure-bash-version 67 68 source "${KUBE_ROOT}/hack/lib/version.sh" 69 source "${KUBE_ROOT}/hack/lib/golang.sh" 70 source "${KUBE_ROOT}/hack/lib/etcd.sh" 71 72 # list of all available group versions. This should be used when generated code 73 # or when starting an API server that you want to have everything. 74 # most preferred version for a group should appear first 75 KUBE_AVAILABLE_GROUP_VERSIONS="${KUBE_AVAILABLE_GROUP_VERSIONS:-\ 76 v1 \ 77 admissionregistration.k8s.io/v1 \ 78 admissionregistration.k8s.io/v1alpha1 \ 79 admissionregistration.k8s.io/v1beta1 \ 80 admission.k8s.io/v1 \ 81 admission.k8s.io/v1beta1 \ 82 apps/v1 \ 83 apps/v1beta1 \ 84 apps/v1beta2 \ 85 authentication.k8s.io/v1 \ 86 authentication.k8s.io/v1alpha1 \ 87 authentication.k8s.io/v1beta1 \ 88 authorization.k8s.io/v1 \ 89 authorization.k8s.io/v1beta1 \ 90 autoscaling/v1 \ 91 autoscaling/v2 \ 92 autoscaling/v2beta1 \ 93 autoscaling/v2beta2 \ 94 batch/v1 \ 95 batch/v1beta1 \ 96 certificates.k8s.io/v1 \ 97 certificates.k8s.io/v1beta1 \ 98 certificates.k8s.io/v1alpha1 \ 99 coordination.k8s.io/v1beta1 \ 100 coordination.k8s.io/v1 \ 101 discovery.k8s.io/v1 \ 102 discovery.k8s.io/v1beta1 \ 103 resource.k8s.io/v1alpha2 \ 104 extensions/v1beta1 \ 105 events.k8s.io/v1 \ 106 events.k8s.io/v1beta1 \ 107 imagepolicy.k8s.io/v1alpha1 \ 108 networking.k8s.io/v1 \ 109 networking.k8s.io/v1alpha1 \ 110 networking.k8s.io/v1beta1 \ 111 node.k8s.io/v1 \ 112 node.k8s.io/v1alpha1 \ 113 node.k8s.io/v1beta1 \ 114 policy/v1 \ 115 policy/v1beta1 \ 116 rbac.authorization.k8s.io/v1 \ 117 rbac.authorization.k8s.io/v1beta1 \ 118 rbac.authorization.k8s.io/v1alpha1 \ 119 scheduling.k8s.io/v1alpha1 \ 120 scheduling.k8s.io/v1beta1 \ 121 scheduling.k8s.io/v1 \ 122 storage.k8s.io/v1beta1 \ 123 storage.k8s.io/v1 \ 124 storage.k8s.io/v1alpha1 \ 125 flowcontrol.apiserver.k8s.io/v1 \ 126 storagemigration.k8s.io/v1alpha1 \ 127 flowcontrol.apiserver.k8s.io/v1beta1 \ 128 flowcontrol.apiserver.k8s.io/v1beta2 \ 129 flowcontrol.apiserver.k8s.io/v1beta3 \ 130 internal.apiserver.k8s.io/v1alpha1 \ 131 }" 132 133 # not all group versions are exposed by the server. This list contains those 134 # which are not available so we don't generate clients or swagger for them 135 KUBE_NONSERVER_GROUP_VERSIONS=" 136 abac.authorization.kubernetes.io/v0 \ 137 abac.authorization.kubernetes.io/v1beta1 \ 138 apidiscovery.k8s.io/v2beta1 \ 139 apidiscovery.k8s.io/v2 \ 140 componentconfig/v1alpha1 \ 141 imagepolicy.k8s.io/v1alpha1\ 142 admission.k8s.io/v1\ 143 admission.k8s.io/v1beta1\ 144 " 145 export KUBE_NONSERVER_GROUP_VERSIONS 146 147 # This emulates "readlink -f" which is not available on MacOS X. 148 # Test: 149 # T=/tmp/$$.$RANDOM 150 # mkdir $T 151 # touch $T/file 152 # mkdir $T/dir 153 # ln -s $T/file $T/linkfile 154 # ln -s $T/dir $T/linkdir 155 # function testone() { 156 # X=$(readlink -f $1 2>&1) 157 # Y=$(kube::readlinkdashf $1 2>&1) 158 # if [ "$X" != "$Y" ]; then 159 # echo readlinkdashf $1: expected "$X", got "$Y" 160 # fi 161 # } 162 # testone / 163 # testone /tmp 164 # testone $T 165 # testone $T/file 166 # testone $T/dir 167 # testone $T/linkfile 168 # testone $T/linkdir 169 # testone $T/nonexistant 170 # testone $T/linkdir/file 171 # testone $T/linkdir/dir 172 # testone $T/linkdir/linkfile 173 # testone $T/linkdir/linkdir 174 function kube::readlinkdashf { 175 # run in a subshell for simpler 'cd' 176 ( 177 if [[ -d "${1}" ]]; then # This also catch symlinks to dirs. 178 cd "${1}" 179 pwd -P 180 else 181 cd "$(dirname "${1}")" 182 local f 183 f=$(basename "${1}") 184 if [[ -L "${f}" ]]; then 185 readlink "${f}" 186 else 187 echo "$(pwd -P)/${f}" 188 fi 189 fi 190 ) 191 } 192 193 # This emulates "realpath" which is not available on MacOS X 194 # Test: 195 # T=/tmp/$$.$RANDOM 196 # mkdir $T 197 # touch $T/file 198 # mkdir $T/dir 199 # ln -s $T/file $T/linkfile 200 # ln -s $T/dir $T/linkdir 201 # function testone() { 202 # X=$(realpath $1 2>&1) 203 # Y=$(kube::realpath $1 2>&1) 204 # if [ "$X" != "$Y" ]; then 205 # echo realpath $1: expected "$X", got "$Y" 206 # fi 207 # } 208 # testone / 209 # testone /tmp 210 # testone $T 211 # testone $T/file 212 # testone $T/dir 213 # testone $T/linkfile 214 # testone $T/linkdir 215 # testone $T/nonexistant 216 # testone $T/linkdir/file 217 # testone $T/linkdir/dir 218 # testone $T/linkdir/linkfile 219 # testone $T/linkdir/linkdir 220 kube::realpath() { 221 if [[ ! -e "${1}" ]]; then 222 echo "${1}: No such file or directory" >&2 223 return 1 224 fi 225 kube::readlinkdashf "${1}" 226 } 227 228 # Marker function to indicate init.sh has been fully sourced 229 kube::init::loaded() { 230 return 0 231 }