Files
werewulf/CLAUDE.md
T
ilker 95dfb8ec12 Add CLAUDE.md, and stop re-running installs on every tenant
The working rules come first because they are what the rest of this commit
came out of. Every expensive mistake in this work had one shape: an action
reported success, had not changed anything, and a measurement was built on
top of it. A sed whose pattern did not match. A str.replace guarded by an
assertion that only checked the value was absent beforehand. A wwctl image
import that refused an existing name, so a full boot measurement ran against
the old image and 234s was reported as real. A pgrep completion check that
matched its own shell and could never report completion. The rule is to read
the changed state back rather than trust an exit code, and to assert what a
measurement depends on before measuring.

Profiling a cold provision - which needed a fix of its own, since the
first-boot runner started ansible-playbook from / and so never loaded
ansible.cfg at all, quietly using stock defaults for the tmp paths that file
exists to set - showed one task dominating: 33.6s of the 80s went to
"Install epel-release", which installs nothing. The template already has it.
The time was dnf rebuilding the metadata cache that the template build
deletes on its way out; the same task against a warm cache takes 2.7s.

Keeping the cache would have been the smaller fix and the wrong one: the
saving decays as the template ages and dnf expires the metadata anyway. The
first-boot path now skips install-tagged tasks outright. They put software
on disk, this only ever runs on a clone of a template that has it, and
skipping them also takes EPEL and OpenHPC back out of the provisioning path
- an outage at either meant no tenant could be created at all. The control
plane still runs the full playbook for day-2 work.

The template cleanup now also removes /root/.docker/config.json. With the
image inherited rather than pulled, no tenant needs the registry credential,
and leaving it there shipped one - narrow, read-only, but real - into every
tenant ever cloned. A control-plane run that does need to pull writes it
again from the environment.

Task profiling is on permanently. A provision getting slower is the failure
mode here, and without per-task timings the only way to find out where the
time went is to instrument it again afterwards, on a cluster that has since
been destroyed.

Not yet measured: the expected drop from 80s. Last verified provision was
178s total - terraform 32s, configuration 80s, node PXE 66s.
2026-09-02 15:03:37 +02:00

94 lines
4.0 KiB
Markdown

# Working rules for this repository
## Verify the effect, never the intent
Every mistake that has cost real time in this repository has the same shape:
an action was taken, the action reported success, the action had not actually
done anything, and a measurement or a conclusion was built on top of it.
The exit code tells you the command ran. It does not tell you the state
changed. These are different questions and only the second one matters.
**After changing something, read the changed thing back.** Not the command's
output — the state itself.
```bash
# Wrong: the edit is assumed to have landed
sed -i 's/foo/bar/' file && next_step
# Right: the new state is confirmed before anything depends on it
sed -i 's/foo/bar/' file
grep -q bar file || { echo "edit did not land"; exit 1; }
```
This has happened here with `sed` (pattern did not match because the file
used different spacing), with a Python `str.replace` (same cause, and the
assertion checked only that the value was absent beforehand, not that it was
present after), and with `wwctl image import`, which prints
`ERROR: image name exists` and leaves the old image in place. In the last
case a full boot measurement was taken against the wrong image and the
resulting number was reported as real.
When writing a guard, assert the postcondition, not the precondition.
## Assert what a measurement depends on, before measuring
A measurement of the wrong thing is worse than no measurement, because it
gets reported and believed. Before timing anything, check that the change
under test is actually in place, and abort loudly if it is not.
```bash
WW=$(ssh $HEAD "lsinitrd .../initramfs-*.img | grep -c wwinit")
[ "$WW" = "0" ] && { echo "ABORT: new image is not in place"; exit 1; }
```
The measurement chain here is expensive — a template build is ~4 minutes and
a provision ~3 — so a wasted cycle is not free, and a wrong number wastes
more than a cycle.
## A completion check must not match itself
`pgrep -f B20-build` run inside `bash -c '... pgrep -f B20-build ...'`
matches its own shell. It always reports "running", so the loop never exits
and the work looks unfinished forever.
Match on something that cannot be the checker: a pid file, a marker the job
writes on exit, or a pattern that excludes the checking process.
## Completion checks must cover failure, not just success
Grepping a log for the success marker is silent when the job crashed, hung,
or was killed — and silence is indistinguishable from "still working". Cover
every terminal state:
```bash
grep -E "TEMPLATE READY|failed=[1-9]|ERROR!|fatal:" "$LOG"
```
Prefer a single command that exits when the condition is true (run in the
background, one notification on exit) over a hand-rolled polling loop. Where
a loop is unavoidable, remember that a dropped SSH connection yields an empty
result, which is neither success nor failure — decide explicitly what that
means instead of letting it fall through.
## Batch changes into one verification cycle
One rebuild that validates four fixes beats four rebuilds. When a fix is
found mid-cycle, stop the cycle, fold the fix in, and restart once.
## Tools in this stack that fail quietly
- `wwctl profile set --nettagadd` exits 0 and changes nothing. Read the
profile back with `wwctl profile list -a` after writing it.
- `wwctl image import` refuses an existing name and exits non-zero, but the
surrounding pipeline may swallow it. Pass `--force` when replacing.
- `wwctl` needs `$HOME`. systemd units do not set one, so a playbook that
works over SSH fails as a service until `Environment=HOME=/root` is set.
- Ansible finds `ansible.cfg` relative to the working directory. A playbook
run from `/` silently uses stock defaults. Set `ANSIBLE_CONFIG` explicitly.
- Playbook-adjacent `group_vars/all.yml` outranks an inventory's own group
vars. A value left there overrides the inventory rather than defaulting
behind it.
- `podman build --squash` keeps the base image layers, so files deleted in
later layers still ship. Use `--squash-all` when size is the point.