bugfix(containers-dashboard): containers in een systemctl managed pod worden nu ook weergegeven als systemctl managed
This commit is contained in:
+24
-1
@@ -470,6 +470,19 @@ def containers_dashboard():
|
||||
dashboard = []
|
||||
defined = find_defined_containers()
|
||||
|
||||
# Cache zodat we niet voor elke container opnieuw systemctl doen
|
||||
unit_active_cache = {}
|
||||
|
||||
def _unit_is_active(unit):
|
||||
if not unit:
|
||||
return False
|
||||
if unit in unit_active_cache:
|
||||
return unit_active_cache[unit]
|
||||
code, out = _systemctl(["systemctl", "--user", "is-active", unit])
|
||||
ok = (code == 0) or ((out or "").strip() == "active")
|
||||
unit_active_cache[unit] = ok
|
||||
return ok
|
||||
|
||||
# A) echte containers (runtime)
|
||||
real = _podman_get_json(f"{PODMAN_API_BASE}/libpod/containers/json?all=true")
|
||||
for c in real:
|
||||
@@ -481,11 +494,20 @@ def containers_dashboard():
|
||||
# Normaliseer naam: Podman kan "/name" geven
|
||||
rname = ((c.get("Names") or ["?"])[0] or "").lstrip("/")
|
||||
|
||||
# Managed: systemd als er een .container definitie bestaat, anders podman
|
||||
# 1) Managed: systemd als er een .container definitie bestaat
|
||||
if rname in defined:
|
||||
c["_dashboard_source"] = "systemd"
|
||||
c["_dashboard_unit"] = f"{rname}.service"
|
||||
c["_dashboard_def_path"] = defined[rname]
|
||||
else:
|
||||
# 2) Extra: zit container in een pod die via systemd (kube/quadlet) draait?
|
||||
podname = (c.get("PodName") or "").strip()
|
||||
pod_unit = _map_pod_to_unit(podname) if podname else None
|
||||
|
||||
if pod_unit and _unit_is_active(pod_unit):
|
||||
c["_dashboard_source"] = "systemd"
|
||||
c["_dashboard_unit"] = pod_unit
|
||||
# geen _dashboard_def_path, want dit is geen .container definitie
|
||||
else:
|
||||
c["_dashboard_source"] = "podman"
|
||||
|
||||
@@ -505,6 +527,7 @@ def containers_dashboard():
|
||||
|
||||
return dashboard
|
||||
|
||||
|
||||
@app.get("/containers")
|
||||
def list_containers():
|
||||
# Ook hier ?all=true voor gestopte containers
|
||||
|
||||
Reference in New Issue
Block a user