diff --git a/pkg/cmd/dockerregistry/dockerregistry.go b/pkg/cmd/dockerregistry/dockerregistry.go index aab41b159f..82b046c3e9 100644 --- a/pkg/cmd/dockerregistry/dockerregistry.go +++ b/pkg/cmd/dockerregistry/dockerregistry.go @@ -7,7 +7,6 @@ import ( "flag" "fmt" "io" - "io/ioutil" "net/http" "os" "os/signal" @@ -252,7 +251,7 @@ func NewServer(ctx context.Context, dockerConfig *configuration.Configuration, e pool := x509.NewCertPool() for _, ca := range dockerConfig.HTTP.TLS.ClientCAs { - caPem, err := ioutil.ReadFile(ca) + caPem, err := os.ReadFile(ca) if err != nil { return nil, err } diff --git a/pkg/dockerregistry/server/blobdescriptorservice_test.go b/pkg/dockerregistry/server/blobdescriptorservice_test.go index e001fa2464..e90413b416 100644 --- a/pkg/dockerregistry/server/blobdescriptorservice_test.go +++ b/pkg/dockerregistry/server/blobdescriptorservice_test.go @@ -3,7 +3,7 @@ package server import ( "context" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -150,7 +150,7 @@ func TestBlobDescriptorServiceIsApplied(t *testing.T) { } if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted { - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { t.Errorf("[%s] failed to read body: %v", tc.name, err) } else if len(content) > 0 { diff --git a/pkg/dockerregistry/server/configuration/configuration.go b/pkg/dockerregistry/server/configuration/configuration.go index 08d230561d..84336137e3 100644 --- a/pkg/dockerregistry/server/configuration/configuration.go +++ b/pkg/dockerregistry/server/configuration/configuration.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/url" "os" "reflect" @@ -181,7 +180,7 @@ type versionInfo struct { // openshift specific configuration. // Environment variables may be used to override configuration parameters. func Parse(rd io.Reader) (*configuration.Configuration, *Configuration, error) { - in, err := ioutil.ReadAll(rd) + in, err := io.ReadAll(rd) if err != nil { return nil, nil, err } diff --git a/pkg/dockerregistry/server/signaturedispatcher.go b/pkg/dockerregistry/server/signaturedispatcher.go index d548ed6598..2f4ef0f796 100644 --- a/pkg/dockerregistry/server/signaturedispatcher.go +++ b/pkg/dockerregistry/server/signaturedispatcher.go @@ -5,7 +5,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" kapierrors "k8s.io/apimachinery/pkg/api/errors" @@ -100,7 +100,7 @@ func (s *signatureHandler) Put(w http.ResponseWriter, r *http.Request) { } sig := signature{} - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { s.handleError(s.ctx, ErrorCodeSignatureInvalid.WithDetail(err.Error()), w) return diff --git a/pkg/dockerregistry/server/signaturedispatcher_test.go b/pkg/dockerregistry/server/signaturedispatcher_test.go index f3d8e89589..64392a7e52 100644 --- a/pkg/dockerregistry/server/signaturedispatcher_test.go +++ b/pkg/dockerregistry/server/signaturedispatcher_test.go @@ -5,7 +5,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/http/httptest" "net/url" @@ -116,7 +116,7 @@ func TestSignatureGet(t *testing.T) { t.Fatalf("unexpected response status: %v", resp.StatusCode) } - content, err := ioutil.ReadAll(resp.Body) + content, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("failed to read body: %v", err) } diff --git a/pkg/dockerregistry/server/util_test.go b/pkg/dockerregistry/server/util_test.go index 7013f6eba8..e95c014e90 100644 --- a/pkg/dockerregistry/server/util_test.go +++ b/pkg/dockerregistry/server/util_test.go @@ -2,7 +2,6 @@ package server import ( "context" - "io/ioutil" "net/http" "os" "testing" @@ -31,7 +30,7 @@ func Test_getImportContext(t *testing.T) { icsp := operatorfake.NewSimpleClientset().OperatorV1alpha1().ImageContentSourcePolicies() idms := cfgfake.NewSimpleClientset().ConfigV1().ImageDigestMirrorSets() itms := cfgfake.NewSimpleClientset().ConfigV1().ImageTagMirrorSets() - tmpCredDir, err := ioutil.TempDir("", "credentials") + tmpCredDir, err := os.MkdirTemp("", "credentials") if err != nil { t.Fatalf("error creating temp dir: %v", err) } @@ -129,7 +128,7 @@ func Test_getImportContext(t *testing.T) { } if len(tt.creds) > 0 { - if err := ioutil.WriteFile( + if err := os.WriteFile( tmpCredDir+"/config.json", tt.creds, 0644, ); err != nil { t.Errorf("error writing config.json: %v", err) diff --git a/pkg/kubernetes-common/credentialprovider/config.go b/pkg/kubernetes-common/credentialprovider/config.go index b56c69c9d2..f900537ec7 100644 --- a/pkg/kubernetes-common/credentialprovider/config.go +++ b/pkg/kubernetes-common/credentialprovider/config.go @@ -20,7 +20,7 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "path/filepath" @@ -99,7 +99,7 @@ func ReadDockercfgFile(searchPaths []string) (cfg DockerConfig, err error) { continue } klog.V(4).Infof("looking for .dockercfg at %s", absDockerConfigFileLocation) - contents, err := ioutil.ReadFile(absDockerConfigFileLocation) + contents, err := os.ReadFile(absDockerConfigFileLocation) if os.IsNotExist(err) { continue } @@ -147,7 +147,7 @@ func ReadDockerConfigJSONFile(searchPaths []string) (cfg DockerConfig, err error func ReadSpecificDockerConfigJsonFile(filePath string) (cfg DockerConfig, err error) { var contents []byte - if contents, err = ioutil.ReadFile(filePath); err != nil { + if contents, err = os.ReadFile(filePath); err != nil { return nil, err } return readDockerConfigJsonFileFromBytes(contents) @@ -195,7 +195,7 @@ func ReadUrl(url string, client *http.Client, header *http.Header) (body []byte, } } - contents, err := ioutil.ReadAll(resp.Body) + contents, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/pkg/kubernetes-common/credentialprovider/config_test.go b/pkg/kubernetes-common/credentialprovider/config_test.go index 418368c908..ed3b7cbd2e 100644 --- a/pkg/kubernetes-common/credentialprovider/config_test.go +++ b/pkg/kubernetes-common/credentialprovider/config_test.go @@ -18,7 +18,6 @@ package credentialprovider import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "reflect" @@ -32,7 +31,7 @@ func TestReadDockerConfigFile(t *testing.T) { //test dockerconfig json inputDockerconfigJsonFile := "{ \"auths\": { \"http://foo.example.com\":{\"auth\":\"Zm9vOmJhcgo=\",\"email\":\"foo@example.com\"}}}" - preferredPath, err := ioutil.TempDir("", "test_foo_bar_dockerconfigjson_") + preferredPath, err := os.MkdirTemp("", "test_foo_bar_dockerconfigjson_") if err != nil { t.Fatalf("Creating tmp dir fail: %v", err) return diff --git a/pkg/origin-common/clientcmd/clientcmd.go b/pkg/origin-common/clientcmd/clientcmd.go index bf2835e568..c5d5c06262 100644 --- a/pkg/origin-common/clientcmd/clientcmd.go +++ b/pkg/origin-common/clientcmd/clientcmd.go @@ -2,7 +2,6 @@ package clientcmd import ( "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -146,7 +145,7 @@ func (cfg *Config) bindEnv() error { cfg.CommonConfig.BearerToken = value } if value, ok := getEnv("BEARER_TOKEN_FILE"); ok && len(cfg.CommonConfig.BearerToken) == 0 { - if tokenData, tokenErr := ioutil.ReadFile(value); tokenErr == nil { + if tokenData, tokenErr := os.ReadFile(value); tokenErr == nil { cfg.CommonConfig.BearerToken = strings.TrimSpace(string(tokenData)) if len(cfg.CommonConfig.BearerToken) == 0 { err = fmt.Errorf("BEARER_TOKEN_FILE %q was empty", value) diff --git a/pkg/testframework/registry.go b/pkg/testframework/registry.go index ccb0b1a52a..8d853c171f 100644 --- a/pkg/testframework/registry.go +++ b/pkg/testframework/registry.go @@ -6,7 +6,7 @@ import ( "crypto/tls" "encoding/json" "fmt" - "io/ioutil" + "io" "net" "net/http" "sync/atomic" @@ -535,7 +535,7 @@ func checkRoute(host string) error { // if deployed registry leverages basic authentication a StatusUnauthorized will // be returned so we consider this status as valid as well. if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusUnauthorized { - dt, err := ioutil.ReadAll(res.Body) + dt, err := io.ReadAll(res.Body) if err != nil { return err } diff --git a/pkg/testutil/logrus.go b/pkg/testutil/logrus.go index e0a6579072..a1f14e8769 100644 --- a/pkg/testutil/logrus.go +++ b/pkg/testutil/logrus.go @@ -2,7 +2,7 @@ package testutil import ( "context" - "io/ioutil" + "io" "strings" "testing" @@ -35,7 +35,7 @@ func (h *logrusHook) Fire(e *logrus.Entry) error { func WithTestLogger(parent context.Context, t *testing.T) context.Context { log := logrus.New() log.Level = logrus.DebugLevel - log.Out = ioutil.Discard + log.Out = io.Discard log.Hooks.Add(&logrusHook{t: t}) return dcontext.WithLogger(parent, logrus.NewEntry(log)) } diff --git a/test/integration/imagelayers/imagelayers_test.go b/test/integration/imagelayers/imagelayers_test.go index 18461d3fd5..3a411a33eb 100644 --- a/test/integration/imagelayers/imagelayers_test.go +++ b/test/integration/imagelayers/imagelayers_test.go @@ -2,7 +2,7 @@ package integration import ( "fmt" - "io/ioutil" + "io" "net/http" "testing" @@ -35,7 +35,7 @@ func getSchema1Manifest(repo *testframework.Repository, tag string) (distributio return nil, fmt.Errorf("get manifest %s:%s: %s", repo.RepoName(), tag, resp.Status) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("read manifest %s:%s: %v", repo.RepoName(), tag, err) } diff --git a/test/integration/pullthrough/pullthrough_test.go b/test/integration/pullthrough/pullthrough_test.go index ce5283e827..0776b86269 100644 --- a/test/integration/pullthrough/pullthrough_test.go +++ b/test/integration/pullthrough/pullthrough_test.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "testing" "time" @@ -45,7 +45,7 @@ func testPullThroughGetManifest(baseURL string, stream *imageapiv1.ImageStreamIm return fmt.Errorf("unexpected status code: %d", resp.StatusCode) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("error reading manifest: %v", err) } diff --git a/test/integration/v2/v2_docker_registry_test.go b/test/integration/v2/v2_docker_registry_test.go index 845f1de1f8..6fce88e083 100644 --- a/test/integration/v2/v2_docker_registry_test.go +++ b/test/integration/v2/v2_docker_registry_test.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "strings" "testing" @@ -158,7 +158,7 @@ func TestV2RegistryGetTags(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Fatalf("unexpected status code: %d", resp.StatusCode) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { t.Fatalf("error retrieving manifest: %v", err) } @@ -188,7 +188,7 @@ func TestV2RegistryGetTags(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Fatalf("unexpected status code: %d", resp.StatusCode) } - body, err = ioutil.ReadAll(resp.Body) + body, err = io.ReadAll(resp.Body) if err != nil { t.Fatalf("error retrieving manifest: %v", err) } @@ -347,7 +347,7 @@ func getTags(baseURL, namespace, streamName, user, token string) ([]string, erro if resp.StatusCode != http.StatusOK { return []string{}, fmt.Errorf("unexpected status code: %d", resp.StatusCode) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return []string{}, fmt.Errorf("error retrieving manifest: %v", err) } @@ -387,7 +387,7 @@ func ping(baseURL, user, token string) error { if resp.StatusCode != http.StatusOK { return fmt.Errorf("unexpected status code: %d", resp.StatusCode) } - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("error retrieving manifest: %v", err) } diff --git a/tools/import-verifier/import-verifier.go b/tools/import-verifier/import-verifier.go index a8f1a9a408..2f07cbd65a 100644 --- a/tools/import-verifier/import-verifier.go +++ b/tools/import-verifier/import-verifier.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -303,7 +302,7 @@ func mergePackages(existingPackages, currPackages []Package) []Package { } func loadImportRestrictions(configFile string) ([]ImportRestriction, error) { - config, err := ioutil.ReadFile(configFile) + config, err := os.ReadFile(configFile) if err != nil { return nil, fmt.Errorf("failed to load configuration from %s: %v", configFile, err) }