Repository navigation
feat(infra): apply a saved plan one node at a time - #5271
Conversation
`devops infra apply <repo> <playbook> --plan <id>` applies a saved plan of `devops infra plan`. The caller gives the playbook, limit and tags of the plan. An agent needs the level safe for a plan with no disruptive class and no unchecked task, else full. The guards refuse a plan whose facts do not give its id, a failed or old plan, a commit that origin does not hold, for an agent a commit off the default branch that is not the head of an open pull request at full, host key checks off for an agent, and a cluster that is not healthy. The hosts with no disruptive class run together. Each disruptive host runs alone in plan order: drain check (server dry run), drain, a fresh check that must equal the plan, the run, Ready with the GPUs of before, health, and uncordon only when the node was schedulable before. The first failure or an unplanned change stops the apply and leaves the node cordoned. Each apply writes the audit record infra.apply and adds to devops_cli_infra_runs_total. --dry-run starts no process. SECURITY.md gets the section Infra Repos. AGENTS.md says that only a person changes hardware; the design text does not fit its cap.
The live apply on condor stopped at the drain: the roadmap Service pod has a grace period of 660 s, and infra.drain_timeout_seconds is 180 s. The drain bound is now the setting, or the longest grace period of a pod that the drain evicts and 60 s, when that is longer.
A pod that mounts a volume that only its node can mount cannot start on another node, so it is down from the drain until the uncordon. In the live apply on condor, the roadmap Service was down for 11 minutes this way. Before the drain check of each disruptive host, the apply reads the pods of the node, the claims and the volumes, and the report and the audit record of the host name each such workload. The apply does not stop for them.
On homelab, prometheus-server mounts a volume that only one agent node mounts. A health gate that reads the alerts before the uncordon of that node never passes. After a host, the apply now waits for the health of the nodes before the uncordon, and for the critical alerts after it.
Live run on dan-petty/homelab (2026-11-12, agent, level
|
| Node | Memory capacity | Allocatable before | Allocatable after | GPU before / after | Cordoned before / after | kubelet start (k3s restart) |
|---|---|---|---|---|---|---|
| hawk | 16240676Ki (15.5 GiB) | 16240676Ki | 13631524Ki (13.0 GiB) | 1 / 1 | yes / yes | 21:15:42Z |
| condor | 65566396Ki (62.5 GiB) | 65566396Ki | 60860092Ki (58.0 GiB) | 2 / 2 | no / no | 21:40:41Z |
| gemini | 65566984Ki (62.5 GiB) | 65566984Ki | 60860680Ki (58.0 GiB) | 2 / 2 | no / no | 22:06:15Z |
| hog | 65634428Ki (62.6 GiB) | 65634428Ki | 65634428Ki (not applied) | 2 / 2 | no / no | not restarted |
Allocatable is now below capacity on the 3 applied nodes: hawk by 2.5 GiB (1Gi + 1Gi + 500Mi of its host_vars), condor and gemini by 4.5 GiB (1Gi + 3Gi + 500Mi). hawk stays cordoned, because it was cordoned before.
Audit records (infra.apply)
| Time | Apply id | Result | Caller | Level | Playbook | Limit | Plan | Commit | Hosts | Duration |
|---|---|---|---|---|---|---|---|---|---|---|
| 21:04:15Z | 88f372f13c1a4d0194560717a45c74aa |
refused | agent (claude_code) | full | 03_k3s.yaml |
hawk.lan | da9629acaf9e |
19f0457 |
- | 3 s |
| 21:16:25Z | 99225fc1413e45729cb1a63cacbc6cdd |
ok | agent (claude_code) | full | 03_k3s.yaml |
hawk.lan | da9629acaf9e |
19f0457 |
hawk.lan applied, 2 runs | 65 s |
| 21:20:46Z | 9cdc6d56c88a4341aff397a3266b7cde |
stopped | agent (claude_code) | full | 03_k3s.yaml |
condor.lan | 9ad5a8af09ff |
19f0457 |
condor.lan stopped at drain, 0 runs | 186 s |
| 21:41:24Z | 2edacdd7af07400eb6b00978dd8835a7 |
ok | agent (claude_code) | full | 03_k3s.yaml |
condor.lan | 9ad5a8af09ff |
19f0457 |
condor.lan applied, 2 runs | 673 s |
| 22:07:51Z | a5c27b50ce21408fa181639e5eac4277 |
ok | agent (claude_code) | full | 03_k3s.yaml |
gemini.lan | ec0e76e8cecb |
19f0457 |
gemini.lan applied, 2 runs; down during the apply: llm/qdrant, logging/loki, monitoring/grafana, monitoring/prometheus-server | 137 s |
| 22:12:20Z | 63f8474a161a4c6ba1259fef612149db |
ok | agent (claude_code) | full | 13_crash_capture.yaml |
hawk.lan | 0f75ad9c9389 |
19f0457 |
hawk.lan applied, 2 runs | 109 s |
Each record has the caller and tool, level, repo, commit, ref, plan id, playbook, limit, tags, result, reason, and each host with its node, disruptive classes, outcome, step, reason, runner idents and the workloads that were down. No record holds a key path or task output.
Each host
hawk, homelab #19 (plan da9629acaf9e…, service-restart:k3s-agent, 2 changes, 1 with the diff hidden). The first try refused at the health gate before any host step: the critical alert RoadmapServiceGitHubThrottled fires (it fired 20:59:11Z to 21:14:38Z, GitHub throttles of the roadmap Service). I waited until it cleared, then made the one retry: drain check, drain (DaemonSets only), fresh check equal to the plan, run (ok=9 changed=2), Ready with 1 GPU, health; no uncordon, because hawk was cordoned before. hawk was Ready for the whole apply.
condor, homelab #19 (plan 9ad5a8af09ff…). The first try stopped at the drain: kubectl drain condor ... --timeout=180s stopped with exit code 1: error when waiting for pod "roadmap-service-6c77cf7b89-dpxz6" in namespace "devops" to terminate: context deadline exceeded. The roadmap Service pod has terminationGracePeriodSeconds: 660, and infra.drain_timeout_seconds is 180. condor did not change (no fresh check, no run), but the drain left it cordoned. The new Service pod can run only on condor (its local volume is there), so it stayed Pending. Commit "fix(infra): let the drain wait for the longest grace period of a pod" fixes the cause. After the old pod stopped, I ran kubectl --context homelab-k3s uncordon condor once at about 21:28:40Z, to put back the state from before my run; this is the only node step of the run outside devops infra. When the Service was Ready again, the one retry ran: drain bound 720 s (it waited for the 11-minute graceful drain of the Service), fresh check, run (ok=9 changed=2), Ready, health, uncordon by the apply at 21:41:31Z. The roadmap Service was down from about 21:17:45Z to 21:41:35Z.
gemini, homelab #19 (plan ec0e76e8cecb…). Before the apply, the pre-flight read named the workloads that only gemini can run (local volumes): llm/qdrant (StatefulSet), logging/loki (StatefulSet), monitoring/grafana (Deployment), monitoring/prometheus-server (Deployment). They were down from the drain (22:05:46Z) until they started again after the uncordon (22:06:59Z). Because prometheus-server runs only on gemini, the apply now waits for the nodes before the uncordon and for the critical alerts after it (commit "fix(infra): wait for the alerts after the uncordon of a host"). Drain bound 360 s (prometheus-server has 300 s), run ok=9 changed=2, Ready, uncordon.
hog, homelab #19: not applied. The plan bebb9d16a876… failed in check mode, so the apply cannot run: the task "Adjust server endpoint in local kubeconfig" (ansible.builtin.replace with delegate_to: localhost) edits a kubeconfig that "Fetch kubeconfig from server to control machine" does not write in check mode (Path ... does not exist !). I commented the evidence on dan-petty/homelab#10, which removes that fetch. I opened no maintenance window and changed no PodDisruptionBudget or CNPG Cluster. For a later apply of hog, the facts are:
- The drain check of hog (
kubectl drain hog --dry-run=server) stops at two CloudNativePG clusters with 1 instance each, whose primary PodDisruptionBudget allows 0 disruptions:llm/llm-gateway-db(PDBllm-gateway-db-primary) andmattermost/mattermost-db(PDBmattermost-db-primary). The owner's window decision ("schedule short maintenance window for homelabs when necessary") makes the CloudNativePGspec.nodeMaintenanceWindow: {inProgress: true, reusePVC: true}the path; feat(infra): open a CloudNativePG window to drain a node #5267 adds it to the apply. Both Clusters are tracked by the Argo CD Applicationsllmandmattermost(automated,selfHeal: true, noignoreDifferences); the field is not in git. - Down during a hog apply (local volumes on hog):
llm/llm-gateway-db (Cluster)(every model call through the gateway stops),mattermost/mattermost-db (Cluster),gdot-local-dev-netbox-demo/postgres (Deployment). The drain moves 37 other pods to condor and gemini. The longest grace period on hog is 1800 s (the two databases), so the drain bound is 1860 s. - The Kubernetes API is down for a short time while k3s restarts on hog; the waits read again through that gap (test
test_the_waits_go_on_through_a_restart_of_the_api_server).
hawk, homelab #20 (plan 0f75ad9c9389…, service-restart:systemd-journald, 7 changes, 2 unchecked: "Regenerate GRUB ..." and "Read the kernel line ..."). Drain check, drain, fresh check, run (ok=15 changed=8: the 7 planned changes and the unchecked GRUB task), Ready, health; hawk stays cordoned. No reboot: the reboot that kdump needs is #5128.
After the run
devops infra status dan-petty/homelab --ping at 22:12:33Z: the 4 hosts in service are Ready and reachable, no host waits for a reboot, hawk is cordoned, and every Deployment is available.
Owner steps and open decisions
- Claude Code permission rule. Keep
Bash(uv run devops *)in the allow list of.claude/settings.json. Eachuv run devops infra apply ...of this run was one plain command, and auto mode let it start. A compound shell line (an assignment,;,&&,|) goes to the auto-mode classifier. The access level in the CLI is the real control. The help ofdevops infra applysays this. - AGENTS.md. The "Only a person" text of design section 11 makes AGENTS.md 6,812 characters; one short clause ("hardware; agents change hosts only with
devops infra") makes it 6,545. The cap is 6,500 (tests/invariants/test_agents_md.py), and the file had 6,496. This PR changes "hosts" to "hardware" (6,499). The levels, the guards and the rule that an agent changes a host only withdevops infraare in SECURITY.md## Infra Repos. A person decides whether other text of AGENTS.md gets shorter. - The health gate and application alerts. The gate before the first host refused hawk for 10 minutes, because
RoadmapServiceGitHubThrottled(severitycritical, a GitHub throttle of the roadmap Service) fired. The design reads every critical alert. A person decides whether the gate reads only the alerts of nodes and of the cluster.
Checks run locally
uv run devops ci testof the tests that cover each changed source module, withtests/docs,tests/lang,tests/invariants/test_agents_md.pyandtests/invariants/test_source_tree.py: 8855 passed.uv run devops ci docs,uv run devops openspec check, ruff and ruff format on the changed files, mypy and bandit (-l) on the changed source files: pass.- Six tests of
tests/docsfail at setup when the shell setsDEVOPS_CLI_CONFIG; they pass without it. Filed test(docs): six docs tests read DEVOPS_CLI_CONFIG of the shell #5268.
Issues filed or commented
- feat(infra): open a CloudNativePG window to drain a node #5267: the CloudNativePG maintenance window as a step of the apply.
- dan-petty/homelab#10 (comment): the kubeconfig fetch of the k3s_server role makes the plan of the server node fail.
- docs(adr): ADRs 0010 and 0014 name the deleted option --sync-readme #5244: ADRs 0010 and 0014 name the deleted option
--sync-readme. - test(docs): six docs tests read DEVOPS_CLI_CONFIG of the shell #5268: six docs tests read
DEVOPS_CLI_CONFIGof the shell. - fix(roadmap): intake hides why a gh issue create failed #5269: intake hides why
gh issue createfailed.
The swallowed-failure ratchet reads check=False as a subprocess call whose result nobody reads.
4db2c64 to
1aa113f
Compare
🤖 I have created a release *beep* *boop* --- ## [0.124.0](v0.123.1...v0.124.0) (2026-11-12) ### Features * **infra:** apply a saved plan one node at a time ([#5271](#5271)) ([b0d68df](b0d68df)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
devops infra apply <repo> <playbook> --plan <id>applies a saved plan. An agent needssafe, orfullfor a disruptive or unchecked plan. Guards: plan hash, age, playbook, limit and tags; commit on origin; host key checks for an agent; healthy nodes and no critical alert. Each disruptive host runs alone: drain check, drain (bound covers pod grace periods), fresh check equal to the plan, run, Ready with its GPUs, node health, uncordon only when it was schedulable, alerts. It names the workloads that only that node can run. An unplanned change or the first failure stops it. Audit recordinfra.applyanddevops_cli_infra_runs_total.SECURITY.md gets
## Infra Repos. The design text for AGENTS.md does not fit its 6,500-character cap (6,812); AGENTS.md says "hardware" in place of "hosts" (6,499).Closes #5125
Change:
openspec/changes/archive/2026-11-12-5125-apply-a-saved-plan-one-node/