From 505488269c67062491dddb39ae0a227c37988c79 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 25 Mar 2015 12:36:20 -0700 Subject: [PATCH 1/3] Use double-square brackets in if tests --- cluster/aws/util.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cluster/aws/util.sh b/cluster/aws/util.sh index 0b726f55682..065fef7a4bb 100644 --- a/cluster/aws/util.sh +++ b/cluster/aws/util.sh @@ -87,7 +87,7 @@ function detect-minions () { echo "Found ${MINION_NAMES[$i]} at ${minion_ip}" KUBE_MINION_IP_ADDRESSES+=("${minion_ip}") done - if [ -z "$KUBE_MINION_IP_ADDRESSES" ]; then + if [[ -z "$KUBE_MINION_IP_ADDRESSES" ]]; then echo "Could not detect Kubernetes minion nodes. Make sure you've launched a cluster with 'kube-up.sh'" exit 1 fi @@ -156,7 +156,7 @@ function detect-image () { # Verify prereqs function verify-prereqs { - if [ "$(which aws)" == "" ]; then + if [[ "$(which aws)" == "" ]]; then echo "Can't find aws in PATH, please fix and retry." exit 1 fi @@ -341,7 +341,7 @@ function kube-up { local htpasswd htpasswd=$(cat "${KUBE_TEMP}/htpasswd") - if [ ! -f $AWS_SSH_KEY ]; then + if [[ ! -f $AWS_SSH_KEY ]]; then ssh-keygen -f $AWS_SSH_KEY -N '' fi @@ -351,7 +351,7 @@ function kube-up { VPC_ID=$($AWS_CMD describe-vpcs | get_vpc_id) - if [ -z "$VPC_ID" ]; then + if [[ -z "$VPC_ID" ]]; then echo "Creating vpc." VPC_ID=$($AWS_CMD create-vpc --cidr-block 172.20.0.0/16 | json_val '["Vpc"]["VpcId"]') $AWS_CMD modify-vpc-attribute --vpc-id $VPC_ID --enable-dns-support '{"Value": true}' > $LOG @@ -362,7 +362,7 @@ function kube-up { echo "Using VPC $VPC_ID" SUBNET_ID=$($AWS_CMD describe-subnets | get_subnet_id $VPC_ID) - if [ -z "$SUBNET_ID" ]; then + if [[ -z "$SUBNET_ID" ]]; then echo "Creating subnet." SUBNET_ID=$($AWS_CMD create-subnet --cidr-block 172.20.0.0/24 --vpc-id $VPC_ID | json_val '["Subnet"]["SubnetId"]') fi @@ -370,7 +370,7 @@ function kube-up { echo "Using subnet $SUBNET_ID" IGW_ID=$($AWS_CMD describe-internet-gateways | get_igw_id $VPC_ID) - if [ -z "$IGW_ID" ]; then + if [[ -z "$IGW_ID" ]]; then echo "Creating Internet Gateway." IGW_ID=$($AWS_CMD create-internet-gateway | json_val '["InternetGateway"]["InternetGatewayId"]') $AWS_CMD attach-internet-gateway --internet-gateway-id $IGW_ID --vpc-id $VPC_ID > $LOG @@ -390,7 +390,7 @@ function kube-up { SEC_GROUP_ID=$($AWS_CMD describe-security-groups | get_sec_group_id) - if [ -z "$SEC_GROUP_ID" ]; then + if [[ -z "$SEC_GROUP_ID" ]]; then echo "Creating security group." SEC_GROUP_ID=$($AWS_CMD create-security-group --group-name kubernetes-sec-group --description kubernetes-sec-group --vpc-id $VPC_ID | json_val '["GroupId"]') $AWS_CMD authorize-security-group-ingress --group-id $SEC_GROUP_ID --protocol -1 --port all --cidr 0.0.0.0/0 > $LOG @@ -805,7 +805,7 @@ function ssh-to-node { local cmd="$2" local ip=$(get_instance_public_ip ${node}) - if [ -z "ip" ]; then + if [[ -z "ip" ]]; then echo "Could not detect IP for ${node}." exit 1 fi From 80ba56a3715df95a8dcc80b9b5abd435cf86ccc1 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 25 Mar 2015 12:36:52 -0700 Subject: [PATCH 2/3] Fix variable dollar-char errors --- cluster/aws/util.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cluster/aws/util.sh b/cluster/aws/util.sh index 065fef7a4bb..2b92ed82324 100644 --- a/cluster/aws/util.sh +++ b/cluster/aws/util.sh @@ -658,7 +658,7 @@ EOF fi echo -e " ${color_yellow}[not working yet]${color_norm}" # Start Docker, in case it failed to start. - ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@$$minion_ip sudo service docker start > $LOG 2>&1 + ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@$minion_ip sudo service docker start > $LOG 2>&1 attempt=$(($attempt+1)) sleep 30 done @@ -805,7 +805,7 @@ function ssh-to-node { local cmd="$2" local ip=$(get_instance_public_ip ${node}) - if [[ -z "ip" ]]; then + if [[ -z "$ip" ]]; then echo "Could not detect IP for ${node}." exit 1 fi From ac12665f4846ed23f640b5beaf6f9b82ed749b02 Mon Sep 17 00:00:00 2001 From: Justin Santa Barbara Date: Wed, 25 Mar 2015 12:41:02 -0700 Subject: [PATCH 3/3] Quote AWS_SSH_KEY --- cluster/aws/util.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cluster/aws/util.sh b/cluster/aws/util.sh index 2b92ed82324..fb2d0c9c9b4 100644 --- a/cluster/aws/util.sh +++ b/cluster/aws/util.sh @@ -341,13 +341,13 @@ function kube-up { local htpasswd htpasswd=$(cat "${KUBE_TEMP}/htpasswd") - if [[ ! -f $AWS_SSH_KEY ]]; then - ssh-keygen -f $AWS_SSH_KEY -N '' + if [[ ! -f "$AWS_SSH_KEY" ]]; then + ssh-keygen -f "$AWS_SSH_KEY" -N '' fi detect-image - $AWS_CMD import-key-pair --key-name kubernetes --public-key-material file://$AWS_SSH_KEY.pub > $LOG 2>&1 || true + $AWS_CMD import-key-pair --key-name kubernetes --public-key-material "file://$AWS_SSH_KEY.pub" > $LOG 2>&1 || true VPC_ID=$($AWS_CMD describe-vpcs | get_vpc_id) @@ -474,7 +474,7 @@ function kube-up { while true; do echo -n Attempt "$(($attempt+1))" to check for salt-master local output - output=$(ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@${KUBE_MASTER_IP} pgrep salt-master 2> $LOG) || output="" + output=$(ssh -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@${KUBE_MASTER_IP} pgrep salt-master 2> $LOG) || output="" if [[ -z "${output}" ]]; then if (( attempt > 30 )); then echo @@ -561,7 +561,7 @@ function kube-up { sleep 10 done echo "Re-running salt highstate" - ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@${KUBE_MASTER_IP} sudo salt '*' state.highstate > $LOG + ssh -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@${KUBE_MASTER_IP} sudo salt '*' state.highstate > $LOG echo "Waiting for cluster initialization." echo @@ -594,9 +594,9 @@ function kube-up { ( mkdir -p "${config_dir}" umask 077 - ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@${KUBE_MASTER_IP} sudo cat /srv/kubernetes/kubecfg.crt >"${config_dir}/${kube_cert}" 2>$LOG - ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@${KUBE_MASTER_IP} sudo cat /srv/kubernetes/kubecfg.key >"${config_dir}/${kube_key}" 2>$LOG - ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@${KUBE_MASTER_IP} sudo cat /srv/kubernetes/ca.crt >"${config_dir}/${ca_cert}" 2>$LOG + ssh -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@${KUBE_MASTER_IP} sudo cat /srv/kubernetes/kubecfg.crt >"${config_dir}/${kube_cert}" 2>$LOG + ssh -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@${KUBE_MASTER_IP} sudo cat /srv/kubernetes/kubecfg.key >"${config_dir}/${kube_key}" 2>$LOG + ssh -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@${KUBE_MASTER_IP} sudo cat /srv/kubernetes/ca.crt >"${config_dir}/${ca_cert}" 2>$LOG "${kubectl}" config set-cluster "${context}" --server="https://${KUBE_MASTER_IP}" --certificate-authority="${config_dir}/${ca_cert}" --global "${kubectl}" config set-credentials "${user}" --auth-path="${config_dir}/${kube_auth}" --global @@ -634,7 +634,7 @@ EOF local minion_name=${MINION_NAMES[$i]} local minion_ip=${KUBE_MINION_IP_ADDRESSES[$i]} echo -n Attempt "$(($attempt+1))" to check Docker on node "${minion_name} @ ${minion_ip}" ... - local output=$(ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@$minion_ip sudo docker ps -a 2>/dev/null) + local output=$(ssh -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@$minion_ip sudo docker ps -a 2>/dev/null) if [[ -z "${output}" ]]; then if (( attempt > 9 )); then echo @@ -658,7 +658,7 @@ EOF fi echo -e " ${color_yellow}[not working yet]${color_norm}" # Start Docker, in case it failed to start. - ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@$minion_ip sudo service docker start > $LOG 2>&1 + ssh -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@$minion_ip sudo service docker start > $LOG 2>&1 attempt=$(($attempt+1)) sleep 30 done @@ -758,7 +758,7 @@ function kube-push { echo "echo Executing configuration" echo "sudo salt '*' mine.update" echo "sudo salt --force-color '*' state.highstate" - ) | ssh -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@${KUBE_MASTER_IP} sudo bash + ) | ssh -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@${KUBE_MASTER_IP} sudo bash get-password @@ -811,7 +811,7 @@ function ssh-to-node { fi for try in $(seq 1 5); do - if ssh -oLogLevel=quiet -oStrictHostKeyChecking=no -i ${AWS_SSH_KEY} ubuntu@${ip} "${cmd}"; then + if ssh -oLogLevel=quiet -oStrictHostKeyChecking=no -i "${AWS_SSH_KEY}" ubuntu@${ip} "${cmd}"; then break fi done