From 541219db77efec9af832b72eeb3892f768eb0f9b Mon Sep 17 00:00:00 2001 From: Abhishek Shah Date: Mon, 30 Mar 2015 18:14:54 -0700 Subject: [PATCH] Retry kube-addons creation if kube-addons creation fails. --- cluster/saltbase/salt/kube-addons/initd | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/cluster/saltbase/salt/kube-addons/initd b/cluster/saltbase/salt/kube-addons/initd index 8cc1d422b5d..702d74ace4f 100644 --- a/cluster/saltbase/salt/kube-addons/initd +++ b/cluster/saltbase/salt/kube-addons/initd @@ -26,14 +26,32 @@ KUBECTL=/usr/local/bin/kubectl # and status_of_proc is working. . /lib/lsb/init-functions +# $1 addon to start. +# $2 count of tries to start the addon. +# $3 delay in seconds between two consecutive tries +function start_addon() { + addon=$1; + tries=$2; + delay=$3; + while [ ${tries} -gt 0 ]; do + ${KUBECTL} create -f ${addon} && \ + echo "== Successfully started ${addon} at $(date -Is)" && \ + return 0; + let tries=tries-1; + echo "== Failed to start ${addon} at $(date -Is). ${tries} tries remaining. ==" + sleep ${delay}; + done + return 1; +} + function addon_manager_async() { # The business logic for whether a given object should be created # was already enforced by salt, and /etc/kubernetes/addons is the # managed result is of that. Start everything below that directory. echo "== Kubernetes addon manager started at $(date -Is) ==" for obj in $(find /etc/kubernetes/addons -name \*.yaml); do - ${KUBECTL} create -f ${obj} & - echo "++ addon ${obj} started in pid $! ++" + start_addon ${obj} 100 10 & + echo "++ addon ${obj} starting in pid $! ++" done noerrors="true" for pid in $(jobs -p); do @@ -52,6 +70,7 @@ function addon_manager_async() { sleep infinity } + # # Function that starts the daemon/service #