From ea95cefb910655ddccc15d6bde773d8d3bc3068f Mon Sep 17 00:00:00 2001 From: Joe Beda Date: Sat, 18 Oct 2014 10:23:14 -0700 Subject: [PATCH] Make vagrant scripts work with bash 3 Fixes #1890 --- cluster/vagrant/config-default.sh | 6 +----- cluster/vagrant/util.sh | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cluster/vagrant/config-default.sh b/cluster/vagrant/config-default.sh index 6e8a96c8722..79171655fe6 100755 --- a/cluster/vagrant/config-default.sh +++ b/cluster/vagrant/config-default.sh @@ -31,13 +31,9 @@ MINION_TAG="${INSTANCE_PREFIX}-minion" # IP LOCATIONS FOR INTERACTING WITH THE MINIONS MINION_IP_BASE="10.245.2." -declare -A VAGRANT_MINION_NAMES_BY_IP - -for (( i=0; i <${NUM_MINIONS}; i++)) do +for ((i=0; i < NUM_MINIONS; i++)) do KUBE_MINION_IP_ADDRESSES[$i]="${MINION_IP_BASE}$[$i+2]" MINION_IP[$i]="${MINION_IP_BASE}$[$i+2]" MINION_NAMES[$i]="${MINION_IP[$i]}" VAGRANT_MINION_NAMES[$i]="minion-$[$i+1]" - - VAGRANT_MINION_NAMES_BY_IP["${MINION_IP[$i]}"]="${VAGRANT_MINION_NAMES[$i]}" done diff --git a/cluster/vagrant/util.sh b/cluster/vagrant/util.sh index 6e23d6ccf60..c1eaabfc3a5 100644 --- a/cluster/vagrant/util.sh +++ b/cluster/vagrant/util.sh @@ -144,11 +144,26 @@ function get-password { echo "Using credentials: $KUBE_USER:$KUBE_PASSWORD" } +# Find the minion name based on the IP address +function find-minion-by-ip { + local ip="$1" + local ip_pattern="${MINION_IP_BASE}(.*)" + + # This is subtle. We map 10.245.2.2 -> minion-1. We do this by matching a + # regexp and using the capture to construct the name. + [[ $ip =~ $ip_pattern ]] || { + return 1 + } + + echo "minion-$((${BASH_REMATCH[1]} - 1))" +} + # SSH to a node by name ($1) and run a command ($2). function ssh-to-node { local node="$1" local cmd="$2" - local machine="${VAGRANT_MINION_NAMES_BY_IP[${node}]}" + local machine + machine=$(find-minion-by-ip $node) vagrant ssh "${machine}" -c "${cmd}" | grep -v "Connection to.*closed" }