Skip to content

Commit

Permalink
replace deprecated ioutil method
Browse files Browse the repository at this point in the history
  • Loading branch information
umagnus committed Apr 20, 2023
1 parent ec092fa commit 3ea02d9
Show file tree
Hide file tree
Showing 35 changed files with 334 additions and 339 deletions.
3 changes: 1 addition & 2 deletions cmd/acr-credential-provider/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -63,7 +62,7 @@ func (e *ExecPlugin) Run(ctx context.Context) error {
}

func (e *ExecPlugin) runPlugin(ctx context.Context, r io.Reader, w io.Writer, args []string) error {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cloud-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"crypto/rand"
"encoding/json"
"fmt"
"io/ioutil"
"math/big"
"net/http"
"os"
Expand Down Expand Up @@ -235,7 +234,7 @@ func RunWrapper(s *options.CloudControllerManagerOptions, c *cloudcontrollerconf
}

func shouldDisableCloudProvider(configFilePath string) (bool, error) {
configBytes, err := ioutil.ReadFile(configFilePath)
configBytes, err := os.ReadFile(configFilePath)
if err != nil {
klog.Errorf("shouldDisableCloudProvider: failed to read %s %s", configFilePath, err.Error())
return false, err
Expand Down
3 changes: 1 addition & 2 deletions cmd/cloud-controller-manager/app/controllermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package app

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -33,7 +32,7 @@ func TestShouldDisableCloudProvider(t *testing.T) {
"disableCloudProvider": true
}
`
err := ioutil.WriteFile(fileName, []byte(content), 0600)
err := os.WriteFile(fileName, []byte(content), 0600)
assert.NoError(t, err)

defer func() {
Expand Down
3 changes: 1 addition & 2 deletions cmd/cloud-controller-manager/app/testing/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package testing
import (
"context"
"fmt"
"io/ioutil"
"net"
"os"
"time"
Expand Down Expand Up @@ -74,7 +73,7 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
}
}()

result.TmpDir, err = ioutil.TempDir("", "cloud-controller-manager")
result.TmpDir, err = os.MkdirTemp("", "cloud-controller-manager")
if err != nil {
return result, fmt.Errorf("failed to create temp dir: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions kubetest2-aks/deployer/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -94,7 +94,7 @@ func (p addCustomConfigPolicy) Do(req *policy.Request) (*http.Response, error) {
return req.Next()
}

body, err := ioutil.ReadAll(req.Raw().Body)
body, err := io.ReadAll(req.Raw().Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func (d *deployer) createResourceGroup(subscriptionID string) (armresources.Reso

func openPath(path string) ([]byte, error) {
if !strings.HasPrefix(path, "http://") && !strings.HasPrefix(path, "https://") {
return ioutil.ReadFile(path)
return os.ReadFile(path)
}
resp, err := http.Get(path)
if err != nil {
Expand All @@ -176,7 +176,7 @@ func openPath(path string) ([]byte, error) {
return []byte{}, fmt.Errorf("failed to http get url with StatusCode: %d", resp.StatusCode)
}

return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func (d *deployer) prepareCustomConfig() ([]byte, error) {
Expand Down Expand Up @@ -343,7 +343,7 @@ func (d *deployer) getAKSKubeconfig() error {
if err := os.MkdirAll(defaultKubeconfigDir, os.ModePerm); err != nil {
return fmt.Errorf("failed to mkdir the default kubeconfig dir: %v", err)
}
if err := ioutil.WriteFile(destPath, kubeconfig.Value, 0666); err != nil {
if err := os.WriteFile(destPath, kubeconfig.Value, 0666); err != nil {
return fmt.Errorf("failed to write kubeconfig to %s", destPath)
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/azureclients/armclient/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"encoding/json"
"fmt"
"html"
"io/ioutil"
"io"
"net/http"
"net/http/httputil"
"strings"
Expand Down Expand Up @@ -114,9 +114,9 @@ func DoHackRegionalRetryForGET(c *Client) autorest.SendDecorator {
return response, rerr
}

bodyBytes, _ := ioutil.ReadAll(response.Body)
bodyBytes, _ := io.ReadAll(response.Body)
defer func() {
response.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
response.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
}()

bodyString := string(bodyBytes)
Expand Down Expand Up @@ -177,9 +177,9 @@ func DoHackRegionalRetryForGET(c *Client) autorest.SendDecorator {
}

// Do the same check on regional response just like the global one
bodyBytes, _ = ioutil.ReadAll(regionalResponse.Body)
bodyBytes, _ = io.ReadAll(regionalResponse.Body)
defer func() {
regionalResponse.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
regionalResponse.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
}()
bodyString = string(bodyBytes)
trimmed = strings.TrimSpace(bodyString)
Expand Down
10 changes: 5 additions & 5 deletions pkg/azureclients/blobclient/azure_blobclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"
"time"
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestCreateContainer(t *testing.T) {
armClient := mockarmclient.NewMockInterface(ctrl)
response := &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
Body: io.NopCloser(bytes.NewReader([]byte(""))),
}

armClient.EXPECT().PutResource(gomock.Any(), gomock.Any(), gomock.Any()).Return(response, nil).Times(1)
Expand All @@ -76,7 +76,7 @@ func TestCreateContainer(t *testing.T) {
// test throttle error from server
response = &http.Response{
StatusCode: http.StatusTooManyRequests,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
}
throttleErr := &retry.Error{
HTTPStatusCode: http.StatusTooManyRequests,
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestGetContainer(t *testing.T) {

response := &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
Body: io.NopCloser(bytes.NewReader([]byte(""))),
}

armClient := mockarmclient.NewMockInterface(ctrl)
Expand All @@ -178,7 +178,7 @@ func TestGetContainer(t *testing.T) {
// test throttle error from server
response = &http.Response{
StatusCode: http.StatusTooManyRequests,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
}
throttleErr := &retry.Error{
HTTPStatusCode: http.StatusTooManyRequests,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"
"time"
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestGet(t *testing.T) {

response := &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
}

armClient := mockarmclient.NewMockInterface(ctrl)
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestGetThrottle(t *testing.T) {

response := &http.Response{
StatusCode: http.StatusTooManyRequests,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
}
throttleErr := &retry.Error{
HTTPStatusCode: http.StatusTooManyRequests,
Expand All @@ -194,7 +194,7 @@ func TestGetNotFound(t *testing.T) {

response := &http.Response{
StatusCode: http.StatusNotFound,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
}
armClient := mockarmclient.NewMockInterface(ctrl)
armClient.EXPECT().GetResource(gomock.Any(), testResourceID).Return(response, nil).Times(1)
Expand All @@ -214,7 +214,7 @@ func TestGetInternalError(t *testing.T) {

response := &http.Response{
StatusCode: http.StatusInternalServerError,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
}
armClient := mockarmclient.NewMockInterface(ctrl)
armClient.EXPECT().GetResource(gomock.Any(), testResourceID).Return(response, nil).Times(1)
Expand All @@ -239,7 +239,7 @@ func TestList(t *testing.T) {
armClient.EXPECT().GetResource(gomock.Any(), testResourcePrefix).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(responseBody)),
Body: io.NopCloser(bytes.NewReader(responseBody)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(1)

Expand Down Expand Up @@ -283,7 +283,7 @@ func TestListNextResultsMultiPages(t *testing.T) {
if test.prepareErr == nil {
armClient.EXPECT().Send(gomock.Any(), req).Return(&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"foo":"bar"}`))),
Body: io.NopCloser(bytes.NewReader([]byte(`{"foo":"bar"}`))),
}, test.sendErr)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any())
}
Expand Down Expand Up @@ -327,14 +327,14 @@ func TestListNextResultsMultiPagesWithListResponderError(t *testing.T) {
if test.prepareErr == nil {
armClient.EXPECT().Send(gomock.Any(), req).Return(&http.Response{
StatusCode: http.StatusNotFound,
Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"foo":"bar"}`))),
Body: io.NopCloser(bytes.NewReader([]byte(`{"foo":"bar"}`))),
}, test.sendErr)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any())
}

response := &http.Response{
StatusCode: http.StatusNotFound,
Body: ioutil.NopCloser(bytes.NewBuffer([]byte(`{"foo":"bar"}`))),
Body: io.NopCloser(bytes.NewBuffer([]byte(`{"foo":"bar"}`))),
}
expected := containerservice.ManagedClusterListResult{}
expected.Response = autorest.Response{Response: response}
Expand All @@ -355,7 +355,7 @@ func TestListWithListResponderError(t *testing.T) {
armClient.EXPECT().GetResource(gomock.Any(), testResourcePrefix).Return(
&http.Response{
StatusCode: http.StatusNotFound,
Body: ioutil.NopCloser(bytes.NewReader(responseBody)),
Body: io.NopCloser(bytes.NewReader(responseBody)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(1)
mcClient := getTestManagedClusterClient(armClient)
Expand All @@ -377,7 +377,7 @@ func TestListWithNextPage(t *testing.T) {
armClient.EXPECT().GetResource(gomock.Any(), testResourcePrefix).Return(
&http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader(responseBody)),
Body: io.NopCloser(bytes.NewReader(responseBody)),
}, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(1)
mcClient := getTestManagedClusterClient(armClient)
Expand Down Expand Up @@ -427,7 +427,7 @@ func TestListThrottle(t *testing.T) {

response := &http.Response{
StatusCode: http.StatusTooManyRequests,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
}
throttleErr := &retry.Error{
HTTPStatusCode: http.StatusTooManyRequests,
Expand All @@ -454,7 +454,7 @@ func TestCreateOrUpdate(t *testing.T) {
armClient := mockarmclient.NewMockInterface(ctrl)
response := &http.Response{
StatusCode: http.StatusOK,
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
Body: io.NopCloser(bytes.NewReader([]byte(""))),
}
armClient.EXPECT().PutResource(gomock.Any(), pointer.StringDeref(mc.ID, ""), mc, gomock.Any()).Return(response, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(1)
Expand All @@ -471,7 +471,7 @@ func TestCreateOrUpdateWithCreateOrUpdateResponderError(t *testing.T) {
armClient := mockarmclient.NewMockInterface(ctrl)
response := &http.Response{
StatusCode: http.StatusNotFound,
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),
Body: io.NopCloser(bytes.NewReader([]byte(""))),
}
armClient.EXPECT().PutResource(gomock.Any(), pointer.StringDeref(mc.ID, ""), mc, gomock.Any()).Return(response, nil).Times(1)
armClient.EXPECT().CloseResponse(gomock.Any(), gomock.Any()).Times(1)
Expand Down Expand Up @@ -524,7 +524,7 @@ func TestCreateOrUpdateThrottle(t *testing.T) {

response := &http.Response{
StatusCode: http.StatusTooManyRequests,
Body: ioutil.NopCloser(bytes.NewReader([]byte("{}"))),
Body: io.NopCloser(bytes.NewReader([]byte("{}"))),
}
throttleErr := &retry.Error{
HTTPStatusCode: http.StatusTooManyRequests,
Expand Down
Loading

0 comments on commit 3ea02d9

Please sign in to comment.