#!/bin/bash # Copyright 2014 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -o errexit set -o nounset set -o pipefail # The root of the build/dist directory global KUBE_ROOT := $[cd "$[dirname $(BASH_SOURCE)]/../.." && pwd -P] global KUBE_OUTPUT_SUBPATH := $(KUBE_OUTPUT_SUBPATH:-_output/local) global KUBE_OUTPUT := ""$(KUBE_ROOT)/$(KUBE_OUTPUT_SUBPATH)"" global KUBE_OUTPUT_BINPATH := ""$(KUBE_OUTPUT)/bin"" # This controls rsync compression. Set to a value > 0 to enable rsync # compression for build container global KUBE_RSYNC_COMPRESS := $(KUBE_RSYNC_COMPRESS:-0) # Set no_proxy for localhost if behind a proxy, otherwise, # the connections to localhost in scripts will time out export no_proxy=127.0.0.1,localhost # This is a symlink to binaries for "this platform", e.g. build tools. global THIS_PLATFORM_BIN := ""$(KUBE_ROOT)/_output/bin"" source "$(KUBE_ROOT)/hack/lib/util.sh" source "$(KUBE_ROOT)/cluster/lib/logging.sh" kube::log::install_errexit source "$(KUBE_ROOT)/hack/lib/version.sh" source "$(KUBE_ROOT)/hack/lib/golang.sh" source "$(KUBE_ROOT)/hack/lib/etcd.sh" global KUBE_OUTPUT_HOSTBIN := ""$(KUBE_OUTPUT_BINPATH)/$[kube::util::host_platform]"" # list of all available group versions. This should be used when generated code # or when starting an API server that you want to have everything. # most preferred version for a group should appear first global KUBE_AVAILABLE_GROUP_VERSIONS := $(KUBE_AVAILABLE_GROUP_VERSIONS:-\ v1 \ admissionregistration.k8s.io/v1alpha1 \ admission.k8s.io/v1alpha1 \ apps/v1beta1 \ apps/v1beta2 \ apps/v1 \ authentication.k8s.io/v1 \ authentication.k8s.io/v1beta1 \ authorization.k8s.io/v1 \ authorization.k8s.io/v1beta1 \ autoscaling/v1 \ autoscaling/v2beta1 \ batch/v1 \ batch/v1beta1 \ batch/v2alpha1 \ certificates.k8s.io/v1beta1 \ extensions/v1beta1 \ imagepolicy.k8s.io/v1alpha1 \ networking.k8s.io/v1 \ policy/v1beta1 \ rbac.authorization.k8s.io/v1 \ rbac.authorization.k8s.io/v1beta1 \ rbac.authorization.k8s.io/v1alpha1 \ scheduling.k8s.io/v1alpha1 \ settings.k8s.io/v1alpha1 \ storage.k8s.io/v1beta1 \ storage.k8s.io/v1 \ ) # not all group versions are exposed by the server. This list contains those # which are not available so we don't generate clients or swagger for them global KUBE_NONSERVER_GROUP_VERSIONS := '" abac.authorization.kubernetes.io/v0 \ abac.authorization.kubernetes.io/v1beta1 \ componentconfig/v1alpha1 \ imagepolicy.k8s.io/v1alpha1\ admission.k8s.io/v1alpha1'\ " # This emulates "readlink -f" which is not available on MacOS X. # Test: # T=/tmp/$$.$RANDOM # mkdir $T # touch $T/file # mkdir $T/dir # ln -s $T/file $T/linkfile # ln -s $T/dir $T/linkdir # function testone() { # X=$(readlink -f $1 2>&1) # Y=$(kube::readlinkdashf $1 2>&1) # if [ "$X" != "$Y" ]; then # echo readlinkdashf $1: expected "$X", got "$Y" # fi # } # testone / # testone /tmp # testone $T # testone $T/file # testone $T/dir # testone $T/linkfile # testone $T/linkdir # testone $T/nonexistant # testone $T/linkdir/file # testone $T/linkdir/dir # testone $T/linkdir/linkfile # testone $T/linkdir/linkdir proc kube::readlinkdashf::readlinkdashf { # run in a subshell for simpler 'cd' shell { if [[ -d "$1" ]] { # This also catch symlinks to dirs. cd $1 pwd -P } else { cd $[dirname $1] var f = '' f := $[basename $1] if [[ -L "$f" ]] { readlink $f } else { echo "$[pwd -P]/$(f)" } } } } # This emulates "realpath" which is not available on MacOS X # Test: # T=/tmp/$$.$RANDOM # mkdir $T # touch $T/file # mkdir $T/dir # ln -s $T/file $T/linkfile # ln -s $T/dir $T/linkdir # function testone() { # X=$(realpath $1 2>&1) # Y=$(kube::realpath $1 2>&1) # if [ "$X" != "$Y" ]; then # echo realpath $1: expected "$X", got "$Y" # fi # } # testone / # testone /tmp # testone $T # testone $T/file # testone $T/dir # testone $T/linkfile # testone $T/linkdir # testone $T/nonexistant # testone $T/linkdir/file # testone $T/linkdir/dir # testone $T/linkdir/linkfile # testone $T/linkdir/linkdir proc kube::realpath { if [[ ! -e "$1" ]] { echo "$1: No such file or directory" > !2 return 1 } kube::readlinkdashf $1 } (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (AndOr children: [ (C {(cd)} { (DQ (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [72 80] ) (/../..) ) } ) (C {(pwd)} {(-P)}) ] op_id: Op_DAmp ) ] ) left_token: spids: [68 89] ) ) } spids: [66] ) ] spids: [66] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_OUTPUT_SUBPATH) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {(_output) (Lit_Slash /) (local)} ) spids: [95 101] ) ) } spids: [93] ) ] spids: [93] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_OUTPUT) op: Equal rhs: {(DQ (${ VSub_Name KUBE_ROOT) (/) (${ VSub_Name KUBE_OUTPUT_SUBPATH))} spids: [104] ) ] spids: [104] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_OUTPUT_BINPATH) op: Equal rhs: {(DQ (${ VSub_Name KUBE_OUTPUT) (/bin))} spids: [115] ) ] spids: [115] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_RSYNC_COMPRESS) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(0)}) spids: [132 136] ) ) } spids: [130] ) ] spids: [130] ) (C {(export)} {(Lit_VarLike "no_proxy=") (127.0.0.1) (Lit_Comma ",") (localhost)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:THIS_PLATFORM_BIN) op: Equal rhs: {(DQ (${ VSub_Name KUBE_ROOT) (/_output/bin))} spids: [157] ) ] spids: [157] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/util.sh))}) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/lib/logging.sh))}) (C {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (install_errexit)} ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/version.sh))}) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/golang.sh))}) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/hack/lib/etcd.sh))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_OUTPUT_HOSTBIN) op: Equal rhs: { (DQ (${ VSub_Name KUBE_OUTPUT_BINPATH) (/) (CommandSubPart command_list: (CommandList children: [ (C {(kube) (Lit_Other ":") (Lit_Other ":") (util) (Lit_Other ":") (Lit_Other ":") (host_platform) } ) ] ) left_token: spids: [228 236] ) ) } spids: [222] ) ] spids: [222] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_AVAILABLE_GROUP_VERSIONS) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {("v1 ") (admissionregistration.k8s.io) (Lit_Slash /) ("v1alpha1 ") (admission.k8s.io) (Lit_Slash /) ("v1alpha1 ") (apps) (Lit_Slash /) ("v1beta1 ") (apps) (Lit_Slash /) ("v1beta2 ") (apps) (Lit_Slash /) ("v1 ") (authentication.k8s.io) (Lit_Slash /) ("v1 ") (authentication.k8s.io) (Lit_Slash /) ("v1beta1 ") (authorization.k8s.io) (Lit_Slash /) ("v1 ") (authorization.k8s.io) (Lit_Slash /) ("v1beta1 ") (autoscaling) (Lit_Slash /) ("v1 ") (autoscaling) (Lit_Slash /) ("v2beta1 ") (batch) (Lit_Slash /) ("v1 ") (batch) (Lit_Slash /) ("v1beta1 ") (batch) (Lit_Slash /) ("v2alpha1 ") (certificates.k8s.io) (Lit_Slash /) ("v1beta1 ") (extensions) (Lit_Slash /) ("v1beta1 ") (imagepolicy.k8s.io) (Lit_Slash /) ("v1alpha1 ") (networking.k8s.io) (Lit_Slash /) ("v1 ") (policy) (Lit_Slash /) ("v1beta1 ") (rbac.authorization.k8s.io) (Lit_Slash /) ("v1 ") (rbac.authorization.k8s.io) (Lit_Slash /) ("v1beta1 ") (rbac.authorization.k8s.io) (Lit_Slash /) ("v1alpha1 ") (scheduling.k8s.io) (Lit_Slash /) ("v1alpha1 ") (settings.k8s.io) (Lit_Slash /) ("v1alpha1 ") (storage.k8s.io) (Lit_Slash /) ("v1beta1 ") (storage.k8s.io) (Lit_Slash /) ("v1 ") } ) spids: [251 361] ) ) } spids: [249] ) ] spids: [249] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_NONSERVER_GROUP_VERSIONS) op: Equal rhs: { (DQ ("\n") (" abac.authorization.kubernetes.io/v0 ") (" abac.authorization.kubernetes.io/v1beta1 ") (" componentconfig/v1alpha1 ") (" imagepolicy.k8s.io/v1alpha1") (" admission.k8s.io/v1alpha1") ) } spids: [371] ) ] spids: [371] ) (FuncDef name: "kube::readlinkdashf" body: (BraceGroup children: [ (Subshell child: (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_d child:{(DQ ($ VSub_Number "$1"))}) ) terminator: ) ] action: [(C {(cd)} {(DQ ($ VSub_Number "$1"))}) (C {(pwd)} {(-P)})] spids: [-1 498] ) ] else_action: [ (C {(cd)} { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ ($ VSub_Number "$1"))})] ) left_token: spids: [521 527] ) } ) (Assignment keyword: Assign_Local pairs: [(assign_pair lhs:(LhsName name:f) op:Equal spids:[532])] spids: [530] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:f) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(basename)} {(DQ ($ VSub_Number "$1"))})] ) left_token: spids: [536 542] ) } spids: [535] ) ] spids: [535] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id:BoolUnary_L child:{(DQ ($ VSub_Name "$f"))}) ) terminator: ) ] action: [(C {(readlink)} {(DQ ($ VSub_Name "$f"))})] spids: [-1 558] ) ] else_action: [ (C {(echo)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)} {(-P)})]) left_token: spids: [574 578] ) (/) (${ VSub_Name f) ) } ) ] spids: [568 586] ) ] spids: [516 589] ) spids: [482 592] ) ] spids: [475] ) spids: [468 471] ) (FuncDef name: "kube::realpath" body: (BraceGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id:BoolUnary_e child:{(DQ ($ VSub_Number "$1"))}) ) ) terminator: ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ($ VSub_Number "$1") (": No such file or directory"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[713])] ) (ControlFlow token: arg_word:{(1)}) ] spids: [-1 703] ) ] spids: [-1 722] ) (C {(kube) (Lit_Other ":") (Lit_Other ":") (readlinkdashf)} {(DQ ($ VSub_Number "$1"))}) ] spids: [685] ) spids: [678 684] ) ] )