diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go index 9576cdd84e9..9d5cc5f0479 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go @@ -181,13 +181,15 @@ func newRequestForProxy(location *url.URL, req *http.Request, enableAggregatedDi newCtx := req.Context() cancelFn := func() {} - // trim leading and trailing slashes. Then "/apis/group/version" requests are for discovery, so if we have exactly three - // segments that we are going to proxy, we have a discovery request. - if enableAggregatedDiscoveryTimeout && len(strings.Split(strings.Trim(req.URL.Path, "/"), "/")) == 3 { - // discovery requests are used by kubectl and others to determine which resources a server has. This is a cheap call that - // should be fast for every aggregated apiserver. Latency for aggregation is expected to be low (as for all extensions) - // so forcing a short timeout here helps responsiveness of all clients. - newCtx, cancelFn = context.WithTimeout(newCtx, aggregatedDiscoveryTimeout) + if requestInfo, ok := genericapirequest.RequestInfoFrom(req.Context()); ok { + // trim leading and trailing slashes. Then "/apis/group/version" requests are for discovery, so if we have exactly three + // segments that we are going to proxy, we have a discovery request. + if enableAggregatedDiscoveryTimeout && !requestInfo.IsResourceRequest && len(strings.Split(strings.Trim(requestInfo.Path, "/"), "/")) == 3 { + // discovery requests are used by kubectl and others to determine which resources a server has. This is a cheap call that + // should be fast for every aggregated apiserver. Latency for aggregation is expected to be low (as for all extensions) + // so forcing a short timeout here helps responsiveness of all clients. + newCtx, cancelFn = context.WithTimeout(newCtx, aggregatedDiscoveryTimeout) + } } // WithContext creates a shallow clone of the request with the same context. diff --git a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go index 5df58b170e7..f9390923c09 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go @@ -540,7 +540,8 @@ func TestGetContextForNewRequest(t *testing.T) { } location.Path = req.URL.Path - newReq, cancelFn := newRequestForProxy(location, req, true) + nestedReq := req.WithContext(genericapirequest.WithRequestInfo(req.Context(), &genericapirequest.RequestInfo{Path: req.URL.Path})) + newReq, cancelFn := newRequestForProxy(location, nestedReq, true) defer cancelFn() theproxy := proxy.NewUpgradeAwareHandler(location, server.Client().Transport, true, false, &responder{w: w})