feat: pick the engine from Docker contexts, with one shared client #28

Merged
jfro merged 1 commit from feat/16-engine-picker into main 2026-11-30 19:51:50 +00:00
Owner

Closes #16

Krane can now talk to any engine the docker CLI knows: local Docker, rootless Podman, and remote engines over SSH or TCP+TLS. You pick it from a menu at the bottom of the sidebar.

Engine menu. Click the engine status (dot, version, running count) to open it.

  • It lists default plus every context in ~/.docker/contexts (or $DOCKER_CONFIG), each with its description and address. The list is read fresh each time the menu opens.
  • Contexts that use SkipTLSVerify, or an address Krane can't use, are listed greyed out with the reason.
  • The status now says which kind of engine it is ("Podman 5.4.2", "Docker 29.1.0") and names the context when it isn't default.

Which engine. The order matches the CLI:

  1. DOCKER_HOST. When it's set, it wins and the menu is locked with a note.
  2. Krane's own choice, saved as engine in ~/.config/krane/settings.json.
  3. $DOCKER_CONTEXT, then currentContext in config.json.
  4. default.

A saved context that has since been removed is skipped. Krane never runs docker context use.

Switching. Krane connects and asks the new engine for its version, giving it up to 5 s. If that works:

  • It swaps the shared client and saves the choice.
  • It clears the containers, images, volumes and networks it was showing, so the old engine's data doesn't linger.
  • Events, notification and stats streams reconnect to the new engine.
  • Open log windows end with a "switched to another engine" line.

If the engine doesn't answer, an alert says so ("deadhost didn't answer within 5 seconds.") and Krane stays on the engine it had.

Must-dos from the plan

  • One shared client (engine::client()): all 14 connect_with_local_defaults() call sites now use it, including stats follow() from #11 (which made a client per container), pulls, logs, notifications and the resource watcher. Over SSH this means one ssh session, not one per call.
  • A 5 s timeout on the connect check and on the container poll, so a dead engine shows as unreachable instead of hanging the fetch loop.

Other changes

  • bollard gets its ssh and ssl features, and sha2 is added (the CLI stores each context under the SHA-256 of its name).
  • Volume sizes come from the selected engine's unix socket; they're skipped for remote engines, as before.
  • Container shell (docker exec) runs docker --context <name>. The terminals that Open in Terminal (#20) opens get DOCKER_CONTEXT=<name>. Neither does this when DOCKER_HOST is set, because --context would win over it.
  • Notifications (#19) use the shared client, and their Podman check (F9) uses the engine they're connected to.

Tests

  • 7 new unit tests: meta.json with and without a description, no docker endpoint or bad JSON, the SHA-256 folder name, reading a config folder with a TLS dir, the precedence table (including a removed context), and telling Podman from Docker.
  • Tried live on Xfce:
    • Switched default (Docker 29.9) → podman (Podman 5.4.2). Containers and images changed over within a second.
    • Restarted Krane, and it came back on podman.
    • Switched to an unreachable tcp://10.255.255.1:2375 context: an alert after 5 s, and Krane stayed on podman.
    • With DOCKER_HOST set, the menu was locked.
  • Not tried: SSH and TLS engines (Nye's probe covers those connectors; it plans to re-run its 5-engine setup).

Screenshots (mock engines; lab shows an unsupported SkipTLSVerify context)

Dark Light
Engines Engines, light
Closes #16 Krane can now talk to any engine the docker CLI knows: local Docker, rootless Podman, and remote engines over SSH or TCP+TLS. You pick it from a menu at the bottom of the sidebar. **Engine menu.** Click the engine status (dot, version, running count) to open it. - It lists `default` plus every context in `~/.docker/contexts` (or `$DOCKER_CONFIG`), each with its description and address. The list is read fresh each time the menu opens. - Contexts that use `SkipTLSVerify`, or an address Krane can't use, are listed greyed out with the reason. - The status now says which kind of engine it is ("Podman 5.4.2", "Docker 29.1.0") and names the context when it isn't `default`. **Which engine.** The order matches the CLI: 1. `DOCKER_HOST`. When it's set, it wins and the menu is locked with a note. 2. Krane's own choice, saved as `engine` in `~/.config/krane/settings.json`. 3. `$DOCKER_CONTEXT`, then `currentContext` in config.json. 4. `default`. A saved context that has since been removed is skipped. Krane never runs `docker context use`. **Switching.** Krane connects and asks the new engine for its version, giving it up to 5 s. If that works: - It swaps the shared client and saves the choice. - It clears the containers, images, volumes and networks it was showing, so the old engine's data doesn't linger. - Events, notification and stats streams reconnect to the new engine. - Open log windows end with a "switched to another engine" line. If the engine doesn't answer, an alert says so ("deadhost didn't answer within 5 seconds.") and Krane stays on the engine it had. **Must-dos from the plan** - One shared client (`engine::client()`): all 14 `connect_with_local_defaults()` call sites now use it, including stats `follow()` from #11 (which made a client per container), pulls, logs, notifications and the resource watcher. Over SSH this means one ssh session, not one per call. - A 5 s timeout on the connect check and on the container poll, so a dead engine shows as unreachable instead of hanging the fetch loop. **Other changes** - bollard gets its `ssh` and `ssl` features, and sha2 is added (the CLI stores each context under the SHA-256 of its name). - Volume sizes come from the selected engine's unix socket; they're skipped for remote engines, as before. - Container shell (`docker exec`) runs `docker --context <name>`. The terminals that Open in Terminal (#20) opens get `DOCKER_CONTEXT=<name>`. Neither does this when `DOCKER_HOST` is set, because `--context` would win over it. - Notifications (#19) use the shared client, and their Podman check (F9) uses the engine they're connected to. **Tests** - 7 new unit tests: meta.json with and without a description, no docker endpoint or bad JSON, the SHA-256 folder name, reading a config folder with a TLS dir, the precedence table (including a removed context), and telling Podman from Docker. - Tried live on Xfce: - Switched `default` (Docker 29.9) → `podman` (Podman 5.4.2). Containers and images changed over within a second. - Restarted Krane, and it came back on `podman`. - Switched to an unreachable `tcp://10.255.255.1:2375` context: an alert after 5 s, and Krane stayed on podman. - With `DOCKER_HOST` set, the menu was locked. - Not tried: SSH and TLS engines (Nye's probe covers those connectors; it plans to re-run its 5-engine setup). **Screenshots** (mock engines; `lab` shows an unsupported SkipTLSVerify context) | Dark | Light | | --- | --- | | ![Engines](https://git.knope.dev/attachments/ad5d84ca-9dbe-4a11-b50e-e20a75f0335b) | ![Engines, light](https://git.knope.dev/attachments/05a5a4d3-b959-4d1e-86fc-bf5cea720bae) |
feat: pick the engine from Docker contexts, with one shared client
All checks were successful
CI / test (pull_request) Successful in 5m4s
d6775f2992
jfro force-pushed feat/16-engine-picker from d6775f2992
All checks were successful
CI / test (pull_request) Successful in 5m4s
to 4a33b9aa10
All checks were successful
CI / test (pull_request) Successful in 5m16s
2026-11-30 19:02:58 +00:00
Compare
jfro changed target branch from feat/20-open-project to main 2026-11-30 19:31:02 +00:00
jfro force-pushed feat/16-engine-picker from 4a33b9aa10
All checks were successful
CI / test (pull_request) Successful in 5m16s
to 9cdb6df985
All checks were successful
CI / test (pull_request) Successful in 5m25s
CI / test (push) Successful in 5m1s
2026-11-30 19:31:41 +00:00
Compare
jfro left a comment

Review from Nye (posted by Upper Wolfjaw) — at d6775f2

PR #28 (#16 engine picker) review — Nye, d6775f2

Verdict: changes requested (one medium finding, F12). Everything else checks out.

Passed

  • CI gates (notes/gates.sh): fmt, clippy (default + mock), both builds, 38 tests.
  • C9, five real engines (notes/pr28-five-engines.sh + pr28-five-engines-test.rs): engine::switch
    through podman (Podman 5.4.2), sshlocal (ssh://peak@localhost), tlsctx (tcp :2376, client cert
    required), tcpplain (tcp :2375), default. Each lists exactly the containers docker --context X ps -a lists; cli_args() = --context X. deadtcp (blackholed 10.255.255.1) fails with
    "deadtcp didn't answer within 5 seconds." after 5.0 s and Krane stays on the old engine.
  • DOCKER_HOST wins (notes/pr28-docker-host.sh): tcp://:2375, ssh://, and tcp://:2376 with
    DOCKER_TLS_VERIFY/DOCKER_CERT_PATH all list the CLI's containers; switch() is refused; no --context.
  • Live GUI: menu lists all 6 contexts with hosts; switching to podman updates the list and the
    status ("Podman 5.4.2 · podman"); deadtcp shows "Couldn't Switch Engine" dialog after 5 s.
  • No Docker::connect_with_* left outside engine.rs (only #[ignore] tests); stats follow(),
    logs, notify events and resource events all end on switch.

F12 (medium): resources stuck after switching away from a dead engine

spawn_resource_watch awaits fetch_resources() on the old client with no timeout and no switch
check. If the engine doesn't answer (saved choice is a remote that's down, or it drops mid-read),
the loop sits in list_volumes until bollard's 120 s request timeout. Switching to a good engine
brings containers back at once, but Volumes/Images/Networks stay empty for up to 2 minutes.
Proof: bash notes/pr28-switch-away-proof.sh in a PR worktree (appends
notes/pr28-switch-away-test.rs and runs it): 15 s after switching deadtcp -> default there are
0 networks. Fix sketch (notes/pr28-f12-fix.patch): select! fetch_resources against
engine::switches().changed(); with it the test passes in 1.5 s. (Old-engine errors arriving
after a switch are dropped too.)

Notes, not findings

  • Two quick switches: if the first engine is slow (up to 5 s) and the second answers first, the
    first finishes last and wins. Low; could ignore a switch() that isn't the latest request.
  • fetch_containers is wrapped in the 5 s answer() timeout on every poll, not just the first
    connect; a slow remote with many containers over ssh could flap "unreachable". Not seen here.
**Review from Nye (posted by Upper Wolfjaw)** — at d6775f2 # PR #28 (#16 engine picker) review — Nye, d6775f2 Verdict: changes requested (one medium finding, F12). Everything else checks out. ## Passed - CI gates (notes/gates.sh): fmt, clippy (default + mock), both builds, 38 tests. - C9, five real engines (notes/pr28-five-engines.sh + pr28-five-engines-test.rs): engine::switch through podman (Podman 5.4.2), sshlocal (ssh://peak@localhost), tlsctx (tcp :2376, client cert required), tcpplain (tcp :2375), default. Each lists exactly the containers `docker --context X ps -a` lists; cli_args() = --context X. deadtcp (blackholed 10.255.255.1) fails with "deadtcp didn't answer within 5 seconds." after 5.0 s and Krane stays on the old engine. - DOCKER_HOST wins (notes/pr28-docker-host.sh): tcp://:2375, ssh://, and tcp://:2376 with DOCKER_TLS_VERIFY/DOCKER_CERT_PATH all list the CLI's containers; switch() is refused; no --context. - Live GUI: menu lists all 6 contexts with hosts; switching to podman updates the list and the status ("Podman 5.4.2 · podman"); deadtcp shows "Couldn't Switch Engine" dialog after 5 s. - No Docker::connect_with_* left outside engine.rs (only #[ignore] tests); stats follow(), logs, notify events and resource events all end on switch. ## F12 (medium): resources stuck after switching away from a dead engine spawn_resource_watch awaits fetch_resources() on the old client with no timeout and no switch check. If the engine doesn't answer (saved choice is a remote that's down, or it drops mid-read), the loop sits in list_volumes until bollard's 120 s request timeout. Switching to a good engine brings containers back at once, but Volumes/Images/Networks stay empty for up to 2 minutes. Proof: `bash notes/pr28-switch-away-proof.sh` in a PR worktree (appends notes/pr28-switch-away-test.rs and runs it): 15 s after switching deadtcp -> default there are 0 networks. Fix sketch (notes/pr28-f12-fix.patch): select! fetch_resources against engine::switches().changed(); with it the test passes in 1.5 s. (Old-engine errors arriving after a switch are dropped too.) ## Notes, not findings - Two quick switches: if the first engine is slow (up to 5 s) and the second answers first, the first finishes last and wins. Low; could ignore a switch() that isn't the latest request. - fetch_containers is wrapped in the 5 s answer() timeout on every poll, not just the first connect; a slow remote with many containers over ssh could flap "unreachable". Not seen here.
Author
Owner

F12 fixed in 9cdb6df (rebased onto main now that #26/#27 merged). The resource loop select!s fetch_resources against engine::switches(), so a switch drops the dead engine's request straight away (Nye's sketch), and it marks sizes stale so the new engine's volume sizes are read on the next pass. Nye's switch-away test: 8 networks / 19 images 1.5 s after switching away from a blackholed tcp engine. Back to Nye for recheck.

**F12 fixed** in 9cdb6df (rebased onto main now that #26/#27 merged). The resource loop `select!`s `fetch_resources` against `engine::switches()`, so a switch drops the dead engine's request straight away (Nye's sketch), and it marks sizes stale so the new engine's volume sizes are read on the next pass. Nye's switch-away test: 8 networks / 19 images 1.5 s after switching away from a blackholed tcp engine. Back to Nye for recheck.
jfro merged commit 9cdb6df985 into main 2026-11-30 19:51:50 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/krane!28
No description provided.