mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-16 23:28:25 +00:00
Remove ioutil from client-go
Signed-off-by: inosato <si17_21@yahoo.co.jp> Kubernetes-commit: 88dfa51b6003c90e8f0a0508939a1d79950a40df
This commit is contained in:
committed by
Kubernetes Publisher
parent
2e404084ad
commit
27de641f75
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -519,7 +518,7 @@ func InClusterConfig() (*Config, error) {
|
||||
return nil, ErrNotInCluster
|
||||
}
|
||||
|
||||
token, err := ioutil.ReadFile(tokenFile)
|
||||
token, err := os.ReadFile(tokenFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -585,7 +584,7 @@ func dataFromSliceOrFile(data []byte, file string) ([]byte, error) {
|
||||
return data, nil
|
||||
}
|
||||
if len(file) > 0 {
|
||||
fileData, err := ioutil.ReadFile(file)
|
||||
fileData, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
@@ -22,10 +22,10 @@ import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -437,7 +437,7 @@ func (r *Request) Body(obj interface{}) *Request {
|
||||
}
|
||||
switch t := obj.(type) {
|
||||
case string:
|
||||
data, err := ioutil.ReadFile(t)
|
||||
data, err := os.ReadFile(t)
|
||||
if err != nil {
|
||||
r.err = err
|
||||
return r
|
||||
@@ -745,7 +745,7 @@ func (r *Request) Stream(ctx context.Context) (io.ReadCloser, error) {
|
||||
return nil, err
|
||||
}
|
||||
if r.body != nil {
|
||||
req.Body = ioutil.NopCloser(r.body)
|
||||
req.Body = io.NopCloser(r.body)
|
||||
}
|
||||
resp, err := client.Do(req)
|
||||
updateURLMetrics(ctx, r, resp, err)
|
||||
@@ -937,7 +937,7 @@ func (r *Request) Do(ctx context.Context) Result {
|
||||
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)
|
||||
result.body, result.err = io.ReadAll(resp.Body)
|
||||
glogBody("Response Body", result.body)
|
||||
if resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusPartialContent {
|
||||
result.err = r.transformUnstructuredResponseError(resp, req, result.body)
|
||||
@@ -956,7 +956,7 @@ func (r *Request) DoRaw(ctx context.Context) ([]byte, error) {
|
||||
func (r *Request) transformResponse(resp *http.Response, req *http.Request) Result {
|
||||
var body []byte
|
||||
if resp.Body != nil {
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
switch err.(type) {
|
||||
case nil:
|
||||
body = data
|
||||
@@ -1098,7 +1098,7 @@ const maxUnstructuredResponseTextBytes = 2048
|
||||
// TODO: introduce transformation of generic http.Client.Do() errors that separates 4.
|
||||
func (r *Request) transformUnstructuredResponseError(resp *http.Response, req *http.Request, body []byte) error {
|
||||
if body == nil && resp.Body != nil {
|
||||
if data, err := ioutil.ReadAll(&io.LimitedReader{R: resp.Body, N: maxUnstructuredResponseTextBytes}); err == nil {
|
||||
if data, err := io.ReadAll(&io.LimitedReader{R: resp.Body, N: maxUnstructuredResponseTextBytes}); err == nil {
|
||||
body = data
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,6 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -88,7 +87,7 @@ func TestRequestSetsHeaders(t *testing.T) {
|
||||
}
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusForbidden,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, nil
|
||||
})
|
||||
config := defaultContentConfig()
|
||||
@@ -303,7 +302,7 @@ func TestRequestBody(t *testing.T) {
|
||||
}
|
||||
|
||||
// test error set when failing to read file
|
||||
f, err := ioutil.TempFile("", "test")
|
||||
f, err := os.CreateTemp("", "test")
|
||||
if err != nil {
|
||||
t.Fatalf("unable to create temp file")
|
||||
}
|
||||
@@ -360,7 +359,7 @@ func TestTransformResponse(t *testing.T) {
|
||||
Response: &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Header: http.Header{"Content-Type": []string{"application/json"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
Body: io.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Error: true,
|
||||
ErrFn: func(err error) bool {
|
||||
@@ -371,7 +370,7 @@ func TestTransformResponse(t *testing.T) {
|
||||
Response: &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Header: http.Header{"Content-Type": []string{"text/any"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
Body: io.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Error: true,
|
||||
ErrFn: func(err error) bool {
|
||||
@@ -379,13 +378,13 @@ func TestTransformResponse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
{Response: &http.Response{StatusCode: http.StatusForbidden}, Error: true},
|
||||
{Response: &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||
{Response: &http.Response{StatusCode: http.StatusOK, Body: ioutil.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||
{Response: &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||
{Response: &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(bytes.NewReader(invalid))}, Data: invalid},
|
||||
}
|
||||
for i, test := range testCases {
|
||||
r := NewRequestWithClient(uri, "", defaultContentConfig(), nil)
|
||||
if test.Response.Body == nil {
|
||||
test.Response.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||
test.Response.Body = io.NopCloser(bytes.NewReader([]byte{}))
|
||||
}
|
||||
result := r.transformResponse(test.Response, &http.Request{})
|
||||
response, created, err := result.body, result.statusCode == http.StatusCreated, result.err
|
||||
@@ -458,7 +457,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
Response: &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Header: http.Header{"Content-Type": []string{"application/json"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
Body: io.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Called: true,
|
||||
ExpectContentType: "application/json",
|
||||
@@ -472,7 +471,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
Response: &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Header: http.Header{"Content-Type": []string{"application/protobuf"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
Body: io.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
|
||||
@@ -502,7 +501,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
Response: &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Header: http.Header{"Content-Type": []string{"text/any"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
Body: io.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
Called: true,
|
||||
@@ -513,7 +512,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
ContentType: "text/any",
|
||||
Response: &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
Body: io.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
Called: true,
|
||||
@@ -525,7 +524,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
Response: &http.Response{
|
||||
StatusCode: http.StatusNotFound,
|
||||
Header: http.Header{"Content-Type": []string{"application/unrecognized"}},
|
||||
Body: ioutil.NopCloser(bytes.NewReader(invalid)),
|
||||
Body: io.NopCloser(bytes.NewReader(invalid)),
|
||||
},
|
||||
Decoder: scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion),
|
||||
|
||||
@@ -549,7 +548,7 @@ func TestTransformResponseNegotiate(t *testing.T) {
|
||||
contentConfig.Negotiator = negotiator
|
||||
r := NewRequestWithClient(uri, "", contentConfig, nil)
|
||||
if test.Response.Body == nil {
|
||||
test.Response.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||
test.Response.Body = io.NopCloser(bytes.NewReader([]byte{}))
|
||||
}
|
||||
result := r.transformResponse(test.Response, &http.Request{})
|
||||
_, err := result.body, result.err
|
||||
@@ -601,7 +600,7 @@ func TestTransformUnstructuredError(t *testing.T) {
|
||||
},
|
||||
Res: &http.Response{
|
||||
StatusCode: http.StatusConflict,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(nil)),
|
||||
Body: io.NopCloser(bytes.NewReader(nil)),
|
||||
},
|
||||
ErrFn: apierrors.IsAlreadyExists,
|
||||
},
|
||||
@@ -613,7 +612,7 @@ func TestTransformUnstructuredError(t *testing.T) {
|
||||
},
|
||||
Res: &http.Response{
|
||||
StatusCode: http.StatusConflict,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(nil)),
|
||||
Body: io.NopCloser(bytes.NewReader(nil)),
|
||||
},
|
||||
ErrFn: apierrors.IsConflict,
|
||||
},
|
||||
@@ -623,7 +622,7 @@ func TestTransformUnstructuredError(t *testing.T) {
|
||||
Req: &http.Request{},
|
||||
Res: &http.Response{
|
||||
StatusCode: http.StatusNotFound,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(nil)),
|
||||
Body: io.NopCloser(bytes.NewReader(nil)),
|
||||
},
|
||||
ErrFn: apierrors.IsNotFound,
|
||||
},
|
||||
@@ -631,14 +630,14 @@ func TestTransformUnstructuredError(t *testing.T) {
|
||||
Req: &http.Request{},
|
||||
Res: &http.Response{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Body: ioutil.NopCloser(bytes.NewReader(nil)),
|
||||
Body: io.NopCloser(bytes.NewReader(nil)),
|
||||
},
|
||||
ErrFn: apierrors.IsBadRequest,
|
||||
},
|
||||
{
|
||||
// status in response overrides transformed result
|
||||
Req: &http.Request{},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","apiVersion":"v1","status":"Failure","code":404}`)))},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: io.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","apiVersion":"v1","status":"Failure","code":404}`)))},
|
||||
ErrFn: apierrors.IsBadRequest,
|
||||
Transformed: &apierrors.StatusError{
|
||||
ErrStatus: metav1.Status{Status: metav1.StatusFailure, Code: http.StatusNotFound},
|
||||
@@ -647,20 +646,20 @@ func TestTransformUnstructuredError(t *testing.T) {
|
||||
{
|
||||
// successful status is ignored
|
||||
Req: &http.Request{},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","apiVersion":"v1","status":"Success","code":404}`)))},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: io.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","apiVersion":"v1","status":"Success","code":404}`)))},
|
||||
ErrFn: apierrors.IsBadRequest,
|
||||
},
|
||||
{
|
||||
// empty object does not change result
|
||||
Req: &http.Request{},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(bytes.NewReader([]byte(`{}`)))},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: io.NopCloser(bytes.NewReader([]byte(`{}`)))},
|
||||
ErrFn: apierrors.IsBadRequest,
|
||||
},
|
||||
{
|
||||
// we default apiVersion for backwards compatibility with old clients
|
||||
// TODO: potentially remove in 1.7
|
||||
Req: &http.Request{},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","status":"Failure","code":404}`)))},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: io.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","status":"Failure","code":404}`)))},
|
||||
ErrFn: apierrors.IsBadRequest,
|
||||
Transformed: &apierrors.StatusError{
|
||||
ErrStatus: metav1.Status{Status: metav1.StatusFailure, Code: http.StatusNotFound},
|
||||
@@ -669,7 +668,7 @@ func TestTransformUnstructuredError(t *testing.T) {
|
||||
{
|
||||
// we do not default kind
|
||||
Req: &http.Request{},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"status":"Failure","code":404}`)))},
|
||||
Res: &http.Response{StatusCode: http.StatusBadRequest, Body: io.NopCloser(bytes.NewReader([]byte(`{"status":"Failure","code":404}`)))},
|
||||
ErrFn: apierrors.IsBadRequest,
|
||||
},
|
||||
}
|
||||
@@ -773,7 +772,7 @@ func TestRequestWatch(t *testing.T) {
|
||||
serverReturns: []responseErr{
|
||||
{response: &http.Response{
|
||||
StatusCode: http.StatusForbidden,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, err: nil},
|
||||
},
|
||||
attemptsExpected: 1,
|
||||
@@ -816,7 +815,7 @@ func TestRequestWatch(t *testing.T) {
|
||||
serverReturns: []responseErr{
|
||||
{response: &http.Response{
|
||||
StatusCode: http.StatusForbidden,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, err: nil},
|
||||
},
|
||||
attemptsExpected: 1,
|
||||
@@ -836,7 +835,7 @@ func TestRequestWatch(t *testing.T) {
|
||||
serverReturns: []responseErr{
|
||||
{response: &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, err: nil},
|
||||
},
|
||||
attemptsExpected: 1,
|
||||
@@ -856,7 +855,7 @@ func TestRequestWatch(t *testing.T) {
|
||||
serverReturns: []responseErr{
|
||||
{response: &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &metav1.Status{
|
||||
Body: io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Reason: metav1.StatusReasonUnauthorized,
|
||||
})))),
|
||||
@@ -1088,7 +1087,7 @@ func TestRequestStream(t *testing.T) {
|
||||
serverReturns: []responseErr{
|
||||
{response: &http.Response{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &metav1.Status{
|
||||
Body: io.NopCloser(bytes.NewReader([]byte(runtime.EncodeOrDie(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), &metav1.Status{
|
||||
Status: metav1.StatusFailure,
|
||||
Reason: metav1.StatusReasonUnauthorized,
|
||||
})))),
|
||||
@@ -1107,7 +1106,7 @@ func TestRequestStream(t *testing.T) {
|
||||
serverReturns: []responseErr{
|
||||
{response: &http.Response{
|
||||
StatusCode: http.StatusBadRequest,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"a container name must be specified for pod kube-dns-v20-mz5cv, choose one of: [kubedns dnsmasq healthz]","reason":"BadRequest","code":400}`))),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte(`{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"a container name must be specified for pod kube-dns-v20-mz5cv, choose one of: [kubedns dnsmasq healthz]","reason":"BadRequest","code":400}`))),
|
||||
}, err: nil},
|
||||
},
|
||||
attemptsExpected: 1,
|
||||
@@ -1188,7 +1187,7 @@ func TestRequestStream(t *testing.T) {
|
||||
{response: retryAfterResponse(), err: nil},
|
||||
{response: &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, err: nil},
|
||||
},
|
||||
},
|
||||
@@ -1427,7 +1426,7 @@ func TestConnectionResetByPeerIsRetried(t *testing.T) {
|
||||
if count >= 3 {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
Body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
}, nil
|
||||
}
|
||||
return nil, &net.OpError{Err: syscall.ECONNRESET}
|
||||
@@ -1455,7 +1454,7 @@ func TestCheckRetryHandles429And5xx(t *testing.T) {
|
||||
count := 0
|
||||
ch := make(chan struct{})
|
||||
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
data, err := ioutil.ReadAll(req.Body)
|
||||
data, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to read request body: %v", err)
|
||||
}
|
||||
@@ -1607,7 +1606,7 @@ func TestDoRequestNewWayFile(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
file, err := ioutil.TempFile("", "foo")
|
||||
file, err := os.CreateTemp("", "foo")
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
@@ -1779,7 +1778,7 @@ func TestBody(t *testing.T) {
|
||||
obj := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}
|
||||
bodyExpected, _ := runtime.Encode(scheme.Codecs.LegacyCodec(v1.SchemeGroupVersion), obj)
|
||||
|
||||
f, err := ioutil.TempFile("", "test_body")
|
||||
f, err := os.CreateTemp("", "test_body")
|
||||
if err != nil {
|
||||
t.Fatalf("TempFile error: %v", err)
|
||||
}
|
||||
@@ -2449,7 +2448,7 @@ func TestRequestWithRetry(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "server returns retry-after response, request body is not io.Seeker, retry goes ahead",
|
||||
body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
serverReturns: responseErr{response: retryAfterResponse(), err: nil},
|
||||
errExpected: nil,
|
||||
transformFuncInvokedExpected: 1,
|
||||
@@ -2473,7 +2472,7 @@ func TestRequestWithRetry(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "server returns retryable err, request body is not io.Seek, retry goes ahead",
|
||||
body: ioutil.NopCloser(bytes.NewReader([]byte{})),
|
||||
body: io.NopCloser(bytes.NewReader([]byte{})),
|
||||
serverReturns: responseErr{response: nil, err: io.ErrUnexpectedEOF},
|
||||
errExpected: io.ErrUnexpectedEOF,
|
||||
transformFuncInvokedExpected: 0,
|
||||
@@ -2773,7 +2772,7 @@ func testRequestWithRetry(t *testing.T, key string, doFunc func(ctx context.Cont
|
||||
|
||||
resp := test.serverReturns[attempts].response
|
||||
if resp != nil {
|
||||
responseRecorder.delegated = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||
responseRecorder.delegated = io.NopCloser(bytes.NewReader([]byte{}))
|
||||
resp.Body = responseRecorder
|
||||
}
|
||||
return resp, test.serverReturns[attempts].err
|
||||
@@ -3054,7 +3053,7 @@ func testRetryWithRateLimiterBackoffAndMetrics(t *testing.T, key string, doFunc
|
||||
interceptor.Do()
|
||||
resp := test.serverReturns[attempts].response
|
||||
if resp != nil {
|
||||
resp.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||
resp.Body = io.NopCloser(bytes.NewReader([]byte{}))
|
||||
}
|
||||
return resp, test.serverReturns[attempts].err
|
||||
})
|
||||
@@ -3190,7 +3189,7 @@ func testWithRetryInvokeOrder(t *testing.T, key string, doFunc func(ctx context.
|
||||
interceptor.Do()
|
||||
resp := test.serverReturns[attempts].response
|
||||
if resp != nil {
|
||||
resp.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||
resp.Body = io.NopCloser(bytes.NewReader([]byte{}))
|
||||
}
|
||||
return resp, test.serverReturns[attempts].err
|
||||
})
|
||||
@@ -3365,7 +3364,7 @@ func testWithWrapPreviousError(t *testing.T, doFunc func(ctx context.Context, r
|
||||
|
||||
resp := test.serverReturns[attempts].response
|
||||
if resp != nil {
|
||||
resp.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||
resp.Body = io.NopCloser(bytes.NewReader([]byte{}))
|
||||
}
|
||||
return resp, test.serverReturns[attempts].err
|
||||
})
|
||||
@@ -3665,12 +3664,12 @@ func TestRequestBodyResetOrder(t *testing.T) {
|
||||
}()
|
||||
|
||||
// read the request body.
|
||||
ioutil.ReadAll(req.Body)
|
||||
io.ReadAll(req.Body)
|
||||
|
||||
// first attempt, we send a retry-after
|
||||
if attempts == 0 {
|
||||
resp := retryAfterResponse()
|
||||
respBodyTracker.ReadCloser = ioutil.NopCloser(bytes.NewReader([]byte{}))
|
||||
respBodyTracker.ReadCloser = io.NopCloser(bytes.NewReader([]byte{}))
|
||||
resp.Body = respBodyTracker
|
||||
return resp, nil
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@ package versioned_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
@@ -70,7 +70,7 @@ func TestEncodeDecodeRoundTrip(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
rc := ioutil.NopCloser(buf)
|
||||
rc := io.NopCloser(buf)
|
||||
decoder := restclientwatch.NewDecoder(streaming.NewDecoder(rc, getDecoder()), getDecoder())
|
||||
event, obj, err := decoder.Decode()
|
||||
if err != nil {
|
||||
|
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
@@ -345,7 +344,7 @@ func readAndCloseResponseBody(resp *http.Response) {
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.ContentLength <= maxBodySlurpSize {
|
||||
io.Copy(ioutil.Discard, &io.LimitedReader{R: resp.Body, N: maxBodySlurpSize})
|
||||
io.Copy(io.Discard, &io.LimitedReader{R: resp.Body, N: maxBodySlurpSize})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user