From ae9f6b2601c8f8b97ad2865943f423d65539ffdb Mon Sep 17 00:00:00 2001 From: Mike Danese Date: Mon, 27 Jan 2020 17:54:13 -0800 Subject: [PATCH] update rest.Request signatures Kubernetes-commit: 510aa1b432499f752fbacb2abf7e19f73311cdad --- rest/request.go | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/rest/request.go b/rest/request.go index ebc811e42b..545f15db8a 100644 --- a/rest/request.go +++ b/rest/request.go @@ -61,8 +61,8 @@ type HTTPClient interface { // ResponseWrapper is an interface for getting a response. // The response may be either accessed as a raw data (the whole output is put into memory) or as a stream. type ResponseWrapper interface { - DoRaw() ([]byte, error) - Stream() (io.ReadCloser, error) + DoRaw(context.Context) ([]byte, error) + Stream(context.Context) (io.ReadCloser, error) } // RequestConstructionError is returned when there's an error assembling a request. @@ -104,9 +104,6 @@ type Request struct { // output err error body io.Reader - - // This is only used for per-request timeouts, deadlines, and cancellations. - ctx context.Context } // NewRequest creates a new request helper object for accessing runtime.Objects on a server. @@ -438,13 +435,6 @@ func (r *Request) Body(obj interface{}) *Request { return r } -// Context adds a context to the request. Contexts are only used for -// timeouts, deadlines, and cancellations. -func (r *Request) Context(ctx context.Context) *Request { - r.ctx = ctx - return r -} - // URL returns the current working URL. func (r *Request) URL() *url.URL { p := r.pathPrefix @@ -566,12 +556,7 @@ func (r *Request) tryThrottle(ctx context.Context) error { // Watch attempts to begin watching the requested location. // Returns a watch.Interface, or an error. -func (r *Request) Watch() (watch.Interface, error) { - ctx := context.Background() - if r.ctx != nil { - ctx = r.ctx - } - +func (r *Request) Watch(ctx context.Context) (watch.Interface, error) { // We specifically don't want to rate limit watches, so we // don't use r.rateLimiter here. if r.err != nil { @@ -658,12 +643,7 @@ func updateURLMetrics(req *Request, resp *http.Response, err error) { // Returns io.ReadCloser which could be used for streaming of the response, or an error // Any non-2xx http status code causes an error. If we get a non-2xx code, we try to convert the body into an APIStatus object. // If we can, we return that as an error. Otherwise, we create an error that lists the http status and the content of the response. -func (r *Request) Stream() (io.ReadCloser, error) { - ctx := context.Background() - if r.ctx != nil { - ctx = r.ctx - } - +func (r *Request) Stream(ctx context.Context) (io.ReadCloser, error) { if r.err != nil { return nil, r.err } @@ -875,12 +855,7 @@ func (r *Request) request(ctx context.Context, fn func(*http.Request, *http.Resp // Error type: // * If the server responds with a status: *errors.StatusError or *errors.UnexpectedObjectError // * http.Client.Do errors are returned directly. -func (r *Request) Do() Result { - ctx := context.Background() - if r.ctx != nil { - ctx = r.ctx - } - +func (r *Request) Do(ctx context.Context) Result { var result Result err := r.request(ctx, func(req *http.Request, resp *http.Response) { result = r.transformResponse(resp, req) @@ -892,12 +867,7 @@ func (r *Request) Do() Result { } // DoRaw executes the request but does not process the response body. -func (r *Request) DoRaw() ([]byte, error) { - ctx := context.Background() - if r.ctx != nil { - ctx = r.ctx - } - +func (r *Request) DoRaw(ctx context.Context) ([]byte, error) { var result Result err := r.request(ctx, func(req *http.Request, resp *http.Response) { result.body, result.err = ioutil.ReadAll(resp.Body)