Render valid self-heal working directory and verify units before install
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-30 09:47:32 -06:00
parent 4241954fe1
commit 4850c31335
2 changed files with 17 additions and 2 deletions

View File

@ -10,6 +10,9 @@ The installer records the selected profile, explicit kubeconfig, and current
checkout path in the systemd unit. It restarts the webhook so new source and checkout path in the systemd unit. It restarts the webhook so new source and
environment settings take effect. Without `--apply`, installation defaults to environment settings take effect. Without `--apply`, installation defaults to
dry-run mode unless `LAB_SELF_HEAL_APPLY=true` is explicitly supplied. dry-run mode unless `LAB_SELF_HEAL_APPLY=true` is explicitly supplied.
The rendered file is staged with its `.service` filename and checked using
`systemd-analyze verify --man=no` on Debian before replacing the installed unit.
An invalid rendered unit therefore leaves the existing unit file untouched.
`HomelabStaleResidualPods`, `KubePodEvicted`, and `HomelabStaleResidualPods`, `KubePodEvicted`, and
`KubePodContainerStatusUnknown` select the guarded stale-pod cleanup directly. `KubePodContainerStatusUnknown` select the guarded stale-pod cleanup directly.

View File

@ -3615,6 +3615,7 @@ self_heal() {
if [ "${2:-}" = "install-service" ]; then if [ "${2:-}" = "install-service" ]; then
local apply_mode local apply_mode
local service_file local service_file
local service_stage
apply_mode="${LAB_SELF_HEAL_APPLY:-false}" apply_mode="${LAB_SELF_HEAL_APPLY:-false}"
if [ "${3:-}" = "--apply" ]; then if [ "${3:-}" = "--apply" ]; then
@ -3628,7 +3629,8 @@ self_heal() {
echo "Self-heal kubeconfig is not readable: ${KUBECONFIG}" >&2 echo "Self-heal kubeconfig is not readable: ${KUBECONFIG}" >&2
return 1 return 1
fi fi
service_file="$(mktemp)" service_stage="$(mktemp -d "${TMPDIR:-/tmp}/jeannie-eventd-unit.XXXXXXXX")"
service_file="${service_stage}/jeannie-eventd.service"
if ! python3 - "${REPO_ROOT}/infra/jeannie-eventd/jeannie-eventd.service" \ if ! python3 - "${REPO_ROOT}/infra/jeannie-eventd/jeannie-eventd.service" \
"${REPO_ROOT}" "${LAB_CLUSTER_PROFILE}" "${KUBECONFIG}" "${apply_mode}" >"${service_file}" <<'PY' "${REPO_ROOT}" "${LAB_CLUSTER_PROFILE}" "${KUBECONFIG}" "${apply_mode}" >"${service_file}" <<'PY'
from pathlib import Path from pathlib import Path
@ -3642,7 +3644,9 @@ def quote_unit(value):
return '"' + value.replace("\\", "\\\\").replace('"', '\\"').replace("%", "%%") + '"' return '"' + value.replace("\\", "\\\\").replace('"', '\\"').replace("%", "%%") + '"'
replacements = { replacements = {
"WorkingDirectory": quote_unit(repo), # WorkingDirectory takes a literal absolute path, unlike the shell-word
# parsing used by ExecStart and Environment. Quotes become path characters.
"WorkingDirectory": repo.replace("%", "%%"),
"ExecStart": quote_unit(repo + "/scripts/jeannie-eventd") + " serve", "ExecStart": quote_unit(repo + "/scripts/jeannie-eventd") + " serve",
"Environment=LAB_CLUSTER_PROFILE": quote_unit("LAB_CLUSTER_PROFILE=" + profile), "Environment=LAB_CLUSTER_PROFILE": quote_unit("LAB_CLUSTER_PROFILE=" + profile),
"Environment=KUBECONFIG": quote_unit("KUBECONFIG=" + kubeconfig), "Environment=KUBECONFIG": quote_unit("KUBECONFIG=" + kubeconfig),
@ -3659,11 +3663,19 @@ for line in Path(template).read_text().splitlines():
PY PY
then then
rm -f "${service_file}" rm -f "${service_file}"
rmdir "${service_stage}"
echo "Self-heal service rendering failed; existing service preserved." >&2 echo "Self-heal service rendering failed; existing service preserved." >&2
return 1 return 1
fi fi
if ! sudo systemd-analyze verify --man=no "${service_file}"; then
rm -f "${service_file}"
rmdir "${service_stage}"
echo "Self-heal unit validation failed; existing service preserved." >&2
return 1
fi
sudo install -m 0644 "${service_file}" /etc/systemd/system/jeannie-eventd.service sudo install -m 0644 "${service_file}" /etc/systemd/system/jeannie-eventd.service
rm -f "${service_file}" rm -f "${service_file}"
rmdir "${service_stage}"
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable jeannie-eventd sudo systemctl enable jeannie-eventd
sudo systemctl restart jeannie-eventd sudo systemctl restart jeannie-eventd