feat(resources): reclaim banner controls and accurate reclaim math (#1318)

* feat(resources): reclaim banner controls and accurate reclaim math

Make the Resources Hub reclaim banner match what it advertises and give
operators control over when it appears.

- "Review & prune" now reclaims every category the banner lists (unused
  images, stopped containers, and dangling volumes) instead of images
  only, so the banner clears in one action. Pruning runs volumes first,
  while stopped containers still reference their named volumes, so a
  stopped stack's data is never cascaded into deletion.
- Add a "Show reclaimable-space banner" toggle under Settings, System,
  Docker hygiene (on by default, per node) and a dismiss control on the
  banner that snoozes it until the reclaimable total grows again.
- Fix the reclaimable-space math: count only containers a prune can
  actually remove (created, exited, dead) and size them by their writable
  layer, so a small, un-prunable remainder no longer keeps the banner up.

* fix(resources): show the reclaim banner when the settings fetch fails

A failed or empty /settings load left the banner's enabled flag at the
previously active node's value, so switching from a node with the banner
turned off to a node whose /settings errored kept the new node's banner
hidden. Set the flag unconditionally after the staleness guard so a
failed fetch falls back to the default-on state for the current node.
This commit is contained in:
Anso
2026-06-05 18:59:33 -04:00
committed by GitHub
parent 716daf77d0
commit 308949282c
11 changed files with 457 additions and 12 deletions
@@ -316,6 +316,49 @@ describe('DockerController - getDiskUsage', () => {
expect(usage.reclaimableContainers).toBe(0);
expect(usage.reclaimableVolumes).toBe(0);
});
it('counts only prune-eligible container states (created/exited/dead)', async () => {
// `docker container prune` removes stopped containers (created/exited/dead).
// Paused and restarting containers survive it, so counting them would leave
// a residue the banner can never clear no matter which prune runs.
mockDocker.df.mockResolvedValue({
Images: [],
Volumes: [],
Containers: [
{ State: 'exited', SizeRw: 200 }, // prunable
{ State: 'created', SizeRw: 50 }, // prunable
{ State: 'dead', SizeRw: 25 }, // prunable
{ State: 'paused', SizeRw: 1000 }, // survives prune
{ State: 'restarting', SizeRw: 1000 }, // survives prune
{ State: 'running', SizeRw: 1000 }, // in use
],
});
const dc = DockerController.getInstance(1);
const usage = await dc.getDiskUsage();
expect(usage.reclaimableContainers).toBe(275);
expect(usage.reclaimableContainerCount).toBe(3);
});
it('sizes stopped containers by the writable layer (SizeRw), not SizeRootFs', async () => {
// SizeRootFs includes the read-only image layers, which removing a
// container never frees. A stopped container that wrote nothing reclaims 0.
mockDocker.df.mockResolvedValue({
Images: [],
Volumes: [],
Containers: [
{ State: 'exited', SizeRw: 0, SizeRootFs: 500_000_000 }, // wrote nothing
{ State: 'exited', SizeRw: 1_500, SizeRootFs: 900_000 }, // writable layer only
],
});
const dc = DockerController.getInstance(1);
const usage = await dc.getDiskUsage();
expect(usage.reclaimableContainers).toBe(1_500);
expect(usage.reclaimableContainerCount).toBe(2);
});
});
// ── pruneSystem ────────────────────────────────────────────────────────