Repository navigation
Description
Problem Description
The drain check of devops infra stops each run for a node that holds Longhorn storage. devops infra node drain, node restart, node reboot and the drain of devops infra apply first run kubectl drain <node> --ignore-daemonsets --delete-emptydir-data --timeout=30s --dry-run=server (drain_check in src/devops_cli/infra/nodes.py) and stop when it exits with an error (_drain in src/devops_cli/infra/node_run.py and src/devops_cli/infra/apply.py).
Longhorn keeps one PodDisruptionBudget instance-manager-<id> for each storage node while the node is schedulable, with 0 allowed disruptions. It deletes the budget only after the node is cordoned, when its node drain policy allows the drain (syncInstanceManagerPDB and canDeleteInstanceManagerPDB in controller/instance_manager_controller.go of longhorn-manager v1.13.0). So a server dry run before the cordon always names the instance-manager pod, and the check refuses a drain that would end.
The homelab cluster has three storage nodes since Longhorn was installed (dan-petty/homelab#412). By the code, no node command and no apply with a drain can pass the check for these three hosts.
Reproduction Steps
kubectl get pdb -n longhorn-system: three budgetsinstance-manager-<id>, ALLOWED DISRUPTIONS 0. The cluster has no Longhorn volume.kubectl drain <storage node> --ignore-daemonsets --delete-emptydir-data --force --timeout=30s --dry-run=server(read-only, run on 2026-11-27 with kubectl v1.37.3 for the build of dan-petty/homelab#429): exit code 1 after 33 seconds. The last line iserror when evicting pods/"instance-manager-<id>" -n "longhorn-system": global timeout reached: 30s. No node is cordoned and no pod changes.- The same dry run for a node with no Longhorn pod exits 0 in under a second.
Not reproduced with devops infra node drain itself: no real drain ran. The evidence is the dry run and the code path.
Expected vs Actual Behavior
Expected: the drain check stops a run only for a pod that the real drain cannot evict.
Actual: the check stops each run for a Longhorn storage node, because the dry run comes before the cordon and Longhorn frees its pod only after the cordon.
The same limit holds for a CloudNativePG cluster with more than one instance: the operator moves the primary to another instance only when the node of the primary is cordoned (document "Kubernetes upgrade and maintenance" of CloudNativePG 1.30). The homelab cluster has no such database now.
Environment Diagnostics
kubectl v1.37.3, cluster v1.37.2+k3s1, Longhorn v1.13.0 with the node drain policy block-if-contains-last-replica, devops-cli main of 2026-11-27.
Logs, Traces, or Terminal Output
error when evicting pods/"instance-manager-<id>" -n "longhorn-system" (will retry after 5s): Cannot evict pod as it would violate the pod's disruption budget.
error: unable to drain node "<storage node>" due to error: error when evicting pods/"instance-manager-<id>" -n "longhorn-system": global timeout reached: 30s, continuing command...
There are pending nodes to be drained:
<storage node>
error when evicting pods/"instance-manager-<id>" -n "longhorn-system": global timeout reached: 30s
Acceptance criteria
- A node command and an apply pass the drain check for a Longhorn storage node whose dry run names only the instance-manager pod of Longhorn, or the check runs in a state in which Longhorn has freed that pod.
- The check still stops a run for a pod that a budget with no allowed disruption covers, for example the one instance of a CloudNativePG cluster.
- A test covers a dry run that names only the instance-manager pod, and a dry run that names that pod and one more pod.
The upgrade play of the homelab repository leaves the instance-manager pod out of its own check (dan-petty/homelab#429).
Source
Alternatives check of 2026-11-27: none.
Tool: none found.
Reason: Searches surfaced only node-reboot daemons (kured, system-upgrade-controller) that cordon and then drain, and Longhorn's own cordon-dependent PDB; no open tool offers a reusable drain preflight check, so drain_check must be fixed in devops-cli.
Lacks:
- No reusable drain preflight check in any found tool
- No way to tell a PDB that clears after the cordon
- Daemons replace the node workflow instead of adding a check
- No dry-run option that accounts for Longhorn instance-manager budgets
Proposed design
Problem statement
Fix the drain check to ignore only the Longhorn instance-manager block. The drain check runs a server dry run before the cordon. Longhorn keeps an instance-manager PodDisruptionBudget with zero allowed disruptions until the node is cordoned. The dry run therefore fails for each Longhorn storage node. Node commands and applies stop before a drain that would finish. The fix keeps every other block and keeps the check read-only.
Acceptance criteria
Requirement: Drain check ignores the Longhorn instance-manager block
The drain check SHALL return no problem when the server dry run fails only for Longhorn instance-manager pods in the longhorn-system namespace.
Scenario: Dry run names only the Longhorn instance-manager pod
- WHEN The server dry run exits 1 and its error output names only a pod in
longhorn-systemwhose name starts withinstance-manager-. - THEN
Cluster.drain_checkreturnsNone, and the unit test with the recorded dry-run output passes.
Requirement: Drain check stops for a second blocked pod
The drain check SHALL return the dry-run problem when the server dry run fails for a pod other than a Longhorn instance-manager pod.
Scenario: Dry run names the Longhorn instance-manager pod and one more pod
- WHEN The server dry-run error output names a
longhorn-system/instance-manager-*pod and a pod in another namespace whose PodDisruptionBudget allows no disruption. - THEN
Cluster.drain_checkreturns a problem that names the other pod, and the node command and the apply stop before the drain.
Requirement: Drain check stops for a single CloudNativePG instance
The drain check SHALL stop a run when the server dry run fails for the only instance of a CloudNativePG cluster.
Scenario: Dry run names the single CloudNativePG instance
- WHEN The server dry-run error output names a pod of a CloudNativePG cluster with one instance and no Longhorn instance-manager pod.
- THEN
Cluster.drain_checkreturns the problem, and the node command and the apply stop before the drain.
Requirement: Drain check reads every eviction error
The drain check MUST inspect every error when evicting pods/... line in the server dry-run output.
Scenario: Longhorn error comes before another blocked pod
- WHEN The server dry-run output has an
instance-manager-*eviction error line before an eviction error line for another pod. - THEN
Cluster.drain_checkreturns a problem for the other pod, and the unit test with the recorded output passes.
Requirement: Node command and apply reach the drain
The node command and the apply SHALL reach the drain step for a Longhorn storage node whose dry run names only the instance-manager pod.
Scenario: Node command and apply use the corrected drain check
- WHEN A node command or an apply runs the drain check for a Longhorn storage node and the dry run names only the instance-manager pod.
- THEN The run calls the drain step and does not stop at the drain check.
Existing Tool Considered
The alternatives check in the issue body records verdict none and no tool. No open, maintained tool or library offers a reusable drain preflight check. The fix stays in drain_check in src/devops_cli/infra/nodes.py. Cost to build, keep and fix the parser: about 3,000 tokens and 1 hour.
Key questions
- How should the drain check treat the Longhorn instance-manager PodDisruptionBudget?: Ignore a dry-run failure only when every blocked pod is a Longhorn instance-manager pod in
longhorn-system. Return the problem when any other pod is blocked. (best practice) [sources: src/devops_cli/infra/nodes.py:421, src/devops_cli/infra/node_run.py, src/devops_cli/infra/apply.py]- Chosen: Ignore only Longhorn instance-manager errors. It keeps the check read-only and keeps every other PodDisruptionBudget block.
- Rejected: Cordon the node before the dry run. It changes the node before the check and leaves the node cordoned when the check fails.
- Rejected: Exclude Longhorn pods with
--pod-selector. It hides the Longhorn pod from the dry run and does not test the recorded failure output.
- How should the drain check find every blocked pod in the dry-run output?: Read every
error when evicting pods/...line in stderr. Do not use only the last line. (best practice) [sources: src/devops_cli/infra/nodes.py:421]- Chosen: Read every eviction error line. A second blocked pod can appear before the last line, and the check must stop for it.
- Rejected: Use only the last stderr line. It hides a second blocked pod and lets the drain check pass.
- Should the check query Longhorn to decide whether the PodDisruptionBudget will be deleted after the cordon?: No. The fix ignores the Longhorn instance-manager block and keeps every other block. The real drain remains the final guard if Longhorn keeps the budget for a last replica. (best practice) [sources: src/devops_cli/infra/nodes.py:421]
- Chosen: Ignore the Longhorn instance-manager block. It is a small, read-only fix and matches the acceptance tests.
- Rejected: Query Longhorn custom resources for the node drain policy. It copies version-specific Longhorn logic and adds a new API dependency.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 27, 2026
Both concern the node drain check added by #5128, but #5128 adds the commands while the candidate fixes a PDB interaction bug in them.devops-cli-service commentedon Nov 27, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (10)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 28, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Nov 28, 2026
Released in v0.241.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.241.0
devops-cli-service commentedon Nov 29, 2026
Live since 2026-11-29 00:41 UTC