matches specific usernames instead of "*"

This commit is contained in:
yue9944882 2020-11-23 15:12:26 +08:00
parent ee31c93748
commit 812f13fbec

View File

@ -159,7 +159,7 @@ var _ = SIGDescribe("API priority and fairness", func() {
defer cleanup() defer cleanup()
framework.Logf("creating FlowSchema %q", flowSchemaName) framework.Logf("creating FlowSchema %q", flowSchemaName)
_, cleanup = createFlowSchema(f, flowSchemaName, 1000, priorityLevelName, "*") _, cleanup = createFlowSchema(f, flowSchemaName, 1000, priorityLevelName, "highqps", "lowqps")
defer cleanup() defer cleanup()
type client struct { type client struct {
@ -265,9 +265,9 @@ func getPriorityLevelConcurrency(f *framework.Framework, priorityLevelName strin
// createFlowSchema creates a flow schema referring to a particular priority // createFlowSchema creates a flow schema referring to a particular priority
// level and matching the username provided. // level and matching the username provided.
func createFlowSchema(f *framework.Framework, flowSchemaName string, matchingPrecedence int32, priorityLevelName string, matchingUsername string) (*flowcontrol.FlowSchema, func()) { func createFlowSchema(f *framework.Framework, flowSchemaName string, matchingPrecedence int32, priorityLevelName string, matchingUsernames ...string) (*flowcontrol.FlowSchema, func()) {
var subjects []flowcontrol.Subject var subjects []flowcontrol.Subject
if matchingUsername == "*" { if len(matchingUsernames) == 1 && matchingUsernames[0] == "*" {
subjects = append(subjects, flowcontrol.Subject{ subjects = append(subjects, flowcontrol.Subject{
Kind: flowcontrol.SubjectKindGroup, Kind: flowcontrol.SubjectKindGroup,
Group: &flowcontrol.GroupSubject{ Group: &flowcontrol.GroupSubject{
@ -275,12 +275,14 @@ func createFlowSchema(f *framework.Framework, flowSchemaName string, matchingPre
}, },
}) })
} else { } else {
subjects = append(subjects, flowcontrol.Subject{ for _, matchingUsername := range matchingUsernames {
Kind: flowcontrol.SubjectKindUser, subjects = append(subjects, flowcontrol.Subject{
User: &flowcontrol.UserSubject{ Kind: flowcontrol.SubjectKindUser,
Name: matchingUsername, User: &flowcontrol.UserSubject{
}, Name: matchingUsername,
}) },
})
}
} }
createdFlowSchema, err := f.ClientSet.FlowcontrolV1beta1().FlowSchemas().Create( createdFlowSchema, err := f.ClientSet.FlowcontrolV1beta1().FlowSchemas().Create(