...

Text file src/k8s.io/kubernetes/hack/lib/init.sh

Documentation: k8s.io/kubernetes/hack/lib

     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
    17set -o errexit
    18set -o nounset
    19set -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
    26unset 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
    31if [[ "${KUBE_PROVIDERLESS:-"n"}" == "y" ]]; then
    32  export GOFLAGS=${GOFLAGS:-"-tags=providerless"}
    33fi
    34
    35# The root of the build/dist directory
    36KUBE_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}"
    50export KUBE_OUTPUT="${KUBE_ROOT}/${_KUBE_OUTPUT_SUBPATH}"
    51export KUBE_OUTPUT_BIN="${KUBE_OUTPUT}/bin"
    52export 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
    56KUBE_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
    60export no_proxy="127.0.0.1,localhost${no_proxy:+,${no_proxy}}"
    61
    62source "${KUBE_ROOT}/hack/lib/util.sh"
    63source "${KUBE_ROOT}/hack/lib/logging.sh"
    64
    65kube::log::install_errexit
    66kube::util::ensure-bash-version
    67
    68source "${KUBE_ROOT}/hack/lib/version.sh"
    69source "${KUBE_ROOT}/hack/lib/golang.sh"
    70source "${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
    75KUBE_AVAILABLE_GROUP_VERSIONS="${KUBE_AVAILABLE_GROUP_VERSIONS:-\
    76v1 \
    77admissionregistration.k8s.io/v1 \
    78admissionregistration.k8s.io/v1alpha1 \
    79admissionregistration.k8s.io/v1beta1 \
    80admission.k8s.io/v1 \
    81admission.k8s.io/v1beta1 \
    82apps/v1 \
    83apps/v1beta1 \
    84apps/v1beta2 \
    85authentication.k8s.io/v1 \
    86authentication.k8s.io/v1alpha1 \
    87authentication.k8s.io/v1beta1 \
    88authorization.k8s.io/v1 \
    89authorization.k8s.io/v1beta1 \
    90autoscaling/v1 \
    91autoscaling/v2 \
    92autoscaling/v2beta1 \
    93autoscaling/v2beta2 \
    94batch/v1 \
    95batch/v1beta1 \
    96certificates.k8s.io/v1 \
    97certificates.k8s.io/v1beta1 \
    98certificates.k8s.io/v1alpha1 \
    99coordination.k8s.io/v1beta1 \
   100coordination.k8s.io/v1 \
   101discovery.k8s.io/v1 \
   102discovery.k8s.io/v1beta1 \
   103resource.k8s.io/v1alpha2 \
   104extensions/v1beta1 \
   105events.k8s.io/v1 \
   106events.k8s.io/v1beta1 \
   107imagepolicy.k8s.io/v1alpha1 \
   108networking.k8s.io/v1 \
   109networking.k8s.io/v1alpha1 \
   110networking.k8s.io/v1beta1 \
   111node.k8s.io/v1 \
   112node.k8s.io/v1alpha1 \
   113node.k8s.io/v1beta1 \
   114policy/v1 \
   115policy/v1beta1 \
   116rbac.authorization.k8s.io/v1 \
   117rbac.authorization.k8s.io/v1beta1 \
   118rbac.authorization.k8s.io/v1alpha1 \
   119scheduling.k8s.io/v1alpha1 \
   120scheduling.k8s.io/v1beta1 \
   121scheduling.k8s.io/v1 \
   122storage.k8s.io/v1beta1 \
   123storage.k8s.io/v1 \
   124storage.k8s.io/v1alpha1 \
   125flowcontrol.apiserver.k8s.io/v1 \
   126storagemigration.k8s.io/v1alpha1 \
   127flowcontrol.apiserver.k8s.io/v1beta1 \
   128flowcontrol.apiserver.k8s.io/v1beta2 \
   129flowcontrol.apiserver.k8s.io/v1beta3 \
   130internal.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
   135KUBE_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"
   145export 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
   174function 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
   220kube::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
   229kube::init::loaded() {
   230  return 0
   231}

View as plain text