api: respect wildcard in evaluations list API (#11710)
This commit is contained in:
parent
90cdc7b47a
commit
e046bb31e9
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
api: Updated the evaluations list API to respect wildcard namespaces
|
||||
```
|
|
@ -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())
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue