Skip to content

Commit

Permalink
api: enable query options on agent force-leave endpoint (#15987)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreikom authored Apr 18, 2023
1 parent 5d7a7ff commit eb9f671
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/15987.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
api: Enable setting query options on agent force-leave endpoint.
```
9 changes: 9 additions & 0 deletions api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,8 +1055,17 @@ func (a *Agent) ForceLeavePrune(node string) error {

// ForceLeaveOpts is used to have the agent eject a failed node or remove it
// completely from the list of members.
//
// DEPRECATED - Use ForceLeaveOptions instead.
func (a *Agent) ForceLeaveOpts(node string, opts ForceLeaveOpts) error {
return a.ForceLeaveOptions(node, opts, nil)
}

// ForceLeaveOptions is used to have the agent eject a failed node or remove it
// completely from the list of members. Allows usage of QueryOptions on-top of ForceLeaveOpts
func (a *Agent) ForceLeaveOptions(node string, opts ForceLeaveOpts, q *QueryOptions) error {
r := a.c.newRequest("PUT", "/v1/agent/force-leave/"+node)
r.setQueryOptions(q)
if opts.Prune {
r.params.Set("prune", "1")
}
Expand Down
14 changes: 14 additions & 0 deletions api/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,20 @@ func TestAPI_AgentForceLeavePrune(t *testing.T) {
}
}

func TestAPI_AgentForceLeaveOptions(t *testing.T) {
t.Parallel()
c, s := makeClient(t)
defer s.Stop()

agent := c.Agent()

// Eject somebody with token
err := agent.ForceLeaveOptions(s.Config.NodeName, ForceLeaveOpts{Prune: true}, &QueryOptions{Token: "testToken"})
if err != nil {
t.Fatalf("err: %v", err)
}
}

func TestAPI_AgentMonitor(t *testing.T) {
t.Parallel()
c, s := makeClient(t)
Expand Down

0 comments on commit eb9f671

Please sign in to comment.