mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
use the existing request info
This commit is contained in:
parent
275f5cf5a0
commit
c24a36610e
@ -181,14 +181,16 @@ func newRequestForProxy(location *url.URL, req *http.Request, enableAggregatedDi
|
|||||||
newCtx := req.Context()
|
newCtx := req.Context()
|
||||||
cancelFn := func() {}
|
cancelFn := func() {}
|
||||||
|
|
||||||
|
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
|
// 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.
|
// segments that we are going to proxy, we have a discovery request.
|
||||||
if enableAggregatedDiscoveryTimeout && len(strings.Split(strings.Trim(req.URL.Path, "/"), "/")) == 3 {
|
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
|
// 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)
|
// 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.
|
// so forcing a short timeout here helps responsiveness of all clients.
|
||||||
newCtx, cancelFn = context.WithTimeout(newCtx, aggregatedDiscoveryTimeout)
|
newCtx, cancelFn = context.WithTimeout(newCtx, aggregatedDiscoveryTimeout)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithContext creates a shallow clone of the request with the same context.
|
// WithContext creates a shallow clone of the request with the same context.
|
||||||
newReq := req.WithContext(newCtx)
|
newReq := req.WithContext(newCtx)
|
||||||
|
@ -540,7 +540,8 @@ func TestGetContextForNewRequest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
location.Path = req.URL.Path
|
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()
|
defer cancelFn()
|
||||||
|
|
||||||
theproxy := proxy.NewUpgradeAwareHandler(location, server.Client().Transport, true, false, &responder{w: w})
|
theproxy := proxy.NewUpgradeAwareHandler(location, server.Client().Transport, true, false, &responder{w: w})
|
||||||
|
Loading…
Reference in New Issue
Block a user