np: fix list of jobs for node pool `all` (#17705)

Unlike nodes, jobs are allowed to be registered in the node pool `all`,
in which case all nodes are used for evaluating placements. When listing
jobs for the `all` node pool only those that are explicitly in this node
pool should be returned.
This commit is contained in:
Luiz Aoqui 2023-06-23 15:47:53 -04:00 committed by GitHub
parent 3398d32000
commit 66962b2b28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 33 deletions

View File

@ -440,13 +440,6 @@ func (n *NodePool) ListJobs(args *structs.NodePoolJobsRequest, reply *structs.No
}, },
} }
if args.Name == structs.NodePoolAll {
if namespace == structs.AllNamespacesSentinel {
iter, err = store.Jobs(ws)
} else {
iter, err = store.JobsByNamespace(ws, namespace)
}
} else {
if namespace == structs.AllNamespacesSentinel { if namespace == structs.AllNamespacesSentinel {
iter, err = store.JobsByPool(ws, args.Name) iter, err = store.JobsByPool(ws, args.Name)
} else { } else {
@ -462,8 +455,6 @@ func (n *NodePool) ListJobs(args *structs.NodePoolJobsRequest, reply *structs.No
}, },
}) })
} }
}
if err != nil { if err != nil {
return err return err
} }

View File

@ -1454,6 +1454,9 @@ func TestNodePoolEndpoint_ListJobs_PaginationFiltering(t *testing.T) {
{name: "job-08", pool: "prod-1", namespace: "default", status: structs.JobStatusRunning}, {name: "job-08", pool: "prod-1", namespace: "default", status: structs.JobStatusRunning},
{name: "job-09", pool: "prod-1", namespace: "non-default", status: structs.JobStatusPending}, {name: "job-09", pool: "prod-1", namespace: "non-default", status: structs.JobStatusPending},
{name: "job-10", pool: "dev-1", namespace: "default", status: structs.JobStatusPending}, {name: "job-10", pool: "dev-1", namespace: "default", status: structs.JobStatusPending},
{name: "job-11", pool: "all", namespace: "default", status: structs.JobStatusPending},
{name: "job-12", pool: "all", namespace: "default", status: structs.JobStatusPending},
{name: "job-13", pool: "all", namespace: "non-default", status: structs.JobStatusPending},
} }
for _, m := range mocks { for _, m := range mocks {
job := mock.MinJob() job := mock.MinJob()
@ -1587,18 +1590,15 @@ func TestNodePoolEndpoint_ListJobs_PaginationFiltering(t *testing.T) {
pool: "all", pool: "all",
namespace: "*", namespace: "*",
aclToken: root.SecretID, aclToken: root.SecretID,
expectedIDs: []string{ // note these are sorted namespace-then-job-ID expectedIDs: []string{"job-11", "job-12", "job-13"},
"job-00", "job-01", "job-02", "job-04", "job-05",
"job-08", "job-10", "job-06", "job-03", "job-09",
},
}, },
{ {
name: "test14 all pool default NS", name: "test14 all pool default NS",
pool: "all", pool: "all",
pageSize: 4, pageSize: 1,
aclToken: root.SecretID, aclToken: root.SecretID,
expectedNextToken: "default.job-05", expectedNextToken: "default.job-12",
expectedIDs: []string{"job-00", "job-01", "job-02", "job-04"}, expectedIDs: []string{"job-11"},
}, },
} }