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:
parent
3398d32000
commit
66962b2b28
|
@ -440,30 +440,21 @@ func (n *NodePool) ListJobs(args *structs.NodePoolJobsRequest, reply *structs.No
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.Name == structs.NodePoolAll {
|
if namespace == structs.AllNamespacesSentinel {
|
||||||
if namespace == structs.AllNamespacesSentinel {
|
iter, err = store.JobsByPool(ws, args.Name)
|
||||||
iter, err = store.Jobs(ws)
|
|
||||||
} else {
|
|
||||||
iter, err = store.JobsByNamespace(ws, namespace)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if namespace == structs.AllNamespacesSentinel {
|
iter, err = store.JobsByNamespace(ws, namespace)
|
||||||
iter, err = store.JobsByPool(ws, args.Name)
|
filters = append(filters,
|
||||||
} else {
|
paginator.GenericFilter{
|
||||||
iter, err = store.JobsByNamespace(ws, namespace)
|
Allow: func(raw interface{}) (bool, error) {
|
||||||
filters = append(filters,
|
job := raw.(*structs.Job)
|
||||||
paginator.GenericFilter{
|
if job == nil || job.NodePool != args.Name {
|
||||||
Allow: func(raw interface{}) (bool, error) {
|
return false, nil
|
||||||
job := raw.(*structs.Job)
|
}
|
||||||
if job == nil || job.NodePool != args.Name {
|
return true, nil
|
||||||
return false, nil
|
},
|
||||||
}
|
})
|
||||||
return true, nil
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
@ -1583,22 +1586,19 @@ func TestNodePoolEndpoint_ListJobs_PaginationFiltering(t *testing.T) {
|
||||||
expectedError: "Permission denied",
|
expectedError: "Permission denied",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "test13 all pool wildcard NS",
|
name: "test13 all pool wildcard NS",
|
||||||
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"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue