Skip to content

feat: add node maintenance evict commands to longhornctl - #635

Open
sudeepr34 wants to merge 3 commits into
longhorn:masterfrom
sudeepr34:feat/maintenance-evict-commands
Open

sudeepr34 wants to merge 3 commits into
longhorn:masterfrom
sudeepr34:feat/maintenance-evict-commands

Conversation

@sudeepr34

Copy link
Copy Markdown
Contributor

Add longhornctl maintenance evict-node and evict-disk commands so node maintenance can be driven from the CLI without the web UI.

evict-node cordons the Kubernetes node, disables Longhorn replica scheduling on it and requests eviction of all its replicas. evict-disk does the same for a single disk identified by UUID. Both accept --wait to block until no replicas remain, and evict-node prints the kubectl drain command that finishes the maintenance workflow.

Related: longhorn/longhorn#8799

Which issue(s) this PR fixes:

Issue longhorn/longhorn#8799

Issue #

What this PR does / why we need it:

Adds longhornctl maintenance evict-node and longhornctl maintenance evict-disk so node maintenance can be performed from the CLI without the web UI (longhorn/longhorn#8799).

  • evict-node --node-id <id> [--wait]: cordons the Kubernetes node, sets allowScheduling=false and evictionRequested=true on the Longhorn node, optionally waits until no replicas remain scheduled on it, then prints the kubectl drain <node> --ignore-daemonsets command that finishes the maintenance workflow.
  • evict-disk --node-id <id> --disk-uuid <uuid> [--wait]: sets allowScheduling=false and evictionRequested=true on the single disk (resolved from UUID via node status), optionally waiting until the disk holds no replicas.

Draining itself stays a kubectl operation (the drain helper isn't vendored by the CLI); the command prints the exact drain invocation as guidance.

Special notes for your reviewer:

  • Eviction completion is detected by polling status.diskStatus[].scheduledReplica (10s interval, 30m timeout) — there is no explicit "eviction complete" condition on the node.
  • Both commands are idempotent: re-running on an already-evicted node/disk logs and continues instead of erroring.
  • Unit tests cover the pure helpers (disk UUID lookup, replica counting, drain command string, flag validation); the cluster-interacting paths follow the existing Diagnoser client patterns.

Additional documentation or context

Follows the maintenance workflow in the Longhorn docs (evict before drain). Related discussion: longhorn/longhorn#8593.

Add `longhornctl maintenance evict-node` and `evict-disk` commands so node
maintenance can be driven from the CLI without the web UI.

evict-node cordons the Kubernetes node, disables Longhorn replica scheduling
on it and requests eviction of all its replicas. evict-disk does the same for
a single disk identified by UUID. Both accept --wait to block until no
replicas remain, and evict-node prints the kubectl drain command that finishes
the maintenance workflow.

Related: longhorn/longhorn#8799

Signed-off-by: Sudeep Reddy <148759887+sudeepr34@users.noreply.github.com>
@derekbit
derekbit force-pushed the feat/maintenance-evict-commands branch from 2fc1925 to 189045c Compare October 12, 2026 01:57
@mergify

mergify Bot commented Nov 11, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant