Skip to content

feat(infra): apply a saved plan one node at a time - #5271

Merged
dan-petty merged 7 commits into
mainfrom
feat/5125-apply-a-saved-plan-one-node
Nov 12, 2026
Merged

dan-petty merged 7 commits into
mainfrom
feat/5125-apply-a-saved-plan-one-node

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

devops infra apply <repo> <playbook> --plan <id> applies a saved plan. An agent needs safe, or full for 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 record infra.apply and devops_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/

`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.
@dan-petty dan-petty added type/feature Type feature: a new function scope/infra Docker container images, DevContainers, and infrastructure tooling labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Live run on dan-petty/homelab (2026-11-12, agent, level full)

The caller was an agent (Claude Code), with agent_access: full for dan-petty/homelab. Each apply was one plain command, uv run devops infra apply dan-petty/homelab <playbook> --plan <id> --limit <host> --path <checkout> --auto-approve, from the worktree of this branch. Auto mode let each one start; no permission prompt or refusal came. All plans and applies ran at homelab origin/main 19f0457 (homelab #19 and #20 merged, not applied).

Before each host: devops infra status dan-petty/homelab --ping showed the 4 hosts in service Ready and reachable, with no pending reboot. No devops-cli-runner-* or fix-plan-validate-* Job ran, no Argo Workflow ran, no Deployment had unavailable replicas, no Argo CD sync ran, and no critical alert fired (except the first hawk try, below). One old condition stayed for the whole run: llm/open-webui-0 is Pending since about 15:00Z, because its volume is tied to a node that is not schedulable for it; it is not a rollout.

Nodes before and after

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 (PDB llm-gateway-db-primary) and mattermost/mattermost-db (PDB mattermost-db-primary). The owner's window decision ("schedule short maintenance window for homelabs when necessary") makes the CloudNativePG spec.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 Applications llm and mattermost (automated, selfHeal: true, no ignoreDifferences); 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. Each uv 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 of devops infra apply says 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 with devops infra are 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 (severity critical, 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 test of the tests that cover each changed source module, with tests/docs, tests/lang, tests/invariants/test_agents_md.py and tests/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/docs fail at setup when the shell sets DEVOPS_CLI_CONFIG; they pass without it. Filed test(docs): six docs tests read DEVOPS_CLI_CONFIG of the shell #5268.

Issues filed or commented

The swallowed-failure ratchet reads check=False as a subprocess call
whose result nobody reads.
@dan-petty
dan-petty force-pushed the feat/5125-apply-a-saved-plan-one-node branch from 4db2c64 to 1aa113f Compare November 12, 2026 22:32
@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 22:38
@dan-petty
dan-petty merged commit b0d68df into main Nov 12, 2026
24 checks passed
@dan-petty
dan-petty deleted the feat/5125-apply-a-saved-plan-one-node branch November 12, 2026 22:51
dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/infra Docker container images, DevContainers, and infrastructure tooling type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(infra): apply a saved plan one node at a time

1 participant