Skip to content

Commit ae62cd6

Browse files
authored
Merge pull request kubernetes#111896 from deads2k/revert-compression-disable
Revert "Add an option to conditionally disable compression based on client ip."
2 parents 9305495 + 2f3ffbe commit ae62cd6

File tree

11 files changed

+15
-459
lines changed

11 files changed

+15
-459
lines changed

staging/src/k8s.io/apiserver/pkg/endpoints/filters/disable_compression.go

-43
This file was deleted.

staging/src/k8s.io/apiserver/pkg/endpoints/filters/disable_compression_test.go

-79
This file was deleted.

staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/writers.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,19 @@ func StreamObject(statusCode int, gv schema.GroupVersion, s runtime.NegotiatedSe
8787
// The context is optional and can be nil. This method will perform optional content compression if requested by
8888
// a client and the feature gate for APIResponseCompression is enabled.
8989
func SerializeObject(mediaType string, encoder runtime.Encoder, hw http.ResponseWriter, req *http.Request, statusCode int, object runtime.Object) {
90-
disableCompression := request.CompressionDisabledFrom(req.Context())
9190
trace := utiltrace.New("SerializeObject",
9291
utiltrace.Field{"audit-id", request.GetAuditIDTruncated(req.Context())},
9392
utiltrace.Field{"method", req.Method},
9493
utiltrace.Field{"url", req.URL.Path},
9594
utiltrace.Field{"protocol", req.Proto},
9695
utiltrace.Field{"mediaType", mediaType},
97-
utiltrace.Field{"encoder", encoder.Identifier()},
98-
utiltrace.Field{"disableCompression", disableCompression})
96+
utiltrace.Field{"encoder", encoder.Identifier()})
9997
defer trace.LogIfLong(5 * time.Second)
10098

10199
w := &deferredResponseWriter{
102100
mediaType: mediaType,
103101
statusCode: statusCode,
104-
contentEncoding: negotiateContentEncoding(req, disableCompression),
102+
contentEncoding: negotiateContentEncoding(req),
105103
hw: hw,
106104
trace: trace,
107105
}
@@ -157,12 +155,12 @@ const (
157155
// negotiateContentEncoding returns a supported client-requested content encoding for the
158156
// provided request. It will return the empty string if no supported content encoding was
159157
// found or if response compression is disabled.
160-
func negotiateContentEncoding(req *http.Request, disableCompression bool) string {
158+
func negotiateContentEncoding(req *http.Request) string {
161159
encoding := req.Header.Get("Accept-Encoding")
162160
if len(encoding) == 0 {
163161
return ""
164162
}
165-
if !utilfeature.DefaultFeatureGate.Enabled(features.APIResponseCompression) || disableCompression {
163+
if !utilfeature.DefaultFeatureGate.Enabled(features.APIResponseCompression) {
166164
return ""
167165
}
168166
for len(encoding) > 0 {

staging/src/k8s.io/apiserver/pkg/endpoints/handlers/responsewriters/writers_test.go

+1-37
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package responsewriters
1919
import (
2020
"bytes"
2121
"compress/gzip"
22-
"context"
2322
"encoding/hex"
2423
"encoding/json"
2524
"errors"
@@ -42,7 +41,6 @@ import (
4241
"k8s.io/apimachinery/pkg/runtime/schema"
4342
"k8s.io/apimachinery/pkg/util/diff"
4443
"k8s.io/apimachinery/pkg/util/uuid"
45-
"k8s.io/apiserver/pkg/endpoints/request"
4644
"k8s.io/apiserver/pkg/features"
4745
utilfeature "k8s.io/apiserver/pkg/util/feature"
4846
featuregatetesting "k8s.io/component-base/featuregate/testing"
@@ -233,7 +231,7 @@ func TestSerializeObject(t *testing.T) {
233231
},
234232

235233
{
236-
name: "compress on gzip, request's context has no decision",
234+
name: "compress on gzip",
237235
compressionEnabled: true,
238236
out: largePayload,
239237
mediaType: "application/json",
@@ -251,40 +249,6 @@ func TestSerializeObject(t *testing.T) {
251249
},
252250
wantBody: gzipContent(largePayload, defaultGzipContentEncodingLevel),
253251
},
254-
{
255-
name: "compress on gzip, request's context allows compression",
256-
compressionEnabled: true,
257-
out: largePayload,
258-
mediaType: "application/json",
259-
req: (&http.Request{
260-
Header: http.Header{
261-
"Accept-Encoding": []string{"gzip"},
262-
},
263-
URL: &url.URL{Path: "/path"},
264-
}).WithContext(request.WithCompressionDisabled(context.Background(), false)),
265-
wantCode: http.StatusOK,
266-
wantHeaders: http.Header{
267-
"Content-Type": []string{"application/json"},
268-
"Content-Encoding": []string{"gzip"},
269-
"Vary": []string{"Accept-Encoding"},
270-
},
271-
wantBody: gzipContent(largePayload, defaultGzipContentEncodingLevel),
272-
},
273-
{
274-
name: "compress on gzip, request's context disables compression",
275-
compressionEnabled: true,
276-
out: largePayload,
277-
mediaType: "application/json",
278-
req: (&http.Request{
279-
Header: http.Header{
280-
"Accept-Encoding": []string{"gzip"},
281-
},
282-
URL: &url.URL{Path: "/path"},
283-
}).WithContext(request.WithCompressionDisabled(context.Background(), true)),
284-
wantCode: http.StatusOK,
285-
wantHeaders: http.Header{"Content-Type": []string{"application/json"}},
286-
wantBody: largePayload,
287-
},
288252

289253
{
290254
name: "compression is not performed on small objects",

staging/src/k8s.io/apiserver/pkg/endpoints/request/disable_compression.go

-37
This file was deleted.

staging/src/k8s.io/apiserver/pkg/endpoints/request/disable_compression_test.go

-43
This file was deleted.

staging/src/k8s.io/apiserver/pkg/server/config.go

-6
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ type Config struct {
257257

258258
// StorageVersionManager holds the storage versions of the API resources installed by this server.
259259
StorageVersionManager storageversion.Manager
260-
261-
// CompressionDisabledFunc returns whether compression should be disabled for a given request.
262-
CompressionDisabledFunc genericapifilters.CompressionDisabledFunc
263260
}
264261

265262
type RecommendedConfig struct {
@@ -859,9 +856,6 @@ func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) http.Handler {
859856
if c.ShutdownSendRetryAfter {
860857
handler = genericfilters.WithRetryAfter(handler, c.lifecycleSignals.NotAcceptingNewRequest.Signaled())
861858
}
862-
if c.CompressionDisabledFunc != nil {
863-
handler = genericapifilters.WithCompressionDisabled(handler, c.CompressionDisabledFunc)
864-
}
865859
handler = genericfilters.WithHTTPLogging(handler)
866860
if utilfeature.DefaultFeatureGate.Enabled(genericfeatures.APIServerTracing) {
867861
handler = genericapifilters.WithTracing(handler, c.TracerProvider)

0 commit comments

Comments
 (0)