Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: improve alloc GC API error messages #9488

Merged
merged 2 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions client/alloc_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ func (a *Allocations) GarbageCollect(args *nstructs.AllocSpecificRequest, reply
}

if !a.c.CollectAllocation(args.AllocID) {
// Could not find alloc
return nstructs.NewErrUnknownAllocation(args.AllocID)
return fmt.Errorf("No such allocation on client or allocation not eligible for GC")
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions client/alloc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ func TestAllocations_GarbageCollect_ACL(t *testing.T) {
"run_for": "20s",
}

noSuchAllocErr := fmt.Errorf("No such allocation on client or allocation not eligible for GC")

// Wait for client to be running job
alloc := testutil.WaitForRunningWithToken(t, server.RPC, job, root.SecretID)[0]

Expand Down Expand Up @@ -306,7 +308,7 @@ func TestAllocations_GarbageCollect_ACL(t *testing.T) {

var resp nstructs.GenericResponse
err := client.ClientRPC("Allocations.GarbageCollect", &req, &resp)
require.True(nstructs.IsErrUnknownAllocation(err))
require.Error(err, noSuchAllocErr)
}

// Try request with a management token
Expand All @@ -316,7 +318,7 @@ func TestAllocations_GarbageCollect_ACL(t *testing.T) {

var resp nstructs.GenericResponse
err := client.ClientRPC("Allocations.GarbageCollect", &req, &resp)
require.True(nstructs.IsErrUnknownAllocation(err))
require.Error(err, noSuchAllocErr)
}
}

Expand Down
3 changes: 2 additions & 1 deletion website/pages/api-docs/client.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ $ curl \
## GC Allocation

This endpoint forces a garbage collection of a particular, stopped allocation
on a node.
on a node. Note that the allocation will still exist on the server and appear
in server responses.

| Method | Path | Produces |
| ------ | --------------------------------- | ------------------ |
Expand Down