mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Use same addons script for init.d and systemd.
This commit is contained in:
parent
25724f7e31
commit
b9570b3daa
@ -48,6 +48,13 @@
|
|||||||
- makedirs: True
|
- makedirs: True
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
/etc/kubernetes/kube-addons.sh:
|
||||||
|
file.managed:
|
||||||
|
- source: salt://kube-addons/kube-addons.sh
|
||||||
|
- user: root
|
||||||
|
- group: root
|
||||||
|
- mode: 755
|
||||||
|
|
||||||
{% if grains['os_family'] == 'RedHat' %}
|
{% if grains['os_family'] == 'RedHat' %}
|
||||||
|
|
||||||
/usr/lib/systemd/system/kube-addons.service:
|
/usr/lib/systemd/system/kube-addons.service:
|
||||||
@ -56,13 +63,6 @@
|
|||||||
- user: root
|
- user: root
|
||||||
- group: root
|
- group: root
|
||||||
|
|
||||||
/etc/kubernetes/kube-addons.sh:
|
|
||||||
file.managed:
|
|
||||||
- source: salt://kube-addons/kube-addons.sh
|
|
||||||
- user: root
|
|
||||||
- group: root
|
|
||||||
- mode: 755
|
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
/etc/init.d/kube-addons:
|
/etc/init.d/kube-addons:
|
||||||
|
@ -19,56 +19,14 @@ NAME=kube-addons
|
|||||||
DAEMON_LOG_FILE=/var/log/$NAME.log
|
DAEMON_LOG_FILE=/var/log/$NAME.log
|
||||||
PIDFILE=/var/run/$NAME.pid
|
PIDFILE=/var/run/$NAME.pid
|
||||||
SCRIPTNAME=/etc/init.d/$NAME
|
SCRIPTNAME=/etc/init.d/$NAME
|
||||||
KUBECTL=/usr/local/bin/kubectl
|
KUBE_ADDONS_SH=/etc/kubernetes/kube-addons.sh
|
||||||
|
|
||||||
# Define LSB log_* functions.
|
# Define LSB log_* functions.
|
||||||
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
|
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
|
||||||
# and status_of_proc is working.
|
# and status_of_proc is working.
|
||||||
. /lib/lsb/init-functions
|
. /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()
|
do_start()
|
||||||
{
|
{
|
||||||
addon_manager_async </dev/null >>${DAEMON_LOG_FILE} 2>&1 &
|
${KUBE_ADDONS_SH} </dev/null >>${DAEMON_LOG_FILE} 2>&1 &
|
||||||
echo $! > ${PIDFILE}
|
echo $! > ${PIDFILE}
|
||||||
disown
|
disown
|
||||||
}
|
}
|
||||||
|
@ -19,22 +19,31 @@
|
|||||||
# managed result is of that. Start everything below that directory.
|
# managed result is of that. Start everything below that directory.
|
||||||
KUBECTL=/usr/local/bin/kubectl
|
KUBECTL=/usr/local/bin/kubectl
|
||||||
|
|
||||||
function create-object() {
|
# $1 addon to start.
|
||||||
obj=$1
|
# $2 count of tries to start the addon.
|
||||||
|
# $3 delay in seconds between two consecutive tries
|
||||||
for tries in {1..5}; do
|
function start_addon() {
|
||||||
if ${KUBECTL} --server="127.0.0.1:8080" create --validate=true -f ${obj}; then
|
addon=$1;
|
||||||
return
|
tries=$2;
|
||||||
fi
|
delay=$3;
|
||||||
echo "++ ${obj} failed, attempt ${try} (sleeping 5) ++"
|
while [ ${tries} -gt 0 ]; do
|
||||||
sleep 5
|
${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
|
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) =="
|
echo "== Kubernetes addon manager started at $(date -Is) =="
|
||||||
for obj in $(find /etc/kubernetes/addons -name \*.yaml); do
|
for obj in $(find /etc/kubernetes/addons -name \*.yaml); do
|
||||||
create-object ${obj} &
|
start_addon ${obj} 100 10 &
|
||||||
echo "++ addon ${obj} started in pid $! ++"
|
echo "++ addon ${obj} starting in pid $! ++"
|
||||||
done
|
done
|
||||||
noerrors="true"
|
noerrors="true"
|
||||||
for pid in $(jobs -p); do
|
for pid in $(jobs -p); do
|
||||||
|
Loading…
Reference in New Issue
Block a user