log INFO "== Kubernetes addon update completed successfully at $(date-Is) =="
else
log WRN "== Kubernetes addon update completed with errors at $(date-Is) =="
fi
}
# The business logic for whether a given object should be created
# The business logic for whether a given object should be created
# was already enforced by salt, and /etc/kubernetes/addons is the
# was already enforced by salt, and /etc/kubernetes/addons is the
# managed result is of that. Start everything below that directory.
# managed result is of that. Start everything below that directory.
echo"== Kubernetes addon manager started at $(date-Is) with ADDON_CHECK_INTERVAL_SEC=${ADDON_CHECK_INTERVAL_SEC} =="
log INFO"== Kubernetes addon manager started at $(date-Is) with ADDON_CHECK_INTERVAL_SEC=${ADDON_CHECK_INTERVAL_SEC} =="
# Create the namespace that will be used to host the cluster-level add-ons.
# Create the namespace that will be used to host the cluster-level add-ons.
start_addon /opt/namespace.yaml 100 10 "" &
start_addon /opt/namespace.yaml 100 10 "" &
...
@@ -75,22 +175,43 @@ while [ -z "${token_found}" ]; do
...
@@ -75,22 +175,43 @@ while [ -z "${token_found}" ]; do
token_found=$(${KUBECTL}${KUBECTL_OPTS} get --namespace="${SYSTEM_NAMESPACE}" serviceaccount default -o go-template="{{with index .secrets 0}}{{.name}}{{end}}"||true)
token_found=$(${KUBECTL}${KUBECTL_OPTS} get --namespace="${SYSTEM_NAMESPACE}" serviceaccount default -o go-template="{{with index .secrets 0}}{{.name}}{{end}}"||true)
done
done
echo"== default service account in the ${SYSTEM_NAMESPACE} namespace has token ${token_found} =="
log INFO "== Default service account in the ${SYSTEM_NAMESPACE} namespace has token ${token_found} =="
# Create admission_control objects if defined before any other addon services. If the limits
# Create admission_control objects if defined before any other addon services. If the limits
# are defined in a namespace other than default, we should still create the limits for the
# are defined in a namespace other than default, we should still create the limits for the
# default namespace.
# default namespace.
for obj in$(find /etc/kubernetes/admission-controls \(-name\*.yaml -o-name\*.json \));do
for obj in$(find /etc/kubernetes/admission-controls \(-name\*.yaml -o-name\*.json \));do
start_addon "${obj}" 100 10 default &
start_addon "${obj}" 100 10 default &
echo"++ obj ${obj} is created ++"
log INFO"++ obj ${obj} is created ++"
done
done
# Fake the "kubectl.kubernetes.io/last-applied-configuration" annotation on old resources
# in order to clean them up by `kubectl apply --prune`.
# RCs have to be annotated for 1.4->1.5 upgrade, because we are migrating from RCs to deployments for all default addons.
# Other types resources will also need this fake annotation if their names are changed,
# otherwise they would be leaked during upgrade.
log INFO "== Annotating the old addon resources at $(date-Is) =="
annotate_addons ReplicationController
# Create new addon resources by apply (with --prune=false).
# The old RCs will not fight for pods created by new Deployments with the same label because the `controllerRef` feature.
# The new Deployments will not fight for pods created by old RCs with the same label because the additional `pod-template-hash` label.
# Apply will fail if some fields are modified but not are allowed, in that case should bump up addon version and name (e.g. handle externally).
log INFO "== Executing apply to spin up new addon resources at $(date-Is) =="
update_addons false
# Wait for new addons to be spinned up before delete old resources
log INFO "== Wait for addons to be spinned up at $(date-Is) =="
sleep${ADDON_CHECK_INTERVAL_SEC}
# Start the apply loop.
# Check if the configuration has changed recently - in case the user
# Check if the configuration has changed recently - in case the user
# created/updated/deleted the files on the master.
# created/updated/deleted the files on the master.
log INFO "== Entering periodical apply loop at $(date-Is) =="
while true;do
while true;do
start_sec=$(date +"%s")
start_sec=$(date +"%s")
#kube-addon-update.sh must be deployed in the same directory as this file
# Only print stderr for the readability of logging