diff --git a/.changelog/15987.txt b/.changelog/15987.txt new file mode 100644 index 0000000000..2a4da0320a --- /dev/null +++ b/.changelog/15987.txt @@ -0,0 +1,3 @@ +```release-note:improvement +api: Enable setting query options on agent force-leave endpoint. +``` \ No newline at end of file diff --git a/api/agent.go b/api/agent.go index baa6de03a2..6dd127b335 100644 --- a/api/agent.go +++ b/api/agent.go @@ -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") } diff --git a/api/agent_test.go b/api/agent_test.go index 4fdc31bb90..ebf7381547 100644 --- a/api/agent_test.go +++ b/api/agent_test.go @@ -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)