Skip to content

Commit

Permalink
api: respect wildcard in evaluations list API
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Dec 20, 2021
1 parent 0ec5db4 commit ff5ee69
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/11710.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
api: Updated the evaluations list API to respect wildcard namespaces
```
4 changes: 3 additions & 1 deletion nomad/eval_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,9 @@ func (e *Eval) List(args *structs.EvalListRequest,
// Scan all the evaluations
var err error
var iter memdb.ResultIterator
if prefix := args.QueryOptions.Prefix; prefix != "" {
if args.RequestNamespace() == structs.AllNamespacesSentinel {
iter, err = store.Evals(ws)
} else if prefix := args.QueryOptions.Prefix; prefix != "" {
iter, err = store.EvalsByIDPrefix(ws, args.RequestNamespace(), prefix)
} else {
iter, err = store.EvalsByNamespace(ws, args.RequestNamespace())
Expand Down
56 changes: 56 additions & 0 deletions nomad/eval_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,62 @@ func TestEvalEndpoint_List(t *testing.T) {

}

func TestEvalEndpoint_ListAllNamespaces(t *testing.T) {
t.Parallel()

s1, cleanupS1 := TestServer(t, nil)
defer cleanupS1()
codec := rpcClient(t, s1)
testutil.WaitForLeader(t, s1.RPC)

// Create the register request
eval1 := mock.Eval()
eval1.ID = "aaaaaaaa-3350-4b4b-d185-0e1992ed43e9"
eval2 := mock.Eval()
eval2.ID = "aaaabbbb-3350-4b4b-d185-0e1992ed43e9"
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2})

// Lookup the eval
get := &structs.EvalListRequest{
QueryOptions: structs.QueryOptions{
Region: "global",
Namespace: "*",
},
}
var resp structs.EvalListResponse
if err := msgpackrpc.CallWithCodec(codec, "Eval.List", get, &resp); err != nil {
t.Fatalf("err: %v", err)
}
if resp.Index != 1000 {
t.Fatalf("Bad index: %d %d", resp.Index, 1000)
}

if len(resp.Evaluations) != 2 {
t.Fatalf("bad: %#v", resp.Evaluations)
}

// Lookup the eval by prefix
get = &structs.EvalListRequest{
QueryOptions: structs.QueryOptions{
Region: "global",
Namespace: structs.DefaultNamespace,
Prefix: "aaaabb",
},
}
var resp2 structs.EvalListResponse
if err := msgpackrpc.CallWithCodec(codec, "Eval.List", get, &resp2); err != nil {
t.Fatalf("err: %v", err)
}
if resp2.Index != 1000 {
t.Fatalf("Bad index: %d %d", resp2.Index, 1000)
}

if len(resp2.Evaluations) != 1 {
t.Fatalf("bad: %#v", resp2.Evaluations)
}

}

func TestEvalEndpoint_List_ACL(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 4 additions & 0 deletions website/content/api-docs/evaluations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ The table below shows this endpoint's support for
specific evaluation status (one of `blocked`, `pending`, `complete`,
`failed`, or `canceled`).

- `namespace` `(string: "default")` - Specifies the target
namespace. Specifying `*` will return all evaluations across all
authorized namespaces.

### Sample Request

```shell-session
Expand Down

0 comments on commit ff5ee69

Please sign in to comment.