mirror of https://github.com/k3s-io/k3s
Merge pull request #49888 from MrHohn/addon-manager-remove-old-codes
Automatic merge from submit-queue [addon-manager] Remove unneeded annotation codes **What this PR does / why we need it**: Clean up addon-manager codes to make it less confusing. The annotation logics is only needed for 1.4->1.5 upgrade. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```pull/6/head
commit
a422196142
|
@ -115,26 +115,7 @@ function create_resource_from_string() {
|
|||
return 1;
|
||||
}
|
||||
|
||||
# $1 resource type.
|
||||
function annotate_addons() {
|
||||
local -r obj_type=$1;
|
||||
|
||||
# Annotate to objects already have this annotation should fail.
|
||||
# Only try once for now.
|
||||
${KUBECTL} ${KUBECTL_OPTS} annotate ${obj_type} --namespace=${SYSTEM_NAMESPACE} -l ${CLUSTER_SERVICE_LABEL}=true \
|
||||
kubectl.kubernetes.io/last-applied-configuration='' --overwrite=false
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
log INFO "== Annotate resources completed successfully at $(date -Is) =="
|
||||
else
|
||||
log WRN "== Annotate resources completed with errors at $(date -Is) =="
|
||||
fi
|
||||
}
|
||||
|
||||
# $1 enable --prune or not.
|
||||
function reconcile_addons() {
|
||||
local -r enable_prune=$1;
|
||||
|
||||
# TODO: Remove the first command in future release.
|
||||
# Adding this for backward compatibility. Old addons have CLUSTER_SERVICE_LABEL=true and don't have
|
||||
# ADDON_MANAGER_LABEL=EnsureExists will still be reconciled.
|
||||
|
@ -143,12 +124,12 @@ function reconcile_addons() {
|
|||
log INFO "== Reconciling with deprecated label =="
|
||||
${KUBECTL} ${KUBECTL_OPTS} apply --namespace=${SYSTEM_NAMESPACE} -f ${ADDON_PATH} \
|
||||
-l ${CLUSTER_SERVICE_LABEL}=true,${ADDON_MANAGER_LABEL}!=EnsureExists \
|
||||
--prune=${enable_prune} --recursive | grep -v configured
|
||||
--prune=true --recursive | grep -v configured
|
||||
|
||||
log INFO "== Reconciling with addon-manager label =="
|
||||
${KUBECTL} ${KUBECTL_OPTS} apply --namespace=${SYSTEM_NAMESPACE} -f ${ADDON_PATH} \
|
||||
-l ${CLUSTER_SERVICE_LABEL}!=true,${ADDON_MANAGER_LABEL}=Reconcile \
|
||||
--prune=${enable_prune} --recursive | grep -v configured
|
||||
--prune=true --recursive | grep -v configured
|
||||
|
||||
log INFO "== Kubernetes addon reconcile completed at $(date -Is) =="
|
||||
}
|
||||
|
@ -191,38 +172,14 @@ for obj in $(find /etc/kubernetes/admission-controls \( -name \*.yaml -o -name \
|
|||
log INFO "++ obj ${obj} is created ++"
|
||||
done
|
||||
|
||||
# TODO: The annotate and spin up parts should be removed after 1.6 is released.
|
||||
|
||||
# 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 migrated from RCs to deployments for all default addons in 1.5.
|
||||
# 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
|
||||
annotate_addons Deployment
|
||||
|
||||
# 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) =="
|
||||
ensure_addons
|
||||
reconcile_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
|
||||
# created/updated/deleted the files on the master.
|
||||
log INFO "== Entering periodical apply loop at $(date -Is) =="
|
||||
while true; do
|
||||
start_sec=$(date +"%s")
|
||||
# Only print stderr for the readability of logging
|
||||
ensure_addons
|
||||
reconcile_addons true
|
||||
reconcile_addons
|
||||
end_sec=$(date +"%s")
|
||||
len_sec=$((${end_sec}-${start_sec}))
|
||||
# subtract the time passed from the sleep time
|
||||
|
|
Loading…
Reference in New Issue