feat: scope disk self-healing to Pimox workers
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-21 10:38:36 -06:00
parent 219f5eda0f
commit cb6f442d97
6 changed files with 80 additions and 22 deletions

View File

@ -52,9 +52,10 @@ spec:
for: 5m
labels:
severity: critical
self_heal: "true"
annotations:
summary: "Node {{ $labels.node }} reports DiskPressure"
description: "DiskPressure is active. Run ./jeannie capacity and inspect image/PVC/log usage."
description: "Kubelet image filesystem pressure has crossed its eviction threshold (85% in the Pimox profile). Jeannie can prune unused images and old pod logs on the alerting Pimox worker."
- alert: HomelabPersistentVolumeAlmostFull
expr: (1 - kubelet_volume_stats_available_bytes / kubelet_volume_stats_capacity_bytes) * 100 > 85
for: 15m
@ -68,6 +69,7 @@ spec:
for: 15m
labels:
severity: warning
self_heal: "true"
annotations:
summary: "Host filesystem {{ $labels.mountpoint }} on {{ $labels.instance }} is over 85% full"
description: "The {{ $labels.mountpoint }} mount on {{ $labels.instance }} is near exhaustion. Review disk usage before it becomes an outage."

View File

@ -1914,7 +1914,7 @@ resource "helm_release" "prometheus_stack" {
routes = [
{
receiver = "jeannie-self-heal"
matchers = ["alertname =~ \"HomelabNodeDiskPressure|FreeDiskSpaceFailed|HomelabStaleResidualPods|KubePodContainerStatusUnknown|KubePodEvicted|JeannieApiMetricsDown\""]
matchers = ["alertname =~ \"HomelabNodeDiskPressure|HomelabHostFilesystemNearlyFull|FreeDiskSpaceFailed|HomelabStaleResidualPods|KubePodContainerStatusUnknown|KubePodEvicted|JeannieApiMetricsDown\""]
repeat_interval = "1h"
}
]

View File

@ -209,19 +209,21 @@ Destructive actions remain blocked.
The first headless self-heal path is intentionally narrow and targets node image
filesystem pressure / `FreeDiskSpaceFailed` symptoms. Alertmanager can call the
Debian-hosted `jeannie-eventd` webhook, which runs `doctor-homelab` in JSON
mode, feeds the findings into `scripts/heal`, and applies only one
allowlisted action per event.
Debian-hosted `jeannie-eventd` webhook. For a disk-pressure alert, the webhook
maps the alert to the reporting Pimox worker and applies worker-scoped image and
old pod-log cleanup; other alerts still
flow through the guarded status/heal planner.
For the first phase, the only automatic mutation is:
For the first phase, the automatic mutations are:
- prune unused container images and delete pod/container logs older than three
days on the alerting Pimox worker;
- delete stale Kubernetes pod records where the reason is `Evicted`,
`NodeLost`, `Unknown`, or `ContainerStatusUnknown`.
It does not prune container images, delete PVCs, delete namespaces, mutate
OpenTofu state, or SSH into nodes for disk cleanup. If image garbage collection
already freed zero bytes, Jeannie reports the node/image/log investigation path
instead of guessing.
It does not delete PVCs, delete namespaces, or mutate OpenTofu state. Disk cleanup
is limited to CRI image pruning and old pod/container logs; it does not touch
application data. Apply mode remains disabled unless `LAB_SELF_HEAL_APPLY=true`.
Test the event pipeline without mutating anything:

View File

@ -209,19 +209,21 @@ Destructive actions remain blocked.
The first headless self-heal path is intentionally narrow and targets node image
filesystem pressure / `FreeDiskSpaceFailed` symptoms. Alertmanager can call the
Debian-hosted `jeannie-eventd` webhook, which runs `doctor-homelab` in JSON
mode, feeds the findings into `scripts/heal`, and applies only one
allowlisted action per event.
Debian-hosted `jeannie-eventd` webhook. For a disk-pressure alert, the webhook
maps the alert to the reporting Pimox worker and applies worker-scoped image and
old pod-log cleanup; other alerts still
flow through the guarded status/heal planner.
For the first phase, the only automatic mutation is:
For the first phase, the automatic mutations are:
- prune unused container images and delete pod/container logs older than three
days on the alerting Pimox worker;
- delete stale Kubernetes pod records where the reason is `Evicted`,
`NodeLost`, `Unknown`, or `ContainerStatusUnknown`.
It does not prune container images, delete PVCs, delete namespaces, mutate
OpenTofu state, or SSH into nodes for disk cleanup. If image garbage collection
already freed zero bytes, Jeannie reports the node/image/log investigation path
instead of guessing.
It does not delete PVCs, delete namespaces, or mutate OpenTofu state. Disk cleanup
is limited to CRI image pruning and old pod/container logs; it does not touch
application data. Apply mode remains disabled unless `LAB_SELF_HEAL_APPLY=true`.
Test the event pipeline without mutating anything:

View File

@ -2,7 +2,7 @@ route:
receiver: default
routes:
- matchers:
- alertname =~ "HomelabNodeDiskPressure|FreeDiskSpaceFailed|HomelabStaleResidualPods|KubePodContainerStatusUnknown|KubePodEvicted|JeannieApiMetricsDown"
- alertname =~ "HomelabNodeDiskPressure|HomelabHostFilesystemNearlyFull|FreeDiskSpaceFailed|HomelabStaleResidualPods|KubePodContainerStatusUnknown|KubePodEvicted|JeannieApiMetricsDown"
receiver: jeannie-self-heal
repeat_interval: 1h

View File

@ -28,6 +28,7 @@ SUPPORTED_ALERTS = {
"JeannieApiMetricsDown",
"HomelabNodeDiskPressure",
"HomelabNodeImageFilesystemPressure",
"HomelabHostFilesystemNearlyFull",
"HomelabStaleResidualPods",
"FreeDiskSpaceFailed",
"KubePodContainerStatusUnknown",
@ -38,6 +39,13 @@ API_SELF_HEAL_COMMANDS = {
"JeannieApiMetricsDown": ["sudo", "systemctl", "restart", "jeannie-server.service"],
}
DISK_SELF_HEAL_ALERTS = {
"HomelabNodeDiskPressure",
"HomelabNodeImageFilesystemPressure",
"HomelabHostFilesystemNearlyFull",
"FreeDiskSpaceFailed",
}
def prom_escape(value: object) -> str:
text = str(value)
@ -100,6 +108,44 @@ def api_self_heal_command(names: set[str]) -> list[str] | None:
return None
def disk_self_heal_command(payload: dict[str, Any], names: set[str]) -> list[str] | None:
if not names & DISK_SELF_HEAL_ALERTS:
return None
labels_list: list[dict[str, Any]] = []
for alert in payload.get("alerts") or []:
if isinstance(alert, dict) and isinstance(alert.get("labels"), dict):
labels_list.append(alert["labels"])
common_labels = payload.get("commonLabels")
if isinstance(common_labels, dict):
labels_list.append(common_labels)
for labels in labels_list:
node = str(labels.get("node") or "")
match = re.fullmatch(r"pimox-worker-(\d{1,2})", node)
if match:
return ["./jeannie", "workers", "disk-cleanup", str(int(match.group(1))), "--yes"]
spec_file = REPO_ROOT / ".lab" / "pimox-workers.tsv"
if spec_file.is_file():
for labels in labels_list:
instance = str(labels.get("instance") or "").split(":", 1)[0]
if not instance:
continue
try:
rows = spec_file.read_text(encoding="utf-8").splitlines()
except OSError:
break
for row in rows:
fields = row.split("\t")
if len(fields) < 4 or fields[1] != instance:
continue
node = fields[3]
match = re.fullmatch(r"pimox-worker-(\d{1,2})", node)
if match:
return ["./jeannie", "workers", "disk-cleanup", str(int(match.group(1))), "--yes"]
return None
def write_text(path: Path, text: str) -> None:
path.write_text(text, encoding="utf-8")
@ -146,17 +192,23 @@ def handle_payload(payload: dict[str, Any], *, apply: bool) -> dict[str, Any]:
write_text(audit_dir / "result.json", json.dumps(result, indent=2) + "\n")
return result
disk_command = disk_self_heal_command(payload, set(names))
api_command = api_self_heal_command(set(names))
if api_command:
direct_command = disk_command or api_command
if direct_command:
result = {
"status": "planned",
"mode": "dry-run",
"alerts": names,
"audit_dir": str(audit_dir),
"planned_command": " ".join(api_command),
"planned_command": " ".join(direct_command),
}
if apply:
apply_result = run_command(api_command, audit_dir, "api-heal")
apply_result = run_command(
direct_command,
audit_dir,
"disk-heal" if disk_command else "api-heal",
)
result["status"] = "applied" if apply_result.returncode == 0 else "apply_failed"
result["mode"] = "apply"
result["apply_status"] = apply_result.returncode