Skip to content

Commit

Permalink
Replace deprecated ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
bryantbiggs authored and sushanth0910 committed Nov 13, 2024
1 parent dbe9573 commit c1dab95
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 @@ -570,7 +570,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 @@ -87,7 +86,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 @@ -246,7 +245,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 All @@ -47,7 +47,7 @@ var _ = SIGDescribe("apiserver", framework.WithDisruptive(), func() {
BeforeEach(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 c1dab95

Please sign in to comment.