From c1dab952d550a8988a3a4c7a1b7a7e29e6157e17 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Thu, 28 Dec 2023 19:34:25 -0500 Subject: [PATCH] Replace deprecated `ioutil` package --- pkg/mapper/configmap/yaml_test.go | 4 ++-- pkg/server/server_test.go | 6 +++--- pkg/token/filecache.go | 12 ++++++------ pkg/token/token.go | 4 ++-- pkg/token/token_test.go | 5 ++--- tests/e2e/apiserver_test.go | 4 ++-- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/pkg/mapper/configmap/yaml_test.go b/pkg/mapper/configmap/yaml_test.go index 81222b4fc..d1792fb42 100644 --- a/pkg/mapper/configmap/yaml_test.go +++ b/pkg/mapper/configmap/yaml_test.go @@ -2,7 +2,7 @@ package configmap import ( "context" - "io/ioutil" + "os" "path" "reflect" "strings" @@ -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 } diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index bc78e0292..3e10ab66b 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "errors" - "io/ioutil" + "io" "net/http" "net/http/httptest" "reflect" @@ -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") } @@ -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.") } diff --git a/pkg/token/filecache.go b/pkg/token/filecache.go index f1e893c2f..e1a0c2a84 100644 --- a/pkg/token/filecache.go +++ b/pkg/token/filecache.go @@ -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 @@ -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 { diff --git a/pkg/token/token.go b/pkg/token/token.go index 769419312..16ab8d92b 100644 --- a/pkg/token/token.go +++ b/pkg/token/token.go @@ -20,7 +20,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -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)) } diff --git a/pkg/token/token_test.go b/pkg/token/token_test.go index faa2aefd7..a8e997c86 100644 --- a/pkg/token/token_test.go +++ b/pkg/token/token_test.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "os" @@ -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{ @@ -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") diff --git a/tests/e2e/apiserver_test.go b/tests/e2e/apiserver_test.go index c1522f7ea..22baba99f 100644 --- a/tests/e2e/apiserver_test.go +++ b/tests/e2e/apiserver_test.go @@ -21,7 +21,7 @@ import ( "time" "bytes" - "io/ioutil" + yamlutil "k8s.io/apimachinery/pkg/util/yaml" . "github.com/onsi/ginkgo/v2" @@ -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)