Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same addons script for init.d and systemd. #6384

Merged
merged 1 commit into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cluster/saltbase/salt/kube-addons/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
46 changes: 2 additions & 44 deletions cluster/saltbase/salt/kube-addons/initd
Original file line number Diff line number Diff line change
Expand Up @@ -19,64 +19,22 @@ 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
}


#
# Function that starts the daemon/service
#
do_start()
{
addon_manager_async </dev/null >>${DAEMON_LOG_FILE} 2>&1 &
${KUBE_ADDONS_SH} </dev/null >>${DAEMON_LOG_FILE} 2>&1 &
echo $! > ${PIDFILE}
disown
}
Expand Down
31 changes: 20 additions & 11 deletions cluster/saltbase/salt/kube-addons/kube-addons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make these locals in this PR and save some time in the other? :)

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
Expand Down