Recognize intentionally disabled Kubernetes runner
This commit is contained in:
parent
8bc51dd8dc
commit
acaf54b07c
|
|
@ -39,6 +39,13 @@ snapshot. Degraded or missing applications are failures; progressing, unknown,
|
|||
or out-of-sync applications are warnings. These are Argo CD's reported states,
|
||||
not a separate endpoint probe. Applications outside Argo CD are not included.
|
||||
|
||||
The optional Kubernetes Gitea runner is an exception: status accepts its
|
||||
`Progressing` state only when Argo CD is synced to the local committed
|
||||
zero-replica configuration, the live Deployment also requests zero replicas,
|
||||
no other application resources report trouble, and the Debian runner service
|
||||
is active. If those facts cannot be verified, the warning remains. The service
|
||||
being active alone does not prove it is registered or processing jobs.
|
||||
|
||||
The Orange Pi K3s service and storage checks are skipped when the selected
|
||||
profile does not put K3s on that host. The cluster scope checks the selected
|
||||
profile, which can be mixed, all-Pimox, or K3s. The OCI scope checks the
|
||||
|
|
|
|||
|
|
@ -37,7 +37,36 @@ def compose(lines):
|
|||
emit("skip", "Compose services", "No Compose-managed containers found; absent services cannot be assessed")
|
||||
|
||||
|
||||
def applications(document):
|
||||
def runner_candidate(document):
|
||||
items = document.get("items")
|
||||
if not isinstance(items, list):
|
||||
raise ValueError("Invalid Kubernetes application list")
|
||||
for app in items:
|
||||
if (app.get("metadata") or {}).get("name") != "gitea-runner":
|
||||
continue
|
||||
status = app.get("status") or {}
|
||||
if ((status.get("health") or {}).get("status") != "Progressing" or
|
||||
(status.get("sync") or {}).get("status") != "Synced" or
|
||||
status.get("conditions")):
|
||||
return
|
||||
found = False
|
||||
for resource in status.get("resources") or []:
|
||||
is_runner = (resource.get("kind") == "Deployment" and
|
||||
resource.get("name") == "gitea-runner" and
|
||||
resource.get("namespace") == "gitea-runner")
|
||||
found = found or is_runner
|
||||
health = (resource.get("health") or {}).get("status")
|
||||
if resource.get("status") in ("OutOfSync", "Unknown"):
|
||||
return
|
||||
if health and health != "Healthy" and not (is_runner and health == "Progressing"):
|
||||
return
|
||||
revision = (status.get("sync") or {}).get("revision")
|
||||
if found and isinstance(revision, str) and revision:
|
||||
print(revision)
|
||||
return
|
||||
|
||||
|
||||
def applications(document, expected_runner=False):
|
||||
items = document.get("items")
|
||||
if not isinstance(items, list):
|
||||
raise ValueError("Invalid Kubernetes application list")
|
||||
|
|
@ -48,23 +77,31 @@ def applications(document):
|
|||
name = metadata.get("name", "unknown")
|
||||
health = status.get("health", {}).get("status", "Unknown")
|
||||
sync = status.get("sync", {}).get("status", "Unknown")
|
||||
if health in ("Degraded", "Missing"):
|
||||
if name == "gitea-runner" and health == "Progressing" and sync == "Synced" and expected_runner:
|
||||
severity = "ok"
|
||||
elif health in ("Degraded", "Missing"):
|
||||
severity = "fail"
|
||||
elif health != "Healthy" or sync != "Synced":
|
||||
severity = "warn"
|
||||
else:
|
||||
severity = "ok"
|
||||
emit(severity, name, f"health={health}, sync={sync}")
|
||||
suffix = "; zero-replica Kubernetes runner is expected; Debian runner service is active" if (
|
||||
name == "gitea-runner" and health == "Progressing" and sync == "Synced" and expected_runner) else ""
|
||||
emit(severity, name, f"health={health}, sync={sync}{suffix}")
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
if len(sys.argv) != 2:
|
||||
if len(sys.argv) not in (2, 3):
|
||||
raise ValueError("Expected compose or applications")
|
||||
if sys.argv[1] == "compose":
|
||||
compose(sys.stdin)
|
||||
elif sys.argv[1] == "applications":
|
||||
applications(json.load(sys.stdin))
|
||||
if len(sys.argv) == 3 and sys.argv[2] != "--expected-runner":
|
||||
raise ValueError("Unknown applications option")
|
||||
applications(json.load(sys.stdin), len(sys.argv) == 3)
|
||||
elif sys.argv[1] == "runner-candidate" and len(sys.argv) == 2:
|
||||
runner_candidate(json.load(sys.stdin))
|
||||
else:
|
||||
raise ValueError("Unknown snapshot type")
|
||||
except (ValueError, TypeError, AttributeError) as exc:
|
||||
|
|
|
|||
|
|
@ -105,12 +105,27 @@ status_focus_compose_report() {
|
|||
done <<<"${rows}"
|
||||
}
|
||||
|
||||
status_focus_runner_expected() {
|
||||
local snapshot="$1" revision head configured deployment
|
||||
revision="$(printf '%s' "${snapshot}" | python3 "${REPO_ROOT}/scripts/status-app-snapshot.py" runner-candidate)" || return 1
|
||||
[[ -n "${revision}" ]] || return 1
|
||||
head="$(git -C "${REPO_ROOT}" rev-parse HEAD 2>/dev/null)" || return 1
|
||||
[[ "${head}" == "${revision}" ]] || return 1
|
||||
configured="$(git -C "${REPO_ROOT}" show HEAD:apps/gitea-runner/deployment.yaml 2>/dev/null | awk '/^ replicas:/ && !seen {print $2; seen=1}')" || return 1
|
||||
[[ "${configured}" == 0 ]] || return 1
|
||||
systemctl is-active --quiet homelab-gitea-runner.service || return 1
|
||||
deployment="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" --request-timeout=8s -n gitea-runner get deployment gitea-runner -o json 2>/dev/null)" || return 1
|
||||
printf '%s' "${deployment}" | python3 -c 'import json,sys; d=json.load(sys.stdin); v=d.get("spec",{}).get("replicas"); sys.exit(0 if type(v) is int and v == 0 else 1)' 2>/dev/null
|
||||
}
|
||||
|
||||
status_focus_applications_report() {
|
||||
local snapshot rows severity name detail failed=0
|
||||
local -a options=()
|
||||
snapshot="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" --request-timeout=8s -n argocd get applications -o json 2>&1)" || {
|
||||
report_ui_emit warn "Kubernetes apps" "Argo CD applications" "Cannot read application status" "${snapshot}"; return 0;
|
||||
}
|
||||
rows="$(printf '%s' "${snapshot}" | python3 "${REPO_ROOT}/scripts/status-app-snapshot.py" applications 2>&1)" || {
|
||||
if status_focus_runner_expected "${snapshot}"; then options+=(--expected-runner); fi
|
||||
rows="$(printf '%s' "${snapshot}" | python3 "${REPO_ROOT}/scripts/status-app-snapshot.py" applications "${options[@]}" 2>&1)" || {
|
||||
report_ui_emit warn "Kubernetes apps" "Argo CD applications" "Cannot interpret application status" "${rows}"; return 0;
|
||||
}
|
||||
while IFS=$'\t' read -r severity name detail; do
|
||||
|
|
@ -131,6 +146,7 @@ status_focus_collect() {
|
|||
if [[ "${scope}" == all || "${scope}" == debian ]]; then
|
||||
report_ui_enqueue status_focus_compose_report "Debian Compose" local "" ""
|
||||
report_ui_check fail "Debian" "Docker service" "./jeannie status debian --details" "" "" check_systemd_active docker
|
||||
report_ui_check warn "Debian" "Gitea runner service" "./jeannie doctor gitea-runner" "" "" check_systemd_active homelab-gitea-runner.service
|
||||
report_ui_check fail "Debian" "Gitea HTTP" "./jeannie status debian --details" "" "" status_focus_http_ok "http://127.0.0.1:${LAB_GITEA_HTTP_PORT:-3000}/"
|
||||
report_ui_check warn "Debian" "Dex HTTP" "./jeannie status debian --details" "" "" status_focus_http_ok "http://127.0.0.1:${LAB_DEX_HTTP_PORT:-5556}/healthz"
|
||||
report_ui_check warn "Debian" "Matrix API" "./jeannie status debian --details" "" "" status_focus_http_ok "http://127.0.0.1:${LAB_MATRIX_SYNAPSE_PORT:-8008}/_matrix/client/versions"
|
||||
|
|
|
|||
|
|
@ -7,12 +7,33 @@ from pathlib import Path
|
|||
SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "status-app-snapshot.py"
|
||||
|
||||
|
||||
def parse(kind, data):
|
||||
return subprocess.run([sys.executable, str(SCRIPT), kind], input=data,
|
||||
def parse(kind, data, *args):
|
||||
return subprocess.run([sys.executable, str(SCRIPT), kind, *args], input=data,
|
||||
capture_output=True, text=True, check=True).stdout
|
||||
|
||||
|
||||
class ApplicationSnapshotTests(unittest.TestCase):
|
||||
def test_runner_candidate_requires_synced_revision_and_no_other_unhealthy_resources(self):
|
||||
runner = {"metadata": {"name": "gitea-runner"}, "status": {
|
||||
"health": {"status": "Progressing"}, "sync": {"status": "Synced", "revision": "abc123"},
|
||||
"resources": [{"kind": "Deployment", "namespace": "gitea-runner", "name": "gitea-runner",
|
||||
"health": {"status": "Progressing"}}]}}
|
||||
self.assertEqual(parse("runner-candidate", json.dumps({"items": [runner]})).strip(), "abc123")
|
||||
runner["status"]["resources"].append({"kind": "PersistentVolumeClaim", "name": "data",
|
||||
"health": {"status": "Degraded"}})
|
||||
self.assertEqual(parse("runner-candidate", json.dumps({"items": [runner]})), "")
|
||||
|
||||
def test_expected_runner_flag_only_changes_matching_progressing_runner(self):
|
||||
data = json.dumps({"items": [
|
||||
{"metadata": {"name": "gitea-runner"}, "status": {
|
||||
"health": {"status": "Progressing"}, "sync": {"status": "Synced"}}},
|
||||
{"metadata": {"name": "other"}, "status": {
|
||||
"health": {"status": "Progressing"}, "sync": {"status": "Synced"}}}]})
|
||||
self.assertIn("warn\tgitea-runner", parse("applications", data))
|
||||
result = parse("applications", data, "--expected-runner")
|
||||
self.assertIn("ok\tgitea-runner", result)
|
||||
self.assertIn("warn\tother", result)
|
||||
|
||||
def test_compose_services_distinguish_health_and_oneoff_jobs(self):
|
||||
def container(name, state, status, oneoff="False"):
|
||||
return json.dumps({"Names": name, "State": state, "Status": status,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,30 @@ status_focus_collect "$2"
|
|||
|
||||
|
||||
class FocusedStatusTests(unittest.TestCase):
|
||||
def test_runner_exception_requires_matching_revision_zero_replicas_and_active_host(self):
|
||||
snapshot = json.dumps({"items": [{"metadata": {"name": "gitea-runner"}, "status": {
|
||||
"health": {"status": "Progressing"}, "sync": {"status": "Synced", "revision": "abc"},
|
||||
"resources": [{"kind": "Deployment", "namespace": "gitea-runner", "name": "gitea-runner",
|
||||
"health": {"status": "Progressing"}}]}}]})
|
||||
code = r'''
|
||||
source "$1"
|
||||
git() { case "$*" in *"rev-parse HEAD"*) printf '%s\n' "$HEAD_REV";; *"show HEAD:"*) printf ' replicas: %s\n' "$CONFIG_REPLICAS";; esac; }
|
||||
systemctl() { [[ "$HOST_STATE" == active ]]; }
|
||||
kubectl() { printf '{"spec":{"replicas":%s}}' "$LIVE_REPLICAS"; }
|
||||
status_focus_runner_expected "$SNAPSHOT"
|
||||
'''
|
||||
base = dict(REPO_ROOT=str(ROOT), KUBECONFIG_PATH="/tmp/kubeconfig", SNAPSHOT=snapshot,
|
||||
HEAD_REV="abc", CONFIG_REPLICAS="0", LIVE_REPLICAS="0", HOST_STATE="active")
|
||||
for changes, expected in (({}, 0), ({"HEAD_REV": "different"}, 1),
|
||||
({"CONFIG_REPLICAS": "1"}, 1), ({"LIVE_REPLICAS": "1"}, 1),
|
||||
({"HOST_STATE": "inactive"}, 1)):
|
||||
with self.subTest(changes=changes):
|
||||
env = os.environ.copy()
|
||||
env.update(base, **changes)
|
||||
result = subprocess.run(["bash", "-c", code, "test", str(SCRIPT)], env=env,
|
||||
capture_output=True, text=True)
|
||||
self.assertEqual(result.returncode, expected)
|
||||
|
||||
def test_help_describes_scopes_and_exits_successfully(self):
|
||||
commands = ROOT / "lib" / "jeannie" / "commands.sh"
|
||||
for args in (("--help",), ("-h",), ("oci", "--help")):
|
||||
|
|
|
|||
Loading…
Reference in New Issue