api: enable query options on agent force-leave endpoint (#15987)

This commit is contained in:
Andrei Komarov 2023-04-18 19:31:48 +03:00 committed by GitHub
parent 5d7a7ff041
commit eb9f671eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 0 deletions

3
.changelog/15987.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:improvement
api: Enable setting query options on agent force-leave endpoint.
```

View File

@ -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")
}

View File

@ -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)