cli: Add prune flag for nomad server force-leave command (#18463)

This feature will help operator to remove a failed/left node from Serf layer immediately
without waiting for 24 hours for the node to be reaped

* Update CLI with prune flag
* Update API /v1/agent/force-leave with prune query string parameter
* Update CLI and API doc
* Add unit test
This commit is contained in:
Gerard Nguyen
2023-09-15 22:45:11 +10:00
committed by GitHub
parent d2dd64f2c4
commit 1339599185
8 changed files with 132 additions and 8 deletions

View File

@@ -441,13 +441,17 @@ The table below shows this endpoint's support for
### Parameters
- `node` `(string: <required>)` - Specifies the name of the node to force leave.
- `prune` `(boolean: <optional>)` - Removes failed or left server from the Serf
member list immediately. If member is actually still alive, it will eventually rejoin
the cluster again.
### Sample Request
```shell-session
$ curl \
--request POST \
https://localhost:4646/v1/agent/force-leave?node=client-ab2e23dc
https://localhost:4646/v1/agent/force-leave?node=client-ab2e23dc&prune=true
```
## Health

View File

@@ -10,7 +10,9 @@ description: >
The `server force-leave` command forces a server to enter the "left" state.
This can be used to eject server nodes which have failed and will not rejoin
the cluster. Note that if the server is actually still alive, it will
the cluster. The failed or left server will be garbage collected after `24h`.
~> Note that if the server is actually still alive, it will
eventually rejoin the cluster again.
## Usage
@@ -22,6 +24,9 @@ nomad server force-leave [options] <node>
This command expects only one argument - the node which should be forced
to enter the "left" state.
Additionally, by specifying the `prune` flag, a failed or left node can be forcibly removed
from the list of members immediately.
If ACLs are enabled, this option requires a token with the `agent:write`
capability.
@@ -29,6 +34,11 @@ capability.
@include 'general_options_no_namespace.mdx'
## Server Force-Leave Options
- `-prune`: Removes failed or left server from the Serf member list immediately.
If member is actually still alive, it will eventually rejoin the cluster again.
## Examples
Force-leave the server "node1":
@@ -37,3 +47,10 @@ Force-leave the server "node1":
$ nomad server force-leave node1
```
Force-leave the server "node1" and prune it:
```shell-session
$ nomad server force-leave -prune node1
```