#!/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. # This script will source the default skeleton helper functions, then sources # cluster/${KUBERNETES_PROVIDER}/util.sh where KUBERNETES_PROVIDER, if unset, # will use its default value (gce). global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/.." source "$(KUBE_ROOT)/cluster/skeleton/util.sh" if [[ -n "${KUBERNETES_CONFORMANCE_TEST:-}" ]] { global KUBERNETES_PROVIDER := ''"" } else { global KUBERNETES_PROVIDER := $(KUBERNETES_PROVIDER:-gce) } # PROVIDER_VARS is a list of cloud provider specific variables. Note: # this is a list of the _names_ of the variables, not the value of the # variables. Providers can add variables to be appended to kube-env. # (see `build-kube-env`). global PROVIDER_VARS := ''"" global PROVIDER_UTILS := ""$(KUBE_ROOT)/cluster/$(KUBERNETES_PROVIDER)/util.sh"" if test -f $(PROVIDER_UTILS) { source $(PROVIDER_UTILS) } # Federation utils # Sets the kubeconfig context value for the current cluster. # Args: # $1: zone (required) # # Vars set: # CLUSTER_CONTEXT proc kubeconfig-federation-context { if [[ -z "${1:-}" ]] { echo "zone parameter is required" exit 1 } global CLUSTER_CONTEXT := ""federation-e2e-$(KUBERNETES_PROVIDER)-$(1)"" } # Should NOT be called within the global scope, unless setting the desired global zone vars # This function is currently NOT USED in the global scope proc set-federation-zone-vars { global zone := $1 kubeconfig-federation-context $(zone) export OVERRIDE_CONTEXT="$(CLUSTER_CONTEXT)" echo "Setting zone vars to: $OVERRIDE_CONTEXT" if [[ "$KUBERNETES_PROVIDER" == "gce" ]]{ # This needs a revamp, but for now e2e zone name is used as the unique # cluster identifier in our e2e tests and we will continue to use that # pattern. export CLUSTER_NAME="$(zone)" export KUBE_GCE_ZONE="$(zone)" # gcloud has a 61 character limit, and for firewall rules this # prefix gets appended to itself, with some extra information # need tot keep it short export KUBE_GCE_INSTANCE_PREFIX="$(USER)-$(zone)" } elif [[ "$KUBERNETES_PROVIDER" == "gke" ]]{ export CLUSTER_NAME="$(USER)-$(zone)" } elif [[ "$KUBERNETES_PROVIDER" == "aws" ]]{ export KUBE_AWS_ZONE="$zone" export KUBE_AWS_INSTANCE_PREFIX="$(USER)-$(zone)" # WARNING: This is hack # After KUBE_AWS_INSTANCE_PREFIX is changed, # we need to make sure the config-xxx.sh file is # re-sourced so the change propogates to dependent computed values # (eg: MASTER_SG_NAME, NODE_SG_NAME, etc) source "$(KUBE_ROOT)/cluster/aws/util.sh" } else { echo "Provider \"$(KUBERNETES_PROVIDER)\" is not supported" exit 1 } } (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [55 63] ) (/..) } spids: [54] ) ] spids: [54] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/skeleton/util.sh))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_n child: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [84 87] ) ) } ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBERNETES_PROVIDER) op: Equal rhs: {(DQ )} spids: [96] ) ] spids: [96] ) ] spids: [-1 93] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBERNETES_PROVIDER) op: Equal rhs: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(gce)}) spids: [105 109] ) ) } spids: [103] ) ] spids: [103] ) ] spids: [100 112] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:PROVIDER_VARS) op:Equal rhs:{(DQ )} spids:[127])] spids: [127] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PROVIDER_UTILS) op: Equal rhs: {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/) (${ VSub_Name KUBERNETES_PROVIDER) (/util.sh))} spids: [132] ) ] spids: [132] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-f)} {(${ VSub_Name PROVIDER_UTILS)} {(Lit_Other "]")}) terminator: ) ] action: [(C {(source)} {(DQ (${ VSub_Name PROVIDER_UTILS))})] spids: [-1 157] ) ] spids: [-1 168] ) (FuncDef name: kubeconfig-federation-context body: (BraceGroup children: [ (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: [209 212] ) ) } ) ) terminator: ) ] action: [(C {(echo)} {(DQ ("zone parameter is required"))}) (C {(exit)} {(1)})] spids: [-1 218] ) ] spids: [-1 233] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CLUSTER_CONTEXT) op: Equal rhs: { (DQ (federation-e2e-) (${ VSub_Name KUBERNETES_PROVIDER) (-) (${ VSub_Number 1)) } spids: [236] ) ] spids: [236] ) ] spids: [199] ) spids: [193 198] ) (FuncDef name: set-federation-zone-vars body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:zone) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [264] ) ] spids: [264] ) (C {(kubeconfig-federation-context)} {(DQ (${ VSub_Name zone))}) (C {(export)} {(Lit_VarLike "OVERRIDE_CONTEXT=") (DQ (${ VSub_Name CLUSTER_CONTEXT))}) (C {(echo)} {(DQ ("Setting zone vars to: ") ($ VSub_Name "$OVERRIDE_CONTEXT"))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$KUBERNETES_PROVIDER"))} right: {(DQ (gce))} ) ) terminator: ) ] action: [ (C {(export)} {(Lit_VarLike "CLUSTER_NAME=") (DQ (${ VSub_Name zone))}) (C {(export)} {(Lit_VarLike "KUBE_GCE_ZONE=") (DQ (${ VSub_Name zone))}) (C {(export)} {(Lit_VarLike "KUBE_GCE_INSTANCE_PREFIX=") (DQ (${ VSub_Name USER) (-) (${ VSub_Name zone)) } ) ] spids: [-1 313] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$KUBERNETES_PROVIDER"))} right: {(DQ (gke))} ) ) terminator: ) ] action: [ (C {(export)} {(Lit_VarLike "CLUSTER_NAME=") (DQ (${ VSub_Name USER) (-) (${ VSub_Name zone))} ) ] spids: [376 392] ) (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$KUBERNETES_PROVIDER"))} right: {(DQ (aws))} ) ) terminator: ) ] action: [ (C {(export)} {(Lit_VarLike "KUBE_AWS_ZONE=") (DQ ($ VSub_Name "$zone"))}) (C {(export)} {(Lit_VarLike "KUBE_AWS_INSTANCE_PREFIX=") (DQ (${ VSub_Name USER) (-) (${ VSub_Name zone)) } ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/aws/util.sh))}) ] spids: [411 427] ) ] else_action: [ (C {(echo)} { (DQ ("Provider ") (EscapedLiteralPart token:) (${ VSub_Name KUBERNETES_PROVIDER) (EscapedLiteralPart token:) (" is not supported") ) } ) (C {(exit)} {(1)}) ] spids: [484 505] ) ] spids: [261] ) spids: [257 260] ) ] )