Skip to content

Commit 3740c24

Browse files
authored
api: respect wildcard in evaluations list API (#11710)
1 parent 0ec5db4 commit 3740c24

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

.changelog/11710.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
api: Updated the evaluations list API to respect wildcard namespaces
3+
```

nomad/eval_endpoint.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,9 @@ func (e *Eval) List(args *structs.EvalListRequest,
353353
// Scan all the evaluations
354354
var err error
355355
var iter memdb.ResultIterator
356-
if prefix := args.QueryOptions.Prefix; prefix != "" {
356+
if args.RequestNamespace() == structs.AllNamespacesSentinel {
357+
iter, err = store.Evals(ws)
358+
} else if prefix := args.QueryOptions.Prefix; prefix != "" {
357359
iter, err = store.EvalsByIDPrefix(ws, args.RequestNamespace(), prefix)
358360
} else {
359361
iter, err = store.EvalsByNamespace(ws, args.RequestNamespace())

nomad/eval_endpoint_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,41 @@ func TestEvalEndpoint_List(t *testing.T) {
718718

719719
}
720720

721+
func TestEvalEndpoint_ListAllNamespaces(t *testing.T) {
722+
t.Parallel()
723+
724+
s1, cleanupS1 := TestServer(t, nil)
725+
defer cleanupS1()
726+
codec := rpcClient(t, s1)
727+
testutil.WaitForLeader(t, s1.RPC)
728+
729+
// Create the register request
730+
eval1 := mock.Eval()
731+
eval1.ID = "aaaaaaaa-3350-4b4b-d185-0e1992ed43e9"
732+
eval2 := mock.Eval()
733+
eval2.ID = "aaaabbbb-3350-4b4b-d185-0e1992ed43e9"
734+
s1.fsm.State().UpsertEvals(structs.MsgTypeTestSetup, 1000, []*structs.Evaluation{eval1, eval2})
735+
736+
// Lookup the eval
737+
get := &structs.EvalListRequest{
738+
QueryOptions: structs.QueryOptions{
739+
Region: "global",
740+
Namespace: "*",
741+
},
742+
}
743+
var resp structs.EvalListResponse
744+
if err := msgpackrpc.CallWithCodec(codec, "Eval.List", get, &resp); err != nil {
745+
t.Fatalf("err: %v", err)
746+
}
747+
if resp.Index != 1000 {
748+
t.Fatalf("Bad index: %d %d", resp.Index, 1000)
749+
}
750+
751+
if len(resp.Evaluations) != 2 {
752+
t.Fatalf("bad: %#v", resp.Evaluations)
753+
}
754+
}
755+
721756
func TestEvalEndpoint_List_ACL(t *testing.T) {
722757
t.Parallel()
723758

website/content/api-docs/evaluations.mdx

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ The table below shows this endpoint's support for
4949
specific evaluation status (one of `blocked`, `pending`, `complete`,
5050
`failed`, or `canceled`).
5151

52+
- `namespace` `(string: "default")` - Specifies the target
53+
namespace. Specifying `*` will return all evaluations across all
54+
authorized namespaces.
55+
5256
### Sample Request
5357

5458
```shell-session

0 commit comments

Comments
 (0)