fix: add functions to restart k3s services and wait for readiness in deployment workflow
This commit is contained in:
@@ -695,30 +695,68 @@ jobs:
|
||||
echo "Sudo mode: ${SUDO_MODE}"
|
||||
kubectl_cmd version --client
|
||||
|
||||
check_plain_http_registry() {
|
||||
restart_k3s_service() {
|
||||
for unit in k3s k3s-server k3s-agent; do
|
||||
if sudo_cmd systemctl is-active "${unit}" >/dev/null 2>&1; then
|
||||
echo "Restarting systemd unit ${unit}..."
|
||||
sudo_cmd systemctl restart "${unit}"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
for svc in k3s k3s-server k3s-agent; do
|
||||
if [ -x "/etc/init.d/${svc}" ]; then
|
||||
echo "Restarting init.d service ${svc}..."
|
||||
sudo_cmd "/etc/init.d/${svc}" restart
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
echo "Cannot find a k3s service unit to restart."
|
||||
echo "Manually restart k3s on the NAS, then re-run this workflow."
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_k3s_ready() {
|
||||
i=0
|
||||
while [ "${i}" -lt 60 ]; do
|
||||
if kubectl_cmd get --raw=/readyz >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
i=$((i + 1))
|
||||
sleep 2
|
||||
done
|
||||
echo "k3s API did not return to ready within 120s."
|
||||
return 1
|
||||
}
|
||||
|
||||
ensure_plain_http_registry() {
|
||||
if [ "${REGISTRY_PLAIN_HTTP}" != "true" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
registry_file="/etc/rancher/k3s/registries.yaml"
|
||||
if ! sudo_cmd test -f "${registry_file}"; then
|
||||
echo "Gitea Registry is configured as plain HTTP, but ${registry_file} does not exist."
|
||||
echo "Create it on the NAS before deployment:"
|
||||
echo "mirrors:"
|
||||
echo " \"${REGISTRY_HOST}\":"
|
||||
echo " endpoint:"
|
||||
echo " - \"http://${REGISTRY_HOST}\""
|
||||
echo "Then restart k3s."
|
||||
desired_endpoint="http://${REGISTRY_HOST}"
|
||||
|
||||
if sudo_cmd test -f "${registry_file}" \
|
||||
&& sudo_cmd grep -F "${desired_endpoint}" "${registry_file}" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "Writing k3s plain-HTTP mirror config to ${registry_file}..."
|
||||
registry_yaml="$(printf 'mirrors:\n "%s":\n endpoint:\n - "%s"\n' \
|
||||
"${REGISTRY_HOST}" "${desired_endpoint}")"
|
||||
|
||||
if ! printf '%s' "${registry_yaml}" | sudo_cmd tee "${registry_file}" >/dev/null; then
|
||||
echo "Failed to write ${registry_file} via sudo."
|
||||
echo "Create it manually on the NAS with:"
|
||||
echo "${registry_yaml}"
|
||||
echo "and restart k3s, then re-run this workflow."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! sudo_cmd grep -F "http://${REGISTRY_HOST}" "${registry_file}" >/dev/null 2>&1; then
|
||||
echo "Gitea Registry is configured as plain HTTP, but ${registry_file} does not contain http://${REGISTRY_HOST}."
|
||||
echo "Add this mirror endpoint and restart k3s:"
|
||||
echo "mirrors:"
|
||||
echo " \"${REGISTRY_HOST}\":"
|
||||
echo " endpoint:"
|
||||
echo " - \"http://${REGISTRY_HOST}\""
|
||||
if ! restart_k3s_service; then
|
||||
exit 1
|
||||
fi
|
||||
if ! wait_for_k3s_ready; then
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
@@ -897,9 +935,11 @@ jobs:
|
||||
esac
|
||||
}
|
||||
|
||||
if [ -n "${IMAGE_LIST}" ]; then
|
||||
ensure_plain_http_registry
|
||||
fi
|
||||
ensure_namespace
|
||||
if [ -n "${IMAGE_LIST}" ]; then
|
||||
check_plain_http_registry
|
||||
ensure_registry_secret
|
||||
else
|
||||
echo "No application images selected; skipping registry pull-secret setup."
|
||||
|
||||
Reference in New Issue
Block a user