support for scaling_policy in global prefix search
This commit is contained in:
parent
369d030467
commit
ebbb760ec4
|
@ -31,6 +31,7 @@ var (
|
|||
structs.Deployments,
|
||||
structs.Plugins,
|
||||
structs.Volumes,
|
||||
structs.ScalingPolicies,
|
||||
structs.Namespaces,
|
||||
}
|
||||
)
|
||||
|
@ -68,6 +69,8 @@ func (s *Search) getMatches(iter memdb.ResultIterator, prefix string) ([]string,
|
|||
id = t.ID
|
||||
case *structs.CSIVolume:
|
||||
id = t.ID
|
||||
case *structs.ScalingPolicy:
|
||||
id = t.ID
|
||||
case *structs.Namespace:
|
||||
id = t.Name
|
||||
default:
|
||||
|
@ -106,6 +109,8 @@ func getResourceIter(context structs.Context, aclObj *acl.ACL, namespace, prefix
|
|||
return state.DeploymentsByIDPrefix(ws, namespace, prefix)
|
||||
case structs.Plugins:
|
||||
return state.CSIPluginsByIDPrefix(ws, prefix)
|
||||
case structs.ScalingPolicies:
|
||||
return state.ScalingPoliciesByIDPrefix(ws, namespace, prefix)
|
||||
case structs.Volumes:
|
||||
return state.CSIVolumesByIDPrefix(ws, namespace, prefix)
|
||||
case structs.Namespaces:
|
||||
|
|
|
@ -102,6 +102,7 @@ func searchContexts(aclObj *acl.ACL, namespace string, context structs.Context)
|
|||
acl.NamespaceCapabilityListJobs,
|
||||
acl.NamespaceCapabilityReadJob)
|
||||
volRead := allowVolume(aclObj, namespace)
|
||||
policyRead := aclObj.AllowNsOp(namespace, acl.NamespaceCapabilityListScalingPolicies)
|
||||
|
||||
// Filter contexts down to those the ACL grants access to
|
||||
available := make([]structs.Context, 0, len(all))
|
||||
|
@ -111,6 +112,10 @@ func searchContexts(aclObj *acl.ACL, namespace string, context structs.Context)
|
|||
if jobRead {
|
||||
available = append(available, c)
|
||||
}
|
||||
case structs.ScalingPolicies:
|
||||
if policyRead || jobRead {
|
||||
available = append(available, c)
|
||||
}
|
||||
case structs.Namespaces:
|
||||
if aclObj.AllowNamespace(namespace) {
|
||||
available = append(available, c)
|
||||
|
|
|
@ -989,3 +989,42 @@ func TestSearch_PrefixSearch_Namespace_ACL(t *testing.T) {
|
|||
assert.Len(resp.Matches[structs.Namespaces], 2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSearch_PrefixSearch_ScalingPolicy(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
|
||||
s, cleanupS := TestServer(t, func(c *Config) {
|
||||
c.NumSchedulers = 0
|
||||
})
|
||||
defer cleanupS()
|
||||
codec := rpcClient(t, s)
|
||||
testutil.WaitForLeader(t, s.RPC)
|
||||
|
||||
job, policy := mock.JobWithScalingPolicy()
|
||||
prefix := policy.ID
|
||||
state := s.fsm.State()
|
||||
|
||||
require.NoError(state.UpsertJob(structs.MsgTypeTestSetup, jobIndex, job))
|
||||
|
||||
req := &structs.SearchRequest{
|
||||
Prefix: prefix,
|
||||
Context: structs.ScalingPolicies,
|
||||
QueryOptions: structs.QueryOptions{
|
||||
Region: "global",
|
||||
Namespace: job.Namespace,
|
||||
},
|
||||
}
|
||||
|
||||
var resp structs.SearchResponse
|
||||
require.NoError(msgpackrpc.CallWithCodec(codec, "Search.PrefixSearch", req, &resp))
|
||||
require.Equal(1, len(resp.Matches[structs.ScalingPolicies]))
|
||||
require.Equal(policy.ID, resp.Matches[structs.ScalingPolicies][0])
|
||||
require.Equal(uint64(jobIndex), resp.Index)
|
||||
|
||||
req.Context = structs.All
|
||||
require.NoError(msgpackrpc.CallWithCodec(codec, "Search.PrefixSearch", req, &resp))
|
||||
require.Equal(1, len(resp.Matches[structs.ScalingPolicies]))
|
||||
require.Equal(policy.ID, resp.Matches[structs.ScalingPolicies][0])
|
||||
require.Equal(uint64(jobIndex), resp.Index)
|
||||
}
|
||||
|
|
|
@ -201,6 +201,7 @@ const (
|
|||
Namespaces Context = "namespaces"
|
||||
Quotas Context = "quotas"
|
||||
Recommendations Context = "recommendations"
|
||||
ScalingPolicies Context = "scaling_policy"
|
||||
All Context = "all"
|
||||
Plugins Context = "plugins"
|
||||
Volumes Context = "volumes"
|
||||
|
|
Loading…
Reference in New Issue