From b9570b3daa8f8a502b0716fe05717c217fa0173b Mon Sep 17 00:00:00 2001 From: Eric Tune Date: Thu, 2 Apr 2015 14:07:23 -0700 Subject: [PATCH] Use same addons script for init.d and systemd. --- cluster/saltbase/salt/kube-addons/init.sls | 14 +++--- cluster/saltbase/salt/kube-addons/initd | 46 +------------------ .../saltbase/salt/kube-addons/kube-addons.sh | 31 ++++++++----- 3 files changed, 29 insertions(+), 62 deletions(-) diff --git a/cluster/saltbase/salt/kube-addons/init.sls b/cluster/saltbase/salt/kube-addons/init.sls index 8bb0a29135a10..a38adb62556d0 100644 --- a/cluster/saltbase/salt/kube-addons/init.sls +++ b/cluster/saltbase/salt/kube-addons/init.sls @@ -48,20 +48,20 @@ - makedirs: True {% endif %} -{% if grains['os_family'] == 'RedHat' %} - -/usr/lib/systemd/system/kube-addons.service: +/etc/kubernetes/kube-addons.sh: file.managed: - - source: salt://kube-addons/kube-addons.service + - source: salt://kube-addons/kube-addons.sh - user: root - group: root + - mode: 755 -/etc/kubernetes/kube-addons.sh: +{% if grains['os_family'] == 'RedHat' %} + +/usr/lib/systemd/system/kube-addons.service: file.managed: - - source: salt://kube-addons/kube-addons.sh + - source: salt://kube-addons/kube-addons.service - user: root - group: root - - mode: 755 {% else %} diff --git a/cluster/saltbase/salt/kube-addons/initd b/cluster/saltbase/salt/kube-addons/initd index 702d74ace4f2e..6b06e8c7cd16c 100644 --- a/cluster/saltbase/salt/kube-addons/initd +++ b/cluster/saltbase/salt/kube-addons/initd @@ -19,56 +19,14 @@ NAME=kube-addons DAEMON_LOG_FILE=/var/log/$NAME.log PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME -KUBECTL=/usr/local/bin/kubectl +KUBE_ADDONS_SH=/etc/kubernetes/kube-addons.sh # Define LSB log_* functions. # Depend on lsb-base (>= 3.2-14) to ensure that this file is present # 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 - start_addon ${obj} 100 10 & - echo "++ addon ${obj} starting in pid $! ++" - done - noerrors="true" - for pid in $(jobs -p); do - wait ${pid} || noerrors="false" - echo "++ pid ${pid} complete ++" - done - if [ ${noerrors} == "true" ]; then - echo "== Kubernetes addon manager completed successfully at $(date -Is) ==" - else - echo "== Kubernetes addon manager completed with errors at $(date -Is) ==" - fi - # We stay around so that status checks by salt make it look like - # the service is good. (We could do this is other ways, but this - # is simple.) - sleep infinity -} # @@ -76,7 +34,7 @@ function addon_manager_async() { # do_start() { - addon_manager_async >${DAEMON_LOG_FILE} 2>&1 & + ${KUBE_ADDONS_SH} >${DAEMON_LOG_FILE} 2>&1 & echo $! > ${PIDFILE} disown } diff --git a/cluster/saltbase/salt/kube-addons/kube-addons.sh b/cluster/saltbase/salt/kube-addons/kube-addons.sh index 593d57b93d9d5..e68fc15baf22d 100644 --- a/cluster/saltbase/salt/kube-addons/kube-addons.sh +++ b/cluster/saltbase/salt/kube-addons/kube-addons.sh @@ -19,22 +19,31 @@ # managed result is of that. Start everything below that directory. KUBECTL=/usr/local/bin/kubectl -function create-object() { - obj=$1 - - for tries in {1..5}; do - if ${KUBECTL} --server="127.0.0.1:8080" create --validate=true -f ${obj}; then - return - fi - echo "++ ${obj} failed, attempt ${try} (sleeping 5) ++" - sleep 5 +# $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; } +# 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 - create-object ${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