Skip to content

Commit

Permalink
Merge pull request #681 from bryantbiggs/chore/replace-deprecated-ioutil
Browse files Browse the repository at this point in the history
Replace deprecated `ioutil` package
  • Loading branch information
k8s-ci-robot committed Jan 3, 2024
2 parents b780ec3 + 7eee688 commit 6c197ae
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pkg/mapper/configmap/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package configmap

import (
"context"
"io/ioutil"
"os"
"path"
"reflect"
"strings"
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestConfigMap(t *testing.T) {

func configMapFromYaml(fileName string) (*v1.ConfigMap, error) {
var cm v1.ConfigMap
data, err := ioutil.ReadFile(path.Join("./yaml/", fileName))
data, err := os.ReadFile(path.Join("./yaml/", fileName))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"reflect"
Expand All @@ -27,7 +27,7 @@ import (

func verifyBodyContains(t *testing.T, resp *httptest.ResponseRecorder, s string) {
t.Helper()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Failed to read body from ResponseRecorder, this should not happen")
}
Expand All @@ -38,7 +38,7 @@ func verifyBodyContains(t *testing.T, resp *httptest.ResponseRecorder, s string)

func verifyAuthResult(t *testing.T, resp *httptest.ResponseRecorder, expected authenticationv1beta1.TokenReview) {
t.Helper()
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("Failed to read body from ResponseRecorder, this should not happen.")
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/token/filecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"context"
"errors"
"fmt"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/gofrs/flock"
"gopkg.in/yaml.v2"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"time"

"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/gofrs/flock"
"gopkg.in/yaml.v2"
)

// env variable name for custom credential cache file location
Expand All @@ -36,11 +36,11 @@ func (osFS) Stat(filename string) (os.FileInfo, error) {
}

func (osFS) ReadFile(filename string) ([]byte, error) {
return ioutil.ReadFile(filename)
return os.ReadFile(filename)
}

func (osFS) WriteFile(filename string, data []byte, perm os.FileMode) error {
return ioutil.WriteFile(filename, data, perm)
return os.WriteFile(filename, data, perm)
}

func (osFS) MkdirAll(path string, perm os.FileMode) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -577,7 +577,7 @@ func (v tokenVerifier) Verify(token string) (*Identity, error) {
}
defer response.Body.Close()

responseBody, err := ioutil.ReadAll(response.Body)
responseBody, err := io.ReadAll(response.Body)
if err != nil {
return nil, NewSTSError(fmt.Sprintf("error reading HTTP result: %v", err))
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -82,7 +81,7 @@ func toToken(url string) string {
func newVerifier(partition string, statusCode int, body string, err error) Verifier {
var rc io.ReadCloser
if body != "" {
rc = ioutil.NopCloser(bytes.NewReader([]byte(body)))
rc = io.NopCloser(bytes.NewReader([]byte(body)))
}
return tokenVerifier{
client: &http.Client{
Expand Down Expand Up @@ -241,7 +240,7 @@ func TestVerifyNoRedirectsFollowed(t *testing.T) {
}
defer resp.Body.Close()
if resp.Header.Get("Location") != ts2.URL && resp.StatusCode != http.StatusFound {
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
fmt.Printf("%#v\n", resp)
fmt.Println(string(body))
t.Error("Unexpectedly followed redirect")
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"bytes"
"io/ioutil"

yamlutil "k8s.io/apimachinery/pkg/util/yaml"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -54,7 +54,7 @@ var _ = Describe("[apiserver] [Disruptive] the apiserver", func() {

jobPath := filepath.Join(os.Getenv("BASE_DIR"), "apiserver-restart.yaml")

b, _ := ioutil.ReadFile(jobPath)
b, _ := os.ReadFile(jobPath)
decoder := yamlutil.NewYAMLOrJSONDecoder(bytes.NewReader(b), 100)
jobSpec := &batchv1.Job{}
_ = decoder.Decode(&jobSpec)
Expand Down

0 comments on commit 6c197ae

Please sign in to comment.