Skip to content

Commit c24a366

Browse files
committed
use the existing request info
1 parent 275f5cf commit c24a366

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,15 @@ func newRequestForProxy(location *url.URL, req *http.Request, enableAggregatedDi
181181
newCtx := req.Context()
182182
cancelFn := func() {}
183183

184-
// trim leading and trailing slashes. Then "/apis/group/version" requests are for discovery, so if we have exactly three
185-
// segments that we are going to proxy, we have a discovery request.
186-
if enableAggregatedDiscoveryTimeout && len(strings.Split(strings.Trim(req.URL.Path, "/"), "/")) == 3 {
187-
// discovery requests are used by kubectl and others to determine which resources a server has. This is a cheap call that
188-
// should be fast for every aggregated apiserver. Latency for aggregation is expected to be low (as for all extensions)
189-
// so forcing a short timeout here helps responsiveness of all clients.
190-
newCtx, cancelFn = context.WithTimeout(newCtx, aggregatedDiscoveryTimeout)
184+
if requestInfo, ok := genericapirequest.RequestInfoFrom(req.Context()); ok {
185+
// trim leading and trailing slashes. Then "/apis/group/version" requests are for discovery, so if we have exactly three
186+
// segments that we are going to proxy, we have a discovery request.
187+
if enableAggregatedDiscoveryTimeout && !requestInfo.IsResourceRequest && len(strings.Split(strings.Trim(requestInfo.Path, "/"), "/")) == 3 {
188+
// discovery requests are used by kubectl and others to determine which resources a server has. This is a cheap call that
189+
// should be fast for every aggregated apiserver. Latency for aggregation is expected to be low (as for all extensions)
190+
// so forcing a short timeout here helps responsiveness of all clients.
191+
newCtx, cancelFn = context.WithTimeout(newCtx, aggregatedDiscoveryTimeout)
192+
}
191193
}
192194

193195
// WithContext creates a shallow clone of the request with the same context.

staging/src/k8s.io/kube-aggregator/pkg/apiserver/handler_proxy_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ func TestGetContextForNewRequest(t *testing.T) {
540540
}
541541
location.Path = req.URL.Path
542542

543-
newReq, cancelFn := newRequestForProxy(location, req, true)
543+
nestedReq := req.WithContext(genericapirequest.WithRequestInfo(req.Context(), &genericapirequest.RequestInfo{Path: req.URL.Path}))
544+
newReq, cancelFn := newRequestForProxy(location, nestedReq, true)
544545
defer cancelFn()
545546

546547
theproxy := proxy.NewUpgradeAwareHandler(location, server.Client().Transport, true, false, &responder{w: w})

0 commit comments

Comments
 (0)