Kubemark scripts retry failed gcloud commands

This commit is contained in:
Marcin Wielgus 2016-01-26 17:07:15 +01:00
parent 6c63acdd3d
commit 39428cc0e5
2 changed files with 50 additions and 30 deletions

View File

@ -16,6 +16,7 @@
source "${KUBE_ROOT}/cluster/kubemark/config-default.sh" source "${KUBE_ROOT}/cluster/kubemark/config-default.sh"
source "${KUBE_ROOT}/cluster/kubemark/util.sh" source "${KUBE_ROOT}/cluster/kubemark/util.sh"
source "${KUBE_ROOT}/cluster/kube-env.sh"
detect-project &> /dev/null detect-project &> /dev/null
export PROJECT export PROJECT
@ -23,3 +24,22 @@ export PROJECT
MASTER_NAME="${INSTANCE_PREFIX}-kubemark-master" MASTER_NAME="${INSTANCE_PREFIX}-kubemark-master"
MASTER_TAG="kubemark-master" MASTER_TAG="kubemark-master"
EVENT_STORE_NAME="${INSTANCE_PREFIX}-event-store" EVENT_STORE_NAME="${INSTANCE_PREFIX}-event-store"
RETRIES=3
# Runs gcloud compute command with the given parameters. Up to $RETRIES will be made
# to execute the command.
# arguments:
# $@: all stuff that goes after 'gcloud compute '
function run-gcloud-compute-with-retries {
for attempt in $(seq 1 ${RETRIES}); do
if ! gcloud compute $@; then
echo -e "${color_yellow}Attempt ${attempt} failed to $@. Retrying.${color_norm}" >& 2
sleep $(($attempt * 5))
else
return
fi
done
echo -e "${color_red} Failed to $@.${color_norm}" >& 2
exit 1
}

View File

@ -46,12 +46,12 @@ cd $CURR_DIR
GCLOUD_COMMON_ARGS="--project ${PROJECT} --zone ${ZONE}" GCLOUD_COMMON_ARGS="--project ${PROJECT} --zone ${ZONE}"
gcloud compute disks create "${MASTER_NAME}-pd" \ run-gcloud-compute-with-retries disks create "${MASTER_NAME}-pd" \
${GCLOUD_COMMON_ARGS} \ ${GCLOUD_COMMON_ARGS} \
--type "${MASTER_DISK_TYPE}" \ --type "${MASTER_DISK_TYPE}" \
--size "${MASTER_DISK_SIZE}" --size "${MASTER_DISK_SIZE}"
gcloud compute instances create "${MASTER_NAME}" \ run-gcloud-compute-with-retries instances create "${MASTER_NAME}" \
${GCLOUD_COMMON_ARGS} \ ${GCLOUD_COMMON_ARGS} \
--machine-type "${MASTER_SIZE}" \ --machine-type "${MASTER_SIZE}" \
--image-project="${MASTER_IMAGE_PROJECT}" \ --image-project="${MASTER_IMAGE_PROJECT}" \
@ -61,7 +61,7 @@ gcloud compute instances create "${MASTER_NAME}" \
--scopes "storage-ro,compute-rw,logging-write" \ --scopes "storage-ro,compute-rw,logging-write" \
--disk "name=${MASTER_NAME}-pd,device-name=master-pd,mode=rw,boot=no,auto-delete=no" --disk "name=${MASTER_NAME}-pd,device-name=master-pd,mode=rw,boot=no,auto-delete=no"
gcloud compute firewall-rules create "${INSTANCE_PREFIX}-kubemark-master-https" \ run-gcloud-compute-with-retries firewall-rules create "${INSTANCE_PREFIX}-kubemark-master-https" \
--project "${PROJECT}" \ --project "${PROJECT}" \
--network "${NETWORK}" \ --network "${NETWORK}" \
--source-ranges "0.0.0.0/0" \ --source-ranges "0.0.0.0/0" \
@ -73,12 +73,12 @@ MASTER_IP=$(gcloud compute instances describe ${MASTER_NAME} \
if [ "${SEPARATE_EVENT_MACHINE:-false}" == "true" ]; then if [ "${SEPARATE_EVENT_MACHINE:-false}" == "true" ]; then
EVENT_STORE_NAME="${INSTANCE_PREFIX}-event-store" EVENT_STORE_NAME="${INSTANCE_PREFIX}-event-store"
gcloud compute disks create "${EVENT_STORE_NAME}-pd" \ run-gcloud-compute-with-retries disks create "${EVENT_STORE_NAME}-pd" \
${GCLOUD_COMMON_ARGS} \ ${GCLOUD_COMMON_ARGS} \
--type "${MASTER_DISK_TYPE}" \ --type "${MASTER_DISK_TYPE}" \
--size "${MASTER_DISK_SIZE}" --size "${MASTER_DISK_SIZE}"
gcloud compute instances create "${EVENT_STORE_NAME}" \ run-gcloud-compute-with-retries instances create "${EVENT_STORE_NAME}" \
${GCLOUD_COMMON_ARGS} \ ${GCLOUD_COMMON_ARGS} \
--machine-type "${MASTER_SIZE}" \ --machine-type "${MASTER_SIZE}" \
--image-project="${MASTER_IMAGE_PROJECT}" \ --image-project="${MASTER_IMAGE_PROJECT}" \