From 6dca871693781230625b8ac777e6f0717940b652 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 3 Mar 2016 08:20:12 -0800 Subject: [PATCH] Check static IP postcondition if op fails --- cluster/gce/util.sh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index a03adaae02b..2ebb2a579c4 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -298,19 +298,27 @@ function create-static-ip { local attempt=0 local REGION="$2" while true; do - if ! gcloud compute addresses create "$1" \ + if gcloud compute addresses create "$1" \ --project "${PROJECT}" \ --region "${REGION}" -q > /dev/null; then - if (( attempt > 4 )); then - echo -e "${color_red}Failed to create static ip $1 ${color_norm}" >&2 - exit 2 - fi - attempt=$(($attempt+1)) - echo -e "${color_yellow}Attempt $attempt failed to create static ip $1. Retrying.${color_norm}" >&2 - sleep $(($attempt * 5)) - else + # successful operation break fi + + if cloud compute addresses describe "$1" \ + --project "${PROJECT}" \ + --region "${REGION}" >/dev/null 2>&1; then + # it exists - postcondition satisfied + break + fi + + if (( attempt > 4 )); then + echo -e "${color_red}Failed to create static ip $1 ${color_norm}" >&2 + exit 2 + fi + attempt=$(($attempt+1)) + echo -e "${color_yellow}Attempt $attempt failed to create static ip $1. Retrying.${color_norm}" >&2 + sleep $(($attempt * 5)) done }