diff --git a/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go b/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go index f86c856420e..e57dd05099a 100644 --- a/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go +++ b/staging/src/k8s.io/apiserver/plugin/pkg/authorizer/webhook/webhook_v1_test.go @@ -814,6 +814,19 @@ func BenchmarkWithOneCELExpressions(b *testing.B) { benchmarkWebhookAuthorize(b, expressions, true) }) } +func BenchmarkWithOneCELExpressionsFalse(b *testing.B) { + expressions := []apiserver.WebhookMatchCondition{ + { + Expression: "request.user == 'alice2'", + }, + } + b.Run("compile", func(b *testing.B) { + benchmarkNewWebhookAuthorizer(b, expressions, true) + }) + b.Run("authorize", func(b *testing.B) { + benchmarkWebhookAuthorize(b, expressions, true) + }) +} func BenchmarkWithTwoCELExpressions(b *testing.B) { expressions := []apiserver.WebhookMatchCondition{ { @@ -830,13 +843,13 @@ func BenchmarkWithTwoCELExpressions(b *testing.B) { benchmarkWebhookAuthorize(b, expressions, true) }) } -func BenchmarkWithTwoComplexCELExpressions(b *testing.B) { +func BenchmarkWithTwoCELExpressionsFalse(b *testing.B) { expressions := []apiserver.WebhookMatchCondition{ { Expression: "request.user == 'alice'", }, { - Expression: "has(request.resourceAttributes) && request.resourceAttributes.namespace == 'kittensandponies'", + Expression: "request.uid == '2'", }, } b.Run("compile", func(b *testing.B) { @@ -880,6 +893,40 @@ func BenchmarkWithManyCELExpressions(b *testing.B) { benchmarkWebhookAuthorize(b, expressions, true) }) } +func BenchmarkWithManyCELExpressionsFalse(b *testing.B) { + expressions := []apiserver.WebhookMatchCondition{ + { + Expression: "request.user == 'alice'", + }, + { + Expression: "request.uid == '1'", + }, + { + Expression: "('group1' in request.groups)", + }, + { + Expression: "('key1' in request.extra)", + }, + { + Expression: "!('key2' in request.extra)", + }, + { + Expression: "('a' in request.extra['key1'])", + }, + { + Expression: "!('z' in request.extra['key1'])", + }, + { + Expression: "has(request.resourceAttributes) && request.resourceAttributes.namespace == 'kittensandponies1'", + }, + } + b.Run("compile", func(b *testing.B) { + benchmarkNewWebhookAuthorizer(b, expressions, true) + }) + b.Run("authorize", func(b *testing.B) { + benchmarkWebhookAuthorize(b, expressions, true) + }) +} func benchmarkNewWebhookAuthorizer(b *testing.B, expressions []apiserver.WebhookMatchCondition, featureEnabled bool) { service := new(mockV1Service)