podbench 0.1.0b1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- podbench-0.1.0b1/.claude/skills/ephemeral-containers/SKILL.md +120 -0
- podbench-0.1.0b1/.claude/skills/ssh-over-exec/SKILL.md +121 -0
- podbench-0.1.0b1/.copier-answers.yml +16 -0
- podbench-0.1.0b1/.devcontainer/devcontainer.json +72 -0
- podbench-0.1.0b1/.dockerignore +25 -0
- podbench-0.1.0b1/.github/CONTRIBUTING.md +27 -0
- podbench-0.1.0b1/.github/ISSUE_TEMPLATE/bug_report.md +21 -0
- podbench-0.1.0b1/.github/ISSUE_TEMPLATE/issue.md +13 -0
- podbench-0.1.0b1/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +8 -0
- podbench-0.1.0b1/.github/pages/index.html +11 -0
- podbench-0.1.0b1/.github/pages/make_switcher.py +96 -0
- podbench-0.1.0b1/.github/workflows/_container.yml +204 -0
- podbench-0.1.0b1/.github/workflows/_dist.yml +48 -0
- podbench-0.1.0b1/.github/workflows/_docs.yml +55 -0
- podbench-0.1.0b1/.github/workflows/_e2e.yml +75 -0
- podbench-0.1.0b1/.github/workflows/_helm.yml +76 -0
- podbench-0.1.0b1/.github/workflows/_pypi.yml +34 -0
- podbench-0.1.0b1/.github/workflows/_release.yml +32 -0
- podbench-0.1.0b1/.github/workflows/_test.yml +39 -0
- podbench-0.1.0b1/.github/workflows/_tox.yml +22 -0
- podbench-0.1.0b1/.github/workflows/ci.yml +78 -0
- podbench-0.1.0b1/.github/workflows/periodic.yml +13 -0
- podbench-0.1.0b1/.gitignore +71 -0
- podbench-0.1.0b1/.gitleaks.toml +19 -0
- podbench-0.1.0b1/.pre-commit-config.yaml +44 -0
- podbench-0.1.0b1/.python-version +1 -0
- podbench-0.1.0b1/.vscode/extensions.json +5 -0
- podbench-0.1.0b1/.vscode/launch.json +19 -0
- podbench-0.1.0b1/.vscode/settings.json +12 -0
- podbench-0.1.0b1/.vscode/tasks.json +16 -0
- podbench-0.1.0b1/CLAUDE.md +70 -0
- podbench-0.1.0b1/Charts/podbench/.helmignore +5 -0
- podbench-0.1.0b1/Charts/podbench/Chart.yaml +28 -0
- podbench-0.1.0b1/Charts/podbench/templates/_helpers.tpl +62 -0
- podbench-0.1.0b1/Charts/podbench/templates/configmap-seat-identity.yaml +41 -0
- podbench-0.1.0b1/Charts/podbench/templates/pvc-patch-venv.yaml +31 -0
- podbench-0.1.0b1/Charts/podbench/templates/pvc-scratch.yaml +24 -0
- podbench-0.1.0b1/Charts/podbench/templates/rbac.yaml +106 -0
- podbench-0.1.0b1/Charts/podbench/values.yaml +126 -0
- podbench-0.1.0b1/Dockerfile +158 -0
- podbench-0.1.0b1/LICENSE +201 -0
- podbench-0.1.0b1/PKG-INFO +494 -0
- podbench-0.1.0b1/README.md +275 -0
- podbench-0.1.0b1/docs/_api.rst +16 -0
- podbench-0.1.0b1/docs/_templates/custom-module-template.rst +37 -0
- podbench-0.1.0b1/docs/conf.py +198 -0
- podbench-0.1.0b1/docs/explanations/architecture.md +273 -0
- podbench-0.1.0b1/docs/explanations/decisions/0001-record-architecture-decisions.md +18 -0
- podbench-0.1.0b1/docs/explanations/decisions/0002-switched-to-python-copier-template.md +28 -0
- podbench-0.1.0b1/docs/explanations/decisions/0003-publish-to-pypi-and-drop-the-kubectl-plugin.md +70 -0
- podbench-0.1.0b1/docs/explanations/decisions/COPYME +19 -0
- podbench-0.1.0b1/docs/explanations/decisions.md +12 -0
- podbench-0.1.0b1/docs/explanations/design-brief.md +248 -0
- podbench-0.1.0b1/docs/explanations/security.md +292 -0
- podbench-0.1.0b1/docs/explanations/spikes/phase0-report.md +811 -0
- podbench-0.1.0b1/docs/explanations/spikes/s1.md +613 -0
- podbench-0.1.0b1/docs/explanations/spikes/s2.md +604 -0
- podbench-0.1.0b1/docs/explanations/spikes/s3.md +699 -0
- podbench-0.1.0b1/docs/explanations/spikes/s4.md +793 -0
- podbench-0.1.0b1/docs/explanations/spikes/s5.md +1091 -0
- podbench-0.1.0b1/docs/explanations/spikes.md +40 -0
- podbench-0.1.0b1/docs/explanations.md +10 -0
- podbench-0.1.0b1/docs/genindex.md +3 -0
- podbench-0.1.0b1/docs/how-to/attach-to-a-pod.md +175 -0
- podbench-0.1.0b1/docs/how-to/contribute.md +2 -0
- podbench-0.1.0b1/docs/how-to/debug-with-gdb.md +436 -0
- podbench-0.1.0b1/docs/how-to/iterate-on-python.md +377 -0
- podbench-0.1.0b1/docs/how-to/run-container.md +178 -0
- podbench-0.1.0b1/docs/how-to/vscode-remote-ssh.md +254 -0
- podbench-0.1.0b1/docs/how-to.md +10 -0
- podbench-0.1.0b1/docs/images/dls-logo.svg +11 -0
- podbench-0.1.0b1/docs/index.md +65 -0
- podbench-0.1.0b1/docs/reference/cli.md +636 -0
- podbench-0.1.0b1/docs/reference.md +13 -0
- podbench-0.1.0b1/docs/tutorials/first-session.md +232 -0
- podbench-0.1.0b1/docs/tutorials/installation.md +216 -0
- podbench-0.1.0b1/docs/tutorials.md +10 -0
- podbench-0.1.0b1/image/README.md +195 -0
- podbench-0.1.0b1/image/bin/capreport +8 -0
- podbench-0.1.0b1/image/bin/dbg +7 -0
- podbench-0.1.0b1/image/bin/dev-bootstrap +5 -0
- podbench-0.1.0b1/image/bin/pids +7 -0
- podbench-0.1.0b1/image/bin/podbench +7 -0
- podbench-0.1.0b1/image/bin/podbench-run +9 -0
- podbench-0.1.0b1/image/bin/podbench-stop +8 -0
- podbench-0.1.0b1/justfile +49 -0
- podbench-0.1.0b1/kind.yaml +48 -0
- podbench-0.1.0b1/pyproject.toml +181 -0
- podbench-0.1.0b1/renovate.json +51 -0
- podbench-0.1.0b1/setup.cfg +4 -0
- podbench-0.1.0b1/src/podbench/__init__.py +11 -0
- podbench-0.1.0b1/src/podbench/__main__.py +137 -0
- podbench-0.1.0b1/src/podbench/_version.py +24 -0
- podbench-0.1.0b1/src/podbench/agent.py +1034 -0
- podbench-0.1.0b1/src/podbench/dev.py +1736 -0
- podbench-0.1.0b1/src/podbench/gdbcmd.py +579 -0
- podbench-0.1.0b1/src/podbench/kubectl.py +518 -0
- podbench-0.1.0b1/src/podbench/launcher.py +2082 -0
- podbench-0.1.0b1/src/podbench/model.py +403 -0
- podbench-0.1.0b1/src/podbench/patch.py +1977 -0
- podbench-0.1.0b1/src/podbench/probe.py +714 -0
- podbench-0.1.0b1/src/podbench/proc.py +413 -0
- podbench-0.1.0b1/src/podbench/spec.py +805 -0
- podbench-0.1.0b1/src/podbench/sshcfg.py +501 -0
- podbench-0.1.0b1/src/podbench.egg-info/PKG-INFO +494 -0
- podbench-0.1.0b1/src/podbench.egg-info/SOURCES.txt +135 -0
- podbench-0.1.0b1/src/podbench.egg-info/dependency_links.txt +1 -0
- podbench-0.1.0b1/src/podbench.egg-info/entry_points.txt +2 -0
- podbench-0.1.0b1/src/podbench.egg-info/scm_file_list.json +131 -0
- podbench-0.1.0b1/src/podbench.egg-info/scm_version.json +8 -0
- podbench-0.1.0b1/src/podbench.egg-info/top_level.txt +1 -0
- podbench-0.1.0b1/tests/conftest.py +0 -0
- podbench-0.1.0b1/tests/e2e/README.md +104 -0
- podbench-0.1.0b1/tests/e2e/__init__.py +12 -0
- podbench-0.1.0b1/tests/e2e/apps/README.md +69 -0
- podbench-0.1.0b1/tests/e2e/apps/distroless-c.yaml +112 -0
- podbench-0.1.0b1/tests/e2e/apps/python-service.yaml +143 -0
- podbench-0.1.0b1/tests/e2e/conftest.py +687 -0
- podbench-0.1.0b1/tests/e2e/test_s1_transport.py +362 -0
- podbench-0.1.0b1/tests/e2e/test_s3_gdb.py +215 -0
- podbench-0.1.0b1/tests/e2e/test_s4_iterate.py +358 -0
- podbench-0.1.0b1/tests/e2e/test_s5_ladder.py +250 -0
- podbench-0.1.0b1/tests/e2e/test_uvx_detached.py +317 -0
- podbench-0.1.0b1/tests/test_agent.py +670 -0
- podbench-0.1.0b1/tests/test_chart_contract.py +249 -0
- podbench-0.1.0b1/tests/test_cli.py +9 -0
- podbench-0.1.0b1/tests/test_dev.py +1307 -0
- podbench-0.1.0b1/tests/test_gdbcmd.py +482 -0
- podbench-0.1.0b1/tests/test_image_tag.py +92 -0
- podbench-0.1.0b1/tests/test_kubectl.py +401 -0
- podbench-0.1.0b1/tests/test_launcher.py +1469 -0
- podbench-0.1.0b1/tests/test_packaging.py +23 -0
- podbench-0.1.0b1/tests/test_patch.py +1184 -0
- podbench-0.1.0b1/tests/test_probe.py +768 -0
- podbench-0.1.0b1/tests/test_spec.py +790 -0
- podbench-0.1.0b1/tests/test_sshcfg.py +340 -0
- podbench-0.1.0b1/uv.lock +1479 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ephemeral-containers
|
|
3
|
+
description: What the Kubernetes API will and will not let an ephemeral container do — the constraints that shaped podbench's ladder, dev pods and seat identity. Read before changing spec.py, launcher.py, or anything that authors a container spec.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Ephemeral containers
|
|
7
|
+
|
|
8
|
+
`podbench attach` adds an **ephemeral** container; `podbench dev` authors an
|
|
9
|
+
**ordinary** pod. Most of podbench's odder shapes exist because those two are not
|
|
10
|
+
interchangeable, and the API server enforces the difference. Every rule below was hit
|
|
11
|
+
for real against a cluster, not read in a doc.
|
|
12
|
+
|
|
13
|
+
## They are permanent
|
|
14
|
+
|
|
15
|
+
An ephemeral container cannot be removed, stopped or restarted. Consequences that drive
|
|
16
|
+
real code:
|
|
17
|
+
|
|
18
|
+
- **A name is burnt once used.** A container that exits reaches `Completed` and its name
|
|
19
|
+
is unusable for the pod's lifetime. Hence `kubectl.next_container_name` and the
|
|
20
|
+
`podbench-1`, `-2`, `-3` suffixes — and hence a failing rung must take a *fresh* name
|
|
21
|
+
rather than retry its own.
|
|
22
|
+
- **Never give one a short-lived command.** `spec.AGENT_COMMAND` is the default for this
|
|
23
|
+
reason. A container handed `true` — or handed a verb the CLI does not dispatch — burns
|
|
24
|
+
its name immediately.
|
|
25
|
+
- **The agent must not die.** An unhandled exception in start-up costs a name and, if the
|
|
26
|
+
ladder then walks every rung, three of them. `agent.ensure_all` records failures and
|
|
27
|
+
keeps idling instead of raising. Keep it that way.
|
|
28
|
+
- **An OOM is unrecoverable.** A replacement comes up with a fresh rootfs, losing the
|
|
29
|
+
vscode-server, extensions and host keys. Nothing may live *only* in the writable layer
|
|
30
|
+
that cannot be rebuilt.
|
|
31
|
+
|
|
32
|
+
## They may not use `subPath`
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
spec.ephemeralContainers[0].volumeMounts[0].subPath:
|
|
36
|
+
Forbidden: cannot be set for an Ephemeral Container
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The API server refuses the whole request. There is no workaround: mounting the volume
|
|
40
|
+
somewhere else does not help, because NSS reads `/etc/passwd` and nothing else.
|
|
41
|
+
|
|
42
|
+
This is why the seat's identity has two mechanisms, split by container kind:
|
|
43
|
+
|
|
44
|
+
| | mechanism |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `attach` (ephemeral) | the agent registers its own passwd record, against the image's group-writable `/etc/passwd`, under `--seat-gid-root` |
|
|
47
|
+
| `podbench dev` (ordinary pod) | the projected identity from the chart's `seatIdentity`, mounted with `subPath` — better, since nothing is written and no group 0 is needed |
|
|
48
|
+
|
|
49
|
+
`spec.validate_ephemeral_volume_mounts` enforces it at the authoring layer so it cannot
|
|
50
|
+
recur.
|
|
51
|
+
|
|
52
|
+
## They may only mount volumes the pod already declares
|
|
53
|
+
|
|
54
|
+
Pod volumes are immutable after creation, and an ephemeral container may not introduce
|
|
55
|
+
one. So anything needing a volume — Patch mode's venv claim, the seat's home directory —
|
|
56
|
+
only works where the deployment cooperated at creation time. That is the whole reason
|
|
57
|
+
Patch mode asks for a helm change, and `patch --print-values` emits the ask.
|
|
58
|
+
|
|
59
|
+
`launcher.resolve_mounts` refuses an undeclared volume with an explanation rather than
|
|
60
|
+
letting the API server produce a confusing one.
|
|
61
|
+
|
|
62
|
+
## They may not carry `resources`
|
|
63
|
+
|
|
64
|
+
The field is rejected outright, and the container is confined by the pod's cgroup
|
|
65
|
+
regardless. So on a live pod podbench **shares the workload's memory and
|
|
66
|
+
ephemeral-storage limits and cannot reserve its own** — the biggest footgun in the
|
|
67
|
+
product, and the reason Iterate mode authors a real pod (where the sidecar *can* have
|
|
68
|
+
resources) instead of attaching.
|
|
69
|
+
|
|
70
|
+
The mitigation is `kubectl patch pod --subresource resize`, offered behind `--resize`
|
|
71
|
+
and only lightly proven (one cluster, one pod, never against a `LimitRange` or a
|
|
72
|
+
controller that would fight it).
|
|
73
|
+
|
|
74
|
+
## `capabilities.add` on a non-root uid is a silent no-op
|
|
75
|
+
|
|
76
|
+
The kernel grants capabilities to a non-zero uid only through the ambient set, which no
|
|
77
|
+
CRI populates. `capabilities.add: [SYS_PTRACE]` beside `runAsUser: 1000` is **admitted**
|
|
78
|
+
and produces `CapEff: 0000000000000000`: a container that looks privileged and behaves
|
|
79
|
+
unprivileged.
|
|
80
|
+
|
|
81
|
+
The ladder therefore has exactly two capability rungs and no middle ground, and
|
|
82
|
+
`spec.validate_security_context` raises rather than emitting the combination. Do not
|
|
83
|
+
"fix" a failing degraded rung by adding the capability back.
|
|
84
|
+
|
|
85
|
+
## Refusal arrives through two unrelated channels
|
|
86
|
+
|
|
87
|
+
- **Synchronous** — Pod Security Admission, in `kubectl`'s stderr, matched on the stable
|
|
88
|
+
substring `must not include "SYS_PTRACE" in securityContext.capabilities.add`.
|
|
89
|
+
- **Asynchronous** — the kubelet, *seconds later*, in the container's status:
|
|
90
|
+
`CreateContainerConfigError` / `container's runAsUser breaks non-root policy`. The API
|
|
91
|
+
call already exited 0.
|
|
92
|
+
|
|
93
|
+
Only the first can be caught by wrapping the call, and only the second burns a name — so
|
|
94
|
+
each needs its own arm of the walk. Pre-empt the second by reading the target pod's
|
|
95
|
+
`securityContext.runAsNonRoot` before trying a root container.
|
|
96
|
+
|
|
97
|
+
## Attribution: which processes belong to the target
|
|
98
|
+
|
|
99
|
+
Under a shared PID namespace the debug container sees everything, including its own
|
|
100
|
+
processes and any other podbench session's. The only attribution that stays correct is a
|
|
101
|
+
substring match of the target's container id against `/proc/<pid>/cgroup`, injected as
|
|
102
|
+
`PODBENCH_TARGET_CID` (`model.TARGET_CID_ENV`).
|
|
103
|
+
|
|
104
|
+
The cgroup-difference fallback is a guess. `proc.scan_processes` returns
|
|
105
|
+
`Attribution.CGROUP_FALLBACK` and a warning so callers can say so rather than present it
|
|
106
|
+
as fact. PID 1 is *not* reliably the target — under `--target` it is often `/pause`.
|
|
107
|
+
|
|
108
|
+
## Dev pods are clones, and clones carry junk
|
|
109
|
+
|
|
110
|
+
`spec.dev_pod_spec` strips what the API server owns or what would make a controller adopt
|
|
111
|
+
the clone. Two that were learned the hard way:
|
|
112
|
+
|
|
113
|
+
- **`spec.ephemeralContainers`** — `Forbidden: cannot be set on create`. Cloning any pod
|
|
114
|
+
that had ever been attached to failed until this was popped.
|
|
115
|
+
- **Controller labels** (`pod-template-hash` and friends) — keeping them gives a
|
|
116
|
+
`replicas: 1` ReplicaSet two matching pods and one gets reaped.
|
|
117
|
+
|
|
118
|
+
`kubectl debug --copy-to` is not an alternative: it strips **all** labels, so the clone
|
|
119
|
+
never joins the Service, which is the demo. That is why the launcher authors the spec
|
|
120
|
+
itself — and why it can also add resources, volumes and a real sidecar.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ssh-over-exec
|
|
3
|
+
description: The invariants of podbench's ssh-through-kubectl-exec transport, all of which fail silently or misleadingly when broken. Read before touching sshcfg.py, agent.py, or anything that generates a ProxyCommand or an sshd config.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# ssh over `kubectl exec`
|
|
7
|
+
|
|
8
|
+
The transport is a complete OpenSSH connection whose only carrier is `kubectl exec`:
|
|
9
|
+
`sshd -i` runs inside the debug container as the client's `ProxyCommand`, so there is no
|
|
10
|
+
listening socket, no port-forward and no pod IP. Auth to the cluster is the kubeconfig;
|
|
11
|
+
auth to the container is a key.
|
|
12
|
+
|
|
13
|
+
**Every rule here has a silent or misleading failure mode.** That is why the client
|
|
14
|
+
config, the server config and the ProxyCommand are generated from one place and never
|
|
15
|
+
hand-written, and why `tests/test_sshcfg.py` is full of exact-string assertions. The
|
|
16
|
+
regression to fear is a well-meaning tidy-up, not a crash.
|
|
17
|
+
|
|
18
|
+
## `-e` is mandatory, and not for the reason it looks
|
|
19
|
+
|
|
20
|
+
`sshd -i -e`. The flag is **not** about log tidiness — it is about keeping **fd 2 open**.
|
|
21
|
+
|
|
22
|
+
Closing or redirecting stderr in a `kubectl exec`'d process tears down the whole CRI exec
|
|
23
|
+
stream and silently truncates stdio with `rc=0`:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
( echo one; sleep 4; echo two ) | kubectl exec -i pod -c c -- sh -c 'exec cat'
|
|
27
|
+
one
|
|
28
|
+
two # both arrive
|
|
29
|
+
|
|
30
|
+
( echo one; sleep 4; echo two ) | kubectl exec -i pod -c c -- sh -c 'exec 2>/dev/null; exec cat'
|
|
31
|
+
one # "two" SILENTLY LOST, rc=0
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Against sshd it surfaces as a network error — `ssh_dispatch_run_fatal: … Broken pipe`,
|
|
35
|
+
dying at `expecting SSH2_MSG_KEX_ECDH_REPLY` — which sends you debugging the wrong layer.
|
|
36
|
+
|
|
37
|
+
| ProxyCommand | result |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `sshd -i -e` | works |
|
|
40
|
+
| `sshd -i -E /tmp/log` | works (`-E` implies `log_stderr=1`) |
|
|
41
|
+
| `sshd -i` | **fails, reproducibly** |
|
|
42
|
+
| `sh -c '/usr/sbin/sshd -i'` (no `exec`, shell holds fd 2) | works — **masks the bug** |
|
|
43
|
+
| `sh -c 'exec /usr/sbin/sshd -i'` | fails |
|
|
44
|
+
| `sh -c 'exec /usr/sbin/sshd -i -e 2>&1'` | fails |
|
|
45
|
+
|
|
46
|
+
Two spikes disagreed about this (S2 ran without `-e` for a whole session), so the shipped
|
|
47
|
+
form is `-e -o LogLevel=ERROR`: zero stderr bytes, fd 2 still open. `tests/e2e/test_s1_transport.py::test_transport_dies_without_dash_e`
|
|
48
|
+
edits the config podbench *actually generates* and asserts the transport breaks — if it
|
|
49
|
+
ever fails, settle the contradiction, do not delete the flag.
|
|
50
|
+
|
|
51
|
+
## Never `-t`
|
|
52
|
+
|
|
53
|
+
`kubectl exec -t` silently degrades to non-tty from a script, so it looks fine — and
|
|
54
|
+
**hangs the ssh client forever** when a real TTY is present. There is no case where the
|
|
55
|
+
transport wants a TTY.
|
|
56
|
+
|
|
57
|
+
## Never redirect or merge stderr
|
|
58
|
+
|
|
59
|
+
Any `2>&1`, `>/dev/null`, or wrapper that closes fd 2 breaks the transport per the above.
|
|
60
|
+
`proxy_command` returns argv (no shell) so there is nowhere to introduce one.
|
|
61
|
+
|
|
62
|
+
## `ControlPath` must be short
|
|
63
|
+
|
|
64
|
+
`sizeof(sockaddr_un.sun_path)` is 108 bytes. Put the socket next to a kubeconfig or in a
|
|
65
|
+
workspace and ssh refuses with `ControlPath too long`. Hence `/tmp/podbench-cm/%C` and
|
|
66
|
+
`control_path_ok`.
|
|
67
|
+
|
|
68
|
+
**Create the parent directory.** ssh will not, and the failure reads like a transport
|
|
69
|
+
fault: `unix_listener: cannot bind to path …: No such file or directory`.
|
|
70
|
+
`write_ssh_config` calls `ensure_control_dir` because writing the config is when the path
|
|
71
|
+
is known.
|
|
72
|
+
|
|
73
|
+
## `ServerAliveInterval` is mandatory
|
|
74
|
+
|
|
75
|
+
A *stalled* transport — what an apiserver or konnectivity hiccup looks like — hangs ssh
|
|
76
|
+
**forever** with no keepalive. With `ServerAliveInterval 15` / `ServerAliveCountMax 3` it
|
|
77
|
+
fails in seconds. A hard kill or pod deletion is detected instantly either way.
|
|
78
|
+
|
|
79
|
+
## sshd does not leak its own environment
|
|
80
|
+
|
|
81
|
+
The launcher injects `PODBENCH_TARGET_CID` into the container spec and it reaches the
|
|
82
|
+
container — but **not** an ssh session, and a non-interactive `ssh host 'pids'` sources no
|
|
83
|
+
profile either. Without forwarding, the in-pod helpers fall back to *guessing* which
|
|
84
|
+
processes belong to the target.
|
|
85
|
+
|
|
86
|
+
`SetEnv` in the sshd config is the only route that survives. And:
|
|
87
|
+
|
|
88
|
+
> **One `SetEnv` directive carrying every pair, never one per variable.** sshd resolves
|
|
89
|
+
> each keyword **first-match-wins**, so a second `SetEnv` line is silently ignored. This
|
|
90
|
+
> shipped once: only `PODBENCH_NODE_NAME` arrived and `PODBENCH_TARGET_CID` did not.
|
|
91
|
+
|
|
92
|
+
Values containing whitespace are dropped — a space ends the pair early.
|
|
93
|
+
|
|
94
|
+
## Nothing is on `PATH` in an ssh session
|
|
95
|
+
|
|
96
|
+
`ssh host '<cmd>'` runs a non-interactive shell that sources nothing and does not inherit
|
|
97
|
+
the image's `ENV PATH`. Every helper in `image/bin/` names `/app/.venv/bin/podbench` by
|
|
98
|
+
absolute path for exactly this reason. If you add a helper, do the same.
|
|
99
|
+
|
|
100
|
+
## sshd needs an NSS identity
|
|
101
|
+
|
|
102
|
+
sshd resolves the login name through NSS **before** it looks at a key, so a uid with no
|
|
103
|
+
`/etc/passwd` entry fails as `Permission denied (publickey)` — pointing at the key, which
|
|
104
|
+
is not the problem. `ssh-keygen` cannot even mint a host key (`No user exists for uid
|
|
105
|
+
1000`), and `-C` does not help: it calls `getpwuid()` regardless.
|
|
106
|
+
|
|
107
|
+
See the `ephemeral-containers` skill for the two mechanisms that supply an identity and
|
|
108
|
+
why they differ by container kind.
|
|
109
|
+
|
|
110
|
+
## Host keys
|
|
111
|
+
|
|
112
|
+
Fresh keys per attach would mean either `StrictHostKeyChecking no` — teaching users to
|
|
113
|
+
disable host verification — or a warning on every new pod. podbench instead manages
|
|
114
|
+
`known_hosts` programmatically, keyed on `HostKeyAlias podbench-<pod uid>`, and supports a
|
|
115
|
+
stable key from a Secret. Do not "simplify" this to `no`.
|
|
116
|
+
|
|
117
|
+
## Measured budgets
|
|
118
|
+
|
|
119
|
+
Cold connect ~0.345 s; ~0.06 s over `ControlMaster` (≈6×). ~26 MB/s pod→client, ~13 MB/s
|
|
120
|
+
client→pod. ~10 MB RSS per live session. 600 s idle survives with no keepalives; a
|
|
121
|
+
stalled transport needs them.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changes here will be overwritten by Copier
|
|
2
|
+
_commit: 5.4.0
|
|
3
|
+
_src_path: git@github.com:diamondlightsource/python-copier-template
|
|
4
|
+
author_email: gilesknap@gmail.com
|
|
5
|
+
author_name: Giles Knap
|
|
6
|
+
description: debugging container for kubernetes pods
|
|
7
|
+
distribution_name: podbench
|
|
8
|
+
docker: true
|
|
9
|
+
docs_type: sphinx
|
|
10
|
+
git_platform: github.com
|
|
11
|
+
github_org: gilesknap
|
|
12
|
+
package_name: podbench
|
|
13
|
+
pypi: true
|
|
14
|
+
repo_name: podbench
|
|
15
|
+
strict_typing: true
|
|
16
|
+
type_checker: pyright
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// For format details, see https://containers.dev/implementors/json_reference/
|
|
2
|
+
{
|
|
3
|
+
"name": "Python 3 Developer Container",
|
|
4
|
+
"build": {
|
|
5
|
+
"dockerfile": "../Dockerfile",
|
|
6
|
+
"target": "developer"
|
|
7
|
+
},
|
|
8
|
+
"remoteEnv": {
|
|
9
|
+
// Allow X11 apps to run inside the container
|
|
10
|
+
"DISPLAY": "${localEnv:DISPLAY}",
|
|
11
|
+
// Put things that allow it in the persistent cache
|
|
12
|
+
"PRE_COMMIT_HOME": "/cache/pre-commit",
|
|
13
|
+
"UV_CACHE_DIR": "/cache/uv",
|
|
14
|
+
"UV_PYTHON_CACHE_DIR": "/cache/uv-python",
|
|
15
|
+
// Make a venv that is specific for this workspace path as the cache is shared
|
|
16
|
+
"UV_PROJECT_ENVIRONMENT": "/cache/venv-for${localWorkspaceFolder}",
|
|
17
|
+
// Do the equivalent of "activate" the venv so we don't have to "uv run" everything
|
|
18
|
+
"VIRTUAL_ENV": "/cache/venv-for${localWorkspaceFolder}",
|
|
19
|
+
"PATH": "/cache/venv-for${localWorkspaceFolder}/bin:${containerEnv:PATH}"
|
|
20
|
+
},
|
|
21
|
+
"customizations": {
|
|
22
|
+
"vscode": {
|
|
23
|
+
// Set *default* container specific settings.json values on container create.
|
|
24
|
+
"settings": {
|
|
25
|
+
// Use the container's python by default
|
|
26
|
+
"python.defaultInterpreterPath": "/cache/venv-for${localWorkspaceFolder}/bin/python",
|
|
27
|
+
// Don't activate the venv as it is already in the PATH
|
|
28
|
+
"python.terminal.activateEnvInCurrentTerminal": false,
|
|
29
|
+
"python.terminal.activateEnvironment": false,
|
|
30
|
+
// Workaround to prevent garbled python REPL in the terminal
|
|
31
|
+
// https://github.com/microsoft/vscode-python/issues/25505
|
|
32
|
+
"python.terminal.shellIntegration.enabled": false
|
|
33
|
+
},
|
|
34
|
+
// Add the IDs of extensions you want installed when the container is created.
|
|
35
|
+
"extensions": [
|
|
36
|
+
"ms-python.python",
|
|
37
|
+
"github.vscode-github-actions",
|
|
38
|
+
"tamasfe.even-better-toml",
|
|
39
|
+
"redhat.vscode-yaml",
|
|
40
|
+
"ryanluker.vscode-coverage-gutters",
|
|
41
|
+
"charliermarsh.ruff",
|
|
42
|
+
"ms-azuretools.vscode-docker"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
// Create the config folder for the bash-config feature and uv cache
|
|
47
|
+
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config",
|
|
48
|
+
"runArgs": [
|
|
49
|
+
// Allow the container to access the host X11 display and EPICS CA
|
|
50
|
+
"--net=host",
|
|
51
|
+
// Make sure SELinux does not disable with access to host filesystems like tmp
|
|
52
|
+
"--security-opt=label=disable"
|
|
53
|
+
],
|
|
54
|
+
"mounts": [
|
|
55
|
+
// Mount in the user terminal config folder so it can be edited
|
|
56
|
+
{
|
|
57
|
+
"source": "${localEnv:HOME}/.config/terminal-config",
|
|
58
|
+
"target": "/user-terminal-config",
|
|
59
|
+
"type": "bind"
|
|
60
|
+
},
|
|
61
|
+
// Keep a persistent cross container cache for uv, pre-commit, and the venvs
|
|
62
|
+
{
|
|
63
|
+
"source": "devcontainer-shared-cache",
|
|
64
|
+
"target": "/cache",
|
|
65
|
+
"type": "volume"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
// Mount the parent as /workspaces so we can pip install peers as editable
|
|
69
|
+
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
|
|
70
|
+
// After the container is created, recreate the venv then make pre-commit first run faster
|
|
71
|
+
"postCreateCommand": "uv venv --clear && uv sync && pre-commit install --install-hooks"
|
|
72
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# .git is deliberately NOT ignored: the build stage runs setuptools_scm, which
|
|
2
|
+
# derives the version from git metadata, so `uv sync` cannot build the project
|
|
3
|
+
# without it (and _version.py is itself gitignored).
|
|
4
|
+
|
|
5
|
+
# Build and test outputs - regenerated inside the image, and a stale .venv from
|
|
6
|
+
# the host would be the wrong architecture.
|
|
7
|
+
.venv/
|
|
8
|
+
build/
|
|
9
|
+
dist/
|
|
10
|
+
docs/_build/
|
|
11
|
+
.tox/
|
|
12
|
+
*.egg-info/
|
|
13
|
+
**/__pycache__/
|
|
14
|
+
*.py[cod]
|
|
15
|
+
|
|
16
|
+
# Caches and coverage
|
|
17
|
+
.pytest_cache/
|
|
18
|
+
.ruff_cache/
|
|
19
|
+
.mypy_cache/
|
|
20
|
+
.coverage
|
|
21
|
+
cov.xml
|
|
22
|
+
|
|
23
|
+
# Editor and container tooling that never reaches the runtime image
|
|
24
|
+
.devcontainer/
|
|
25
|
+
.vscode/
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Contribute to the project
|
|
2
|
+
|
|
3
|
+
Contributions and issues are most welcome! All issues and pull requests are
|
|
4
|
+
handled through [GitHub](https://github.com/gilesknap/podbench/issues). Also, please check for any existing issues before
|
|
5
|
+
filing a new one. If you have a great idea but it involves big changes, please
|
|
6
|
+
file a ticket before making a pull request! We want to make sure you don't spend
|
|
7
|
+
your time coding something that might not fit the scope of the project.
|
|
8
|
+
|
|
9
|
+
## Issue or Discussion?
|
|
10
|
+
|
|
11
|
+
Github also offers [discussions](https://github.com/gilesknap/podbench/discussions) as a place to ask questions and share ideas. If
|
|
12
|
+
your issue is open ended and it is not obvious when it can be "closed", please
|
|
13
|
+
raise it as a discussion instead.
|
|
14
|
+
|
|
15
|
+
## Code Coverage
|
|
16
|
+
|
|
17
|
+
While 100% code coverage does not make a library bug-free, it significantly
|
|
18
|
+
reduces the number of easily caught bugs! Please make sure coverage remains the
|
|
19
|
+
same or is improved by a pull request!
|
|
20
|
+
|
|
21
|
+
## Developer Information
|
|
22
|
+
|
|
23
|
+
It is recommended that developers use a [vscode devcontainer](https://code.visualstudio.com/docs/devcontainers/containers). This repository contains configuration to set up a containerized development environment that suits its own needs.
|
|
24
|
+
|
|
25
|
+
This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.
|
|
26
|
+
|
|
27
|
+
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/5.4.0/how-to.html).
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug Report
|
|
3
|
+
about: The template to use for reporting bugs and usability issues
|
|
4
|
+
title: " "
|
|
5
|
+
labels: 'bug'
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Describe the bug, including a clear and concise description of the expected behaviour, the actual behavior and the context in which you encountered it (ideally include details of your environment).
|
|
11
|
+
|
|
12
|
+
## Steps To Reproduce
|
|
13
|
+
Steps to reproduce the behavior:
|
|
14
|
+
1. Go to '...'
|
|
15
|
+
2. Click on '....'
|
|
16
|
+
3. Scroll down to '....'
|
|
17
|
+
4. See error
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Acceptance Criteria
|
|
21
|
+
- Specific criteria that will be used to judge if the issue is fixed
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Issue
|
|
3
|
+
about: The standard template to use for feature requests, design discussions and tasks
|
|
4
|
+
title: " "
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
A brief description of the issue, including specific stakeholders and the business case where appropriate
|
|
11
|
+
|
|
12
|
+
## Acceptance Criteria
|
|
13
|
+
- Specific criteria that will be used to judge if the issue is fixed
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Make switcher.json to allow docs to switch between different versions."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import logging
|
|
5
|
+
from argparse import ArgumentParser
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from subprocess import CalledProcessError, check_output
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def report_output(stdout: bytes, label: str) -> list[str]:
|
|
11
|
+
"""Print and return something received frm stdout."""
|
|
12
|
+
ret = stdout.decode().strip().split("\n")
|
|
13
|
+
print(f"{label}: {ret}")
|
|
14
|
+
return ret
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def get_branch_contents(ref: str) -> list[str]:
|
|
18
|
+
"""Get the list of directories in a branch."""
|
|
19
|
+
stdout = check_output(["git", "ls-tree", "-d", "--name-only", ref])
|
|
20
|
+
return report_output(stdout, "Branch contents")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_sorted_tags_list() -> list[str]:
|
|
24
|
+
"""Get a list of sorted tags in descending order from the repository."""
|
|
25
|
+
stdout = check_output(["git", "tag", "-l", "--sort=-v:refname"])
|
|
26
|
+
return report_output(stdout, "Tags list")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def get_versions(ref: str, add: str | None) -> list[str]:
|
|
30
|
+
"""Generate the file containing the list of all GitHub Pages builds."""
|
|
31
|
+
# Get the directories (i.e. builds) from the GitHub Pages branch
|
|
32
|
+
try:
|
|
33
|
+
builds = set(get_branch_contents(ref))
|
|
34
|
+
except CalledProcessError:
|
|
35
|
+
builds = set()
|
|
36
|
+
logging.warning(f"Cannot get {ref} contents")
|
|
37
|
+
|
|
38
|
+
# Add and remove from the list of builds
|
|
39
|
+
if add:
|
|
40
|
+
builds.add(add)
|
|
41
|
+
|
|
42
|
+
# Get a sorted list of tags
|
|
43
|
+
tags = get_sorted_tags_list()
|
|
44
|
+
|
|
45
|
+
# Make the sorted versions list from main branches and tags
|
|
46
|
+
versions: list[str] = []
|
|
47
|
+
for version in ["master", "main"] + tags:
|
|
48
|
+
if version in builds:
|
|
49
|
+
versions.append(version)
|
|
50
|
+
builds.remove(version)
|
|
51
|
+
|
|
52
|
+
# Add in anything that is left to the bottom
|
|
53
|
+
versions += sorted(builds)
|
|
54
|
+
print(f"Sorted versions: {versions}")
|
|
55
|
+
return versions
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def write_json(path: Path, repository: str, versions: list[str]):
|
|
59
|
+
"""Write the JSON switcher to path."""
|
|
60
|
+
org, repo_name = repository.split("/")
|
|
61
|
+
struct = [
|
|
62
|
+
{"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"}
|
|
63
|
+
for version in versions
|
|
64
|
+
]
|
|
65
|
+
text = json.dumps(struct, indent=2)
|
|
66
|
+
print(f"JSON switcher:\n{text}")
|
|
67
|
+
path.write_text(text, encoding="utf-8")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def main(args=None):
|
|
71
|
+
"""Parse args and write switcher."""
|
|
72
|
+
parser = ArgumentParser(
|
|
73
|
+
description="Make a versions.json file from gh-pages directories"
|
|
74
|
+
)
|
|
75
|
+
parser.add_argument(
|
|
76
|
+
"--add",
|
|
77
|
+
help="Add this directory to the list of existing directories",
|
|
78
|
+
)
|
|
79
|
+
parser.add_argument(
|
|
80
|
+
"repository",
|
|
81
|
+
help="The GitHub org and repository name: ORG/REPO",
|
|
82
|
+
)
|
|
83
|
+
parser.add_argument(
|
|
84
|
+
"output",
|
|
85
|
+
type=Path,
|
|
86
|
+
help="Path of write switcher.json to",
|
|
87
|
+
)
|
|
88
|
+
args = parser.parse_args(args)
|
|
89
|
+
|
|
90
|
+
# Write the versions file
|
|
91
|
+
versions = get_versions("origin/gh-pages", args.add)
|
|
92
|
+
write_json(args.output, args.repository, versions)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
main()
|