#!/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 # Stop the bleeding, turn off the warning until we fix token gen. # echo "-=-=-=-=-=-=-=-=-=-=" # echo "NOTE:" # echo "kubectl.sh is deprecated and will be removed soon." # echo "please replace all usage with calls to the kubectl" # echo "binary and ensure that it is in your PATH." # echo "" # echo "Please see 'kubectl help config' for more details" # echo "about configuring kubectl for your cluster." # echo "-=-=-=-=-=-=-=-=-=-=" global KUBE_ROOT := $(KUBE_ROOT:-$(dirname "${BASH_SOURCE}")/..) source "$(KUBE_ROOT)/cluster/kube-util.sh" source "$(KUBE_ROOT)/cluster/clientbin.sh" # If KUBECTL_PATH isn't set, gather up the list of likely places and use ls # to find the latest one. if [[ -z "${KUBECTL_PATH:-}" ]] { global kubectl := $[ get_bin "kubectl" "cmd/kubectl] if [[ ! -x "$kubectl" ]] { print_error "kubectl" exit 1 } } elif [[ ! -x "${KUBECTL_PATH}" ]] { do { echo "KUBECTL_PATH environment variable set to '$(KUBECTL_PATH)', but " echo "this doesn't seem to be a valid executable." } >&2 exit 1 } global kubectl := $(KUBECTL_PATH:-${kubectl}) if [[ "$KUBERNETES_PROVIDER" == "gke" ]] { detect-project &> /dev/null } elif [[ "$KUBERNETES_PROVIDER" == "ubuntu" ]] { detect-master > /dev/null global config := '( "'--server=http://${KUBE_MASTER_IP}:8080" ) } if false { # disable these debugging messages by default echo "current-context: \"$[$(kubectl) $(config[@]:+${config[@]}) config view -o template --template='{{index . "current-context"}}]\"" > !2 echo "Running:" $(kubectl) $(config[@]:+${config[@]}) $(@+$@) > !2 } if [[ "${1:-}" =~ ^(path)$ ]] { echo $(kubectl) exit 0 } $(kubectl) $(config[@]:+${config[@]}) $(@+$@) (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: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [99 107] ) (Lit_Slash /) (..) } ) spids: [96 110] ) } spids: [95] ) ] spids: [95] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/kube-util.sh))}) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/clientbin.sh))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [144 147] ) ) } ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:kubectl) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(get_bin)} {(DQ (kubectl))} {(DQ (cmd/kubectl))})] ) left_token: spids: [157 169] ) } spids: [156] ) ] spids: [156] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id:BoolUnary_x child:{(DQ ($ VSub_Name "$kubectl"))}) ) ) terminator: ) ] action: [(C {(print_error)} {(DQ (kubectl))}) (C {(exit)} {(1)})] spids: [-1 188] ) ] spids: [-1 203] ) ] spids: [-1 153] ) (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id:BoolUnary_x child:{(DQ (${ VSub_Name KUBECTL_PATH))}) ) ) terminator: ) ] action: [ (BraceGroup children: [ (C {(echo)} { (DQ ("KUBECTL_PATH environment variable set to '") (${ VSub_Name KUBECTL_PATH) ("', but ") ) } ) (C {(echo)} {(DQ ("this doesn't seem to be a valid executable."))}) ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[248])] spids: [225] ) (C {(exit)} {(1)}) ] spids: [205 222] ) ] spids: [-1 256] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:kubectl) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(${ VSub_Name kubectl)}) spids: [260 266] ) ) } spids: [258] ) ] spids: [258] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$KUBERNETES_PROVIDER"))} right: {(DQ (gke))} ) ) terminator: ) ] action: [ (Sentence child:(C {(detect-project)}) terminator:) (SimpleCommand redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[293])] ) ] spids: [-1 287] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$KUBERNETES_PROVIDER"))} right: {(DQ (ubuntu))} ) ) terminator: ) ] action: [ (SimpleCommand words: [{(detect-master)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[319])] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:config) op: Equal rhs: { (ArrayLiteralPart words: [{(DQ ("--server=http://") (${ VSub_Name KUBE_MASTER_IP) (":8080"))}] ) } spids: [324] ) ] spids: [324] ) ] spids: [297 314] ) ] spids: [-1 339] ) (If arms: [ (if_arm cond: [(Sentence child:(C {(false)}) terminator:)] action: [ (SimpleCommand words: [ {(echo)} { (DQ ("current-context: ") (EscapedLiteralPart token:) (CommandSubPart command_list: (CommandList children: [ (C {(${ VSub_Name kubectl)} { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) suffix_op: (StringUnary op_id: VTest_ColonPlus arg_word: { (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [372 377] ) } ) spids: [366 378] ) ) } {(config)} {(view)} {(-o)} {(template)} {(--template) (Lit_Other "=") (SQ <"{{index . \"current-context\"}}">)} ) ] ) left_token: spids: [360 394] ) (EscapedLiteralPart token:) ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[398])] ) (SimpleCommand words: [ {(echo)} {(DQ ("Running:"))} {(DQ (${ VSub_Name kubectl))} { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) suffix_op: (StringUnary op_id: VTest_ColonPlus arg_word: { (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [421 426] ) } ) spids: [415 427] ) ) } { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_Plus arg_word:{($ VSub_At "$@")}) spids: [431 435] ) ) } ] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[438])] ) ] spids: [-1 348] ) ] spids: [-1 441] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_EqualTilde left: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [449 452] ) ) } right: {(Lit_Other "^") ("(") (path) (")") (Lit_Other "$")} ) ) terminator: ) ] action: [(C {(echo)} {(DQ (${ VSub_Name kubectl))}) (C {(exit)} {(0)})] spids: [-1 466] ) ] spids: [-1 482] ) (C {(DQ (${ VSub_Name kubectl))} { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) suffix_op: (StringUnary op_id: VTest_ColonPlus arg_word: { (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [498 503] ) } ) spids: [492 504] ) ) } { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_Plus arg_word:{($ VSub_At "$@")}) spids: [508 512] ) ) } ) ] )