Skip to content

Commit

Permalink
add extra comments and update value for maxRequestSize
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Jan 6, 2024
1 parent de53931 commit a1a68d0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 2 additions & 0 deletions pkg/webhook/admission/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var admissionCodecs = serializer.NewCodecFactory(admissionScheme)
// be at most 3MB in size. For the rest of the request, we can assume that
// it will be less than 1MB in size. Therefore, we can set the max request
// size to 7MB.
// If your use case requires larger max request sizes, please
// open an issue (https://github.com/kubernetes-sigs/controller-runtime/issues/new).
var maxRequestSize = int64(7 * 1024 * 1024)

func init() {
Expand Down
19 changes: 6 additions & 13 deletions pkg/webhook/authentication/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,12 @@ import (
var authenticationScheme = runtime.NewScheme()
var authenticationCodecs = serializer.NewCodecFactory(authenticationScheme)

// adapted from https://github.com/kubernetes/kubernetes/blob/c28c2009181fcc44c5f6b47e10e62dacf53e4da0/staging/src/k8s.io/pod-security-admission/cmd/webhook/server/server.go
//
// From https://github.com/kubernetes/apiserver/blob/d6876a0600de06fef75968c4641c64d7da499f25/pkg/server/config.go#L433-L442C5:
//
// 1.5MB is the recommended client request size in byte
// the etcd server should accept. See
// https://github.com/etcd-io/etcd/blob/release-3.4/embed/config.go#L56.
// A request body might be encoded in json, and is converted to
// proto when persisted in etcd, so we allow 2x as the largest request
// body size to be accepted and decoded in a write request.
//
// For the TokenReview request, we can assume that it too will be less than 3MB in size.
var maxRequestSize = int64(3 * 1024 * 1024)
// The TokenReview resource mostly contains a bearer token which
// at most should have a few KB's of size, so we picked 1 MB to
// have plenty of buffer.
// If your use case requires larger max request sizes, please
// open an issue (https://github.com/kubernetes-sigs/controller-runtime/issues/new).
var maxRequestSize = int64(1 * 1024 * 1024)

func init() {
utilruntime.Must(authenticationv1.AddToScheme(authenticationScheme))
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/authentication/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var _ = Describe("Authentication Webhooks", func() {
Body: nopCloser{Reader: rand.Reader},
}

expected := `{"metadata":{"creationTimestamp":null},"spec":{},"status":{"user":{},"error":"request entity is too large; limit is 3145728 bytes"}}
expected := `{"metadata":{"creationTimestamp":null},"spec":{},"status":{"user":{},"error":"request entity is too large; limit is 1048578 bytes"}}
`
webhook.ServeHTTP(respRecorder, req)
Expect(respRecorder.Body.String()).To(Equal(expected))
Expand Down

0 comments on commit a1a68d0

Please sign in to comment.