diff --git a/.changelog/11710.txt b/.changelog/11710.txt new file mode 100644 index 000000000000..ac405d372c3f --- /dev/null +++ b/.changelog/11710.txt @@ -0,0 +1,3 @@ +```release-note:improvement +api: Updated the evaluations list API to respect wildcard namespaces +``` diff --git a/nomad/eval_endpoint.go b/nomad/eval_endpoint.go index e3a14946d89e..5fe4d3658dee 100644 --- a/nomad/eval_endpoint.go +++ b/nomad/eval_endpoint.go @@ -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()) diff --git a/nomad/eval_endpoint_test.go b/nomad/eval_endpoint_test.go index ef142a9d9d6a..2b78c6b72d79 100644 --- a/nomad/eval_endpoint_test.go +++ b/nomad/eval_endpoint_test.go @@ -718,6 +718,41 @@ 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) + } +} + func TestEvalEndpoint_List_ACL(t *testing.T) { t.Parallel() diff --git a/website/content/api-docs/evaluations.mdx b/website/content/api-docs/evaluations.mdx index 9711140edd17..ab78127eaeab 100644 --- a/website/content/api-docs/evaluations.mdx +++ b/website/content/api-docs/evaluations.mdx @@ -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