Repository navigation
Description
Problem or Motivation
dan-petty/homelab has a Makefile target for each host and operation: drain-hawk, uncordon-hawk, restart-hawk and the same for 4 more hosts, plus rolling-restart. Each needs a person, has no health gate, and restart-* uses a play that drains inside Ansible. The play of rolling-restart (tasks/k3s_node_reboot.yaml) skips a node that is already cordoned, so it cannot be combined with a drain from outside. Agents may drain, restart k3s and reboot one node at a time (owner decision 2026-11-12, homelab at level full).
Proposed Solution & Architectural Design
devops infra node drain|uncordon|restart|reboot <repo> <host>... (design sections 5 and 7 in tracker #5120), one host at a time in the given order.
drain: health gate, record the cordon state,kubectl drain --ignore-daemonsets --delete-emptydir-data --timeout(no--forceunless a person gives it).uncordon:kubectl uncordon, then the health gate.restart: drain, restartdevops_infra_node_servicewith an ansible-runner ad-hocansible.builtin.systemd_service, wait for the unit and Ready, check GPU allocatable, uncordon only when the node was schedulable before, health gate.reboot: the same withansible.builtin.reboot, and the kernel before and after in the output.- Access:
uncordonneeds agent levelsafe; the othersfull. Audit record anddevops_cli_infra_runs_totalas in feat(infra): apply a saved plan one node at a time #5125. The first failure stops the run and leaves the node cordoned.--dry-runmakes zero requests.
These commands replace the per-host Makefile targets and rolling-restart; dan-petty/homelab#22 removes them.
Target Subsystem
OpenTofu / Infrastructure as Code
Existing Tool Considered
kubectl and the Ansible modules systemd_service and reboot (check mode support full) do the work; the guards of #5125 are shared. kured reboots nodes with a lock and alert gates, but only when a reboot sentinel exists and with no plan or restart; a later item can add it for unattended kernel reboots. Cost: about 2.5M tokens to build, 0.3M a quarter to keep, 3 hours.
Acceptance Criteria
- Tests with a fake kubectl and recorded events: order of steps for each operation; a cordoned node stays cordoned; a failed Ready wait stops before the next host;
restartrefuses a host with nodevops_infra_node_service; level refusals. - A test:
--dry-runstarts no process. - Live run at level
fullby an agent, recorded in a PR comment with the audit records: after the crash-capture apply of feat(infra): apply a saved plan one node at a time #5125 (dan-petty/homelab#20),node reboot dan-petty/homelab hawk.landrainshawk, reboots it, shows the kernel before and after, checks 1 GPU allocatable, andhawkstays cordoned. After the boot, kdump has reserved its memory (/sys/kernel/kexec_crash_sizeis above 0). - Live run:
node restart dan-petty/homelab hawk.lanrestartsk3s-agent;hawkis Ready and stays cordoned.
Dependencies
#5125; dan-petty/homelab#21 (the node service variable).
Proposed design
Problem statement
dan-petty/homelab keeps one Makefile target for each host and operation. Each target needs a person, has no health gate, and the restart play drains inside Ansible. The rolling-restart play skips a node that is already cordoned, so an outside drain cannot combine with it. This item adds devops infra node drain|uncordon|restart|reboot <repo> <host>... with one host at a time in the given order. Each run has a health gate, a recorded cordon state and an audit record, and it stops at the first failure.
Acceptance criteria
Requirement: drain-order
The node drain command SHALL run the node health check, the server-side drain check, and then kubectl drain --ignore-daemonsets --delete-emptydir-data --timeout <bound> with the drain bound.
Scenario: Drain checks before it cordons
- WHEN A test runs
node drainon one host with the default settings and a fake kubectl that records each call. - THEN The recorded calls show the health check, then
kubectl drain --dry-run=server, thenkubectl drain --ignore-daemonsets --delete-emptydir-data --timeout=180s, in that order.
Requirement: drain-bound
The node drain command SHALL bound the drain by infra.drain_timeout_seconds, or by the longest grace period of a pod that the drain evicts plus 60 s when that is longer.
Scenario: A long grace period extends the bound
- WHEN A test runs
node drainwithinfra.drain_timeout_secondsset to 180 and a fake kubectl that returns one pod on the node with a grace period of 900 s. - THEN The recorded
kubectl draincall has--timeout=960s.
Requirement: drain-force-needs-the-flag
The drain MUST NOT pass --force to kubectl drain unless the person gives --force.
Scenario: Force needs the flag
- WHEN A test runs
node drainon one host with no--force, and again with--force. - THEN The first recorded
kubectl draincall has no--force, and the second recorded call has--force.
Requirement: uncordon-order
The node uncordon command SHALL run kubectl uncordon and then the node health check.
Scenario: Uncordon comes before the health check
- WHEN A test runs
node uncordonon one host with a fake kubectl. - THEN The recorded calls show
kubectl uncordonand then the health check.
Requirement: restart-steps
The node restart command SHALL drain, restart the devops_infra_node_service unit, wait for the unit and Ready, check the allocatable GPU count, uncordon only when the node was schedulable before, and run the health check.
Scenario: Restart follows the drain
- WHEN A test runs
node restarton a schedulable host with a fake kubectl and a fake ansible-runner. - THEN The recorded calls are in that order, and the health check follows
kubectl uncordon.
Requirement: restart-keeps-cordon
The node restart command MUST NOT uncordon a node that was not schedulable before the run.
Scenario: A cordoned node stays cordoned
- WHEN A test runs
node restarton a host that is already cordoned. - THEN The recorded calls hold no
kubectl uncordon, and the command exits 0.
Requirement: restart-needs-a-unit
The node restart command MUST refuse a host that sets no devops_infra_node_service.
Scenario: No unit, no restart
- WHEN A test runs
node restarton a host with nodevops_infra_node_servicein its host variables. - THEN The command exits non-zero, names
devops_infra_node_service, and the fake kubectl and ansible-runner record no call.
Requirement: reboot-steps
The node reboot command SHALL drain, reboot with ansible.builtin.reboot, print the kernel release before and after, wait for Ready, check the allocatable GPU count, uncordon only when the node was schedulable before, and run the health check.
Scenario: Reboot shows both kernels
- WHEN A test runs
node rebooton one schedulable host with a fake kubectl and a fake ansible-runner. - THEN The output holds the kernel release of the fake host before and after the reboot, and the health check follows
kubectl uncordon.
Requirement: agent-levels
The command MUST need agent level safe for uncordon and level full for drain, restart and reboot.
Scenario: The safe level allows only the uncordon
- WHEN A test runs each of the four operations on a repository at level
safe. - THEN
uncordonexits 0 and recordskubectl uncordon;drain,restartandrebootexit non-zero with the level refusal and start no process.
Requirement: dry-run-does-nothing
The command MUST start no process and send no request when the person gives --dry-run.
Scenario: Dry run makes no request
- WHEN A test runs each of the four operations with
--dry-run, a fake kubectl and a fake ansible-runner. - THEN No process starts and the fake runners record no call.
Requirement: one-host-at-a-time
The command SHALL run one host at a time in the given order and MUST stop at the first failure.
Scenario: The second host waits
- WHEN A test runs
node drainon two hosts and the first host fails. - THEN The command exits non-zero and the fake kubectl records no call for the second host.
Requirement: failure-keeps-the-cordon
The command MUST leave the node cordoned when a step after the drain fails.
Scenario: A failed wait keeps the cordon
- WHEN A test runs
node restartand the Ready wait fails after the drain. - THEN The recorded calls hold no
kubectl uncordon, and the command exits non-zero.
Requirement: audit-record-and-counter
Each run SHALL write one audit record with the operation, the host, the caller and the level, and add one to devops_cli_infra_runs_total with the command and the result.
Scenario: One record and one count for each run
- WHEN A test runs a
node drainthat succeeds and one that stops. - THEN The audit log holds two records with results
okandstopped, and the counter adds one for each with the same command.
Existing Tool Considered
kubectl and ansible-core 2.22.0's ansible.builtin.systemd_service and ansible.builtin.reboot do the low-level work. The Kubernetes documentation gives kubectl drain the --ignore-daemonsets, --delete-emptydir-data, --timeout and --force flags (https://kubernetes.io/docs/reference/kubectl/generated/kubectl_drain/, fetched 2026-11-17), and ansible-core 2.22.0 is the pinned tool (src/devops_cli/tools_lock/ansible-core.in:1). The tools lack the health gate, the order, the recorded cordon state, the audit record and the first-failure stop; this change adds them around the tools, and the guards of #5125 are shared. kured reboots nodes with a lock and alert gates, but it acts only when a reboot sentinel exists and it does no plan and no restart, so a later item can add it for unattended kernel reboots. The written cost to build the orchestration instead is about 2.5M tokens, 0.3M tokens a quarter to keep it, and 3 hours.
Key questions
- Which existing code and tools do the drain and the uncordon of a node?:
src/devops_cli/infra/nodes.pyalready holds the drain and the uncordon of a node.src/devops_cli/infra/apply.pycalls them with the drain check and the uncordon rule. The new commands call the same code and add no second drain. [sources: src/devops_cli/infra/nodes.py:360, src/devops_cli/infra/nodes.py:366, src/devops_cli/infra/apply.py, CONTEXT.md] - Where does the unit name of the node service come from?: From the inventory host variable
devops_infra_node_service. The constantNODE_SERVICE_VARIABLEnames it insrc/devops_cli/infra/onboard.py:62, and the homelab fixtures set it for each node. In homelab the value is a template, which only Ansible renders, so the command reads it through an Ansible ad-hocansible.builtin.debugtask and the runner event reader, not from the rawansible-inventory --listvalue. The real homelab repo must set it too, anddan-petty/homelab#21adds it. [sources: src/devops_cli/infra/onboard.py:62, tests/fixtures/infra/homelab_shape/ansible/inventory/host_vars/node-1.example.com.yaml:5, openspec/changes/archive/2026-11-12-5125-apply-a-saved-plan-one-node/design.md:13, openspec/changes/archive/2026-11-12-5121-onboard-an-ansible-infra-repo/design.md:30] - Which agent access level does each operation need?:
uncordonneeds levelsafe.drain,restartandrebootneed levelfull, because each one takes a host out of service. The owner decision of 2026-11-12 gives agentsfullon dan-petty/homelab. (best practice) [sources: src/devops_cli/config/settings.py:2304, SECURITY.md:68, CONTEXT.md]- Chosen: uncordon at
safe, the others atfull. The setting description givessafethe uncordon andfullthe drain, restart and reboot, so an uncordon that an agent may do is not refused. - Rejected: all four at
full. It refuses an uncordon that an agent may do, and the owner decision names the level for each operation. - Rejected: all four at
safe. A drain takes a host out of service, and levelsafeis too low for that.
- Chosen: uncordon at
- How does the command reach a host for the restart and the reboot?: With an ansible-runner ad-hoc task:
ansible.builtin.systemd_servicefor the restart andansible.builtin.rebootfor the reboot. The command reads the inventory of the infra repo at a commit thatoriginholds. (best practice) [sources: CONTEXT.md, src/devops_cli/infra/plan.py, src/devops_cli/infra/apply.py, src/devops_cli/infra/ansible_facts.py:124]- Chosen: ad-hoc ansible-runner task. One task needs no playbook in the infra repo, and the two modules support check mode.
- Rejected: a generated playbook through the infra plan and apply. A plan records a check-mode run of a playbook that the infra repo holds. These commands change one unit or reboot one host.
- Rejected: ssh and systemctl from the CLI. It bypasses the inventory and the Ansible connection of the infra repo.
- What bounds the drain in time, and when does the command pass
--force?:infra.drain_timeout_seconds(default 180 s,DEVOPS_CLI_INFRA_DRAIN_TIMEOUT_SECONDS) bounds the drain. The bound is the longer of that setting and the longest grace period of a pod that the drain evicts plus 60 s, asCluster.drain_boundalready computes it. The command passes--forceonly when the person gives--force;drain_argsadds no--force, because--forcecontinues past a pod that no controller owns and the apply's drain has no--force. (best practice) [sources: src/devops_cli/config/defaults.py:58, docs/CONFIGURATION.md:361, src/devops_cli/infra/nodes.py:351, src/devops_cli/infra/nodes.py:84, openspec/changes/archive/2026-11-12-5125-apply-a-saved-plan-one-node/design.md:9, https://kubernetes.io/docs/reference/kubectl/generated/kubectl_drain/]- Chosen: reuse
infra.drain_timeout_secondsand extend it to the longest evicted pod grace period plus 60 s. It is the project's existing bound,drain_boundalready implements it, and it keeps the standalone drain equal to the apply's drain. - Rejected: fixed
--timeout 300s. It duplicatesinfra.drain_timeout_seconds, ignores the configured value, and differs from the apply's drain. - Rejected: kubectl's default of no timeout. A PodDisruptionBudget can block a drain forever, so the first-failure rule never fires.
- Rejected: require
--timeouton each run. It adds a step to each run, and the setting already gives a safe default.
- Chosen: reuse
- Which audit record and which metric does a node run write?: One audit record with the operation, the host, the caller and the level, and one addition to
devops_cli_infra_runs_totalwith the command and the result. The counter already divides runs by command, so the node commands add their own command values; the description of the counter names onlyapplyatsrc/devops_cli/telemetry/instruments.py:873anddocs/TELEMETRY.md:205, so the change adds the node command values there. (best practice) [sources: openspec/specs/infra-apply/spec.md:146, src/devops_cli/telemetry/instruments.py:870, docs/TELEMETRY.md:205]- Chosen: reuse the audit record and
devops_cli_infra_runs_total. The spec and the dashboard already divide the runs by command, and a second counter duplicates the alert rules. - Rejected: a new counter
devops_cli_infra_node_runs_total. It doubles the dashboard and the alert rules for the same question.
- Chosen: reuse the audit record and
- Which order of steps does a restart use?: The drain, then the unit restart, then the wait for the unit and Ready, then the GPU allocatable check, then an uncordon only when the node was schedulable before, then the health check. (best practice) [sources: CONTEXT.md, openspec/specs/infra-apply/spec.md:90]
- Chosen: drain, restart, wait, GPU check, conditional uncordon, health check. It matches the apply order: drain check, drain, Ready, the health of the nodes, and an uncordon only when the node was schedulable before.
- Rejected: restart the unit before the drain. A unit restart on a node that still runs pods risks a second disruption, and the apply drains first.
- Rejected: always uncordon after the restart. A node that a person cordoned stays cordoned, as the apply does.
- What does
--dry-rundo?: It starts no process and sends no request. The term in CONTEXT.md says a dry run makes no request, and ARCHITECTURE.md says a dry run sends no external request and prints the requests that a real run would send. (best practice) [sources: CONTEXT.md, ARCHITECTURE.md:170]- Chosen: no process and no request. The term in CONTEXT.md says a dry run makes no request, and the issue requires that
--dry-runstarts no process. - Rejected: run the health check read-only. A health check sends a request, and the term says a dry run makes none.
- Chosen: no process and no request. The term in CONTEXT.md says a dry run makes no request, and the issue requires that
Fit
Fits in one pull request.
Suspected block
None.
Activity
dan-petty commentedon Nov 12, 2026
Both live under the devops infra command tree; #5120 is the umbrella and this adds specific node operation sub-commands.devops-cli-service commentedon Nov 17, 2026
Waiting for the alternatives check to run. The next refine round looks at the item again after the check records a verdict.
docs(openspec): name the cause that holds the live runs of #5128
fix(infra): show the help of the node group in devops infra --help (#…
chore(main): release 0.191.0 (#6714)
devops-cli-service commentedon Nov 22, 2026
Released in v0.191.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.191.0
devops-cli-service commentedon Nov 22, 2026
Live since 2026-11-22 01:30 UTC