Skip to content

Commit 19ee1ea

Browse files
authored
Merge pull request kubernetes#85810 from liggitt/disable-webhook-ratelimit
Ensure webhook backend requests are not artificially rate-limited
2 parents 3769de9 + d620493 commit 19ee1ea

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

staging/src/k8s.io/apiserver/pkg/util/webhook/client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ func (cm *ClientManager) HookClient(cc ClientConfig) (*rest.RESTClient, error) {
131131
}
132132

133133
complete := func(cfg *rest.Config) (*rest.RESTClient, error) {
134+
// Avoid client-side rate limiting talking to the webhook backend.
135+
// Rate limiting should happen when deciding how many requests to serve.
136+
cfg.QPS = -1
137+
134138
// Combine CAData from the config with any existing CA bundle provided
135139
if len(cfg.TLSClientConfig.CAData) > 0 {
136140
cfg.TLSClientConfig.CAData = append(cfg.TLSClientConfig.CAData, '\n')

staging/src/k8s.io/apiserver/pkg/util/webhook/webhook.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ func newGenericWebhook(scheme *runtime.Scheme, codecFactory serializer.CodecFact
8888
// Set this to something reasonable so request to webhooks don't hang forever.
8989
clientConfig.Timeout = requestTimeout
9090

91+
// Avoid client-side rate limiting talking to the webhook backend.
92+
// Rate limiting should happen when deciding how many requests to serve.
93+
clientConfig.QPS = -1
94+
9195
codec := codecFactory.LegacyCodec(groupVersions...)
9296
clientConfig.ContentConfig.NegotiatedSerializer = serializer.NegotiatedSerializerWrapper(runtime.SerializerInfo{Serializer: codec})
9397

test/integration/apiserver/admissionwebhook/admission_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,17 @@ func testWebhookAdmission(t *testing.T, watchCache bool) {
566566
// Allow the webhook to establish
567567
time.Sleep(time.Second)
568568

569+
start := time.Now()
570+
count := 0
571+
569572
// Test admission on all resources, subresources, and verbs
570573
for _, gvr := range gvrsToTest {
571574
resource := resourcesByGVR[gvr]
572575
t.Run(gvr.Group+"."+gvr.Version+"."+strings.ReplaceAll(resource.Name, "/", "."), func(t *testing.T) {
573576
for _, verb := range []string{"create", "update", "patch", "connect", "delete", "deletecollection"} {
574577
if shouldTestResourceVerb(gvr, resource, verb) {
575578
t.Run(verb, func(t *testing.T) {
579+
count++
576580
holder.reset(t)
577581
testFunc := getTestFunc(gvr, verb)
578582
testFunc(&testContext{
@@ -591,6 +595,12 @@ func testWebhookAdmission(t *testing.T, watchCache bool) {
591595
}
592596
})
593597
}
598+
599+
duration := time.Now().Sub(start)
600+
perResourceDuration := time.Duration(int(duration) / count)
601+
if perResourceDuration >= 150*time.Millisecond {
602+
t.Errorf("expected resources to process in < 150ms, average was %v", perResourceDuration)
603+
}
594604
}
595605

596606
//

0 commit comments

Comments
 (0)