diff --git a/pkg/build/gobuild.go b/pkg/build/gobuild.go index f289e6cf85..0ee13a67ff 100644 --- a/pkg/build/gobuild.go +++ b/pkg/build/gobuild.go @@ -22,7 +22,6 @@ import ( "fmt" gb "go/build" "io" - "io/ioutil" "log" "os" "os/exec" @@ -288,7 +287,7 @@ func build(ctx context.Context, ip string, dir string, platform v1.Platform, con return "", fmt.Errorf("creating KOCACHE bin dir: %w", err) } } else { - tmpDir, err = ioutil.TempDir("", "ko") + tmpDir, err = os.MkdirTemp("", "ko") if err != nil { return "", err } @@ -846,7 +845,7 @@ func (g *gobuild) buildOne(ctx context.Context, refStr string, base v1.Image, pl } dataLayerBytes := dataLayerBuf.Bytes() dataLayer, err := tarball.LayerFromOpener(func() (io.ReadCloser, error) { - return ioutil.NopCloser(bytes.NewBuffer(dataLayerBytes)), nil + return io.NopCloser(bytes.NewBuffer(dataLayerBytes)), nil }, tarball.WithCompressedCaching, tarball.WithMediaType(layerMediaType)) if err != nil { return nil, err @@ -957,7 +956,7 @@ func buildLayer(appPath, file string, platform *v1.Platform, layerMediaType type } binaryLayerBytes := binaryLayerBuf.Bytes() return tarball.LayerFromOpener(func() (io.ReadCloser, error) { - return ioutil.NopCloser(bytes.NewBuffer(binaryLayerBytes)), nil + return io.NopCloser(bytes.NewBuffer(binaryLayerBytes)), nil }, tarball.WithCompressedCaching, tarball.WithEstargzOptions(estargz.WithPrioritizedFiles([]string{ // When using estargz, prioritize downloading the binary entrypoint. appPath, diff --git a/pkg/build/gobuild_test.go b/pkg/build/gobuild_test.go index c77a122bad..923a9bd3d2 100644 --- a/pkg/build/gobuild_test.go +++ b/pkg/build/gobuild_test.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -403,12 +402,12 @@ func fauxSBOM(context.Context, string, string, string, oci.SignedEntity, string) // A helper method we use to substitute for the default "build" method. func writeTempFile(_ context.Context, s string, _ string, _ v1.Platform, _ Config) (string, error) { - tmpDir, err := ioutil.TempDir("", "ko") + tmpDir, err := os.MkdirTemp("", "ko") if err != nil { return "", err } - file, err := ioutil.TempFile(tmpDir, "out") + file, err := os.CreateTemp(tmpDir, "out") if err != nil { return "", err } @@ -573,7 +572,7 @@ func validateImage(t *testing.T, img oci.SignedImage, baseLayers int64, creation continue } found = true - body, err := ioutil.ReadAll(tr) + body, err := io.ReadAll(tr) if err != nil { t.Errorf("ReadAll() = %v", err) } else if want, got := "Hello there\n", string(body); got != want { diff --git a/pkg/commands/config.go b/pkg/commands/config.go index acf8dce167..142c2d40f2 100644 --- a/pkg/commands/config.go +++ b/pkg/commands/config.go @@ -17,7 +17,7 @@ package commands import ( "context" "fmt" - "io/ioutil" + "io" "log" "os" "strconv" @@ -41,7 +41,7 @@ import ( ) var ( - amazonKeychain authn.Keychain = authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(ioutil.Discard))) + amazonKeychain authn.Keychain = authn.NewKeychainFromHelper(ecr.NewECRHelper(ecr.WithLogger(io.Discard))) azureKeychain authn.Keychain = authn.NewKeychainFromHelper(credhelper.NewACRCredentialsHelper()) keychain = authn.NewMultiKeychain( amazonKeychain, diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index b9dc43414d..8a348f0e24 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "path" "strings" @@ -423,9 +422,9 @@ func resolveFile( } if f == "-" { - b, err = ioutil.ReadAll(os.Stdin) + b, err = io.ReadAll(os.Stdin) } else { - b, err = ioutil.ReadFile(f) + b, err = os.ReadFile(f) } if err != nil { return nil, err diff --git a/pkg/commands/resolver_test.go b/pkg/commands/resolver_test.go index 6586c40232..af615af3a5 100644 --- a/pkg/commands/resolver_test.go +++ b/pkg/commands/resolver_test.go @@ -20,9 +20,9 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "net/http/httptest" + "os" "path" "strings" "testing" @@ -317,7 +317,7 @@ func TestNewPublisherCanPublish(t *testing.T) { // The registry uses a NOP logger to avoid spamming test logs. // Remember to call `defer Close()` on the returned `httptest.Server`. func registryServerWithImage(namespace string) (*httptest.Server, error) { - nopLog := log.New(ioutil.Discard, "", 0) + nopLog := log.New(io.Discard, "", 0) r := registry.New(registry.Logger(nopLog)) s := httptest.NewServer(r) imageName := fmt.Sprintf("%s/%s", s.Listener.Addr().String(), namespace) @@ -356,7 +356,7 @@ func mustRandom() v1.Image { func yamlToTmpFile(t *testing.T, yaml []byte) string { t.Helper() - tmpfile, err := ioutil.TempFile("", "doc") + tmpfile, err := os.CreateTemp("", "doc") if err != nil { t.Fatalf("error creating temp file: %v", err) } diff --git a/pkg/internal/testing/daemon.go b/pkg/internal/testing/daemon.go index ab1152e68a..74c8f03fd1 100644 --- a/pkg/internal/testing/daemon.go +++ b/pkg/internal/testing/daemon.go @@ -17,7 +17,6 @@ package testing import ( "context" "io" - "io/ioutil" "strings" "github.com/docker/docker/api/types" @@ -32,7 +31,7 @@ type MockDaemon struct { func (m *MockDaemon) NegotiateAPIVersion(context.Context) {} func (m *MockDaemon) ImageLoad(context.Context, io.Reader, bool) (types.ImageLoadResponse, error) { return types.ImageLoadResponse{ - Body: ioutil.NopCloser(strings.NewReader("Loaded")), + Body: io.NopCloser(strings.NewReader("Loaded")), }, nil } diff --git a/pkg/publish/kind/write_test.go b/pkg/publish/kind/write_test.go index 27ea8c7682..865d48f0e9 100644 --- a/pkg/publish/kind/write_test.go +++ b/pkg/publish/kind/write_test.go @@ -19,7 +19,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "strings" "testing" @@ -203,7 +202,7 @@ type fakeCmd struct { func (f *fakeCmd) Run() error { if f.stdin != nil { // Consume the entire stdin to move the image publish forward. - ioutil.ReadAll(f.stdin) + io.ReadAll(f.stdin) } return f.err } diff --git a/pkg/publish/layout_test.go b/pkg/publish/layout_test.go index cb919c7d9b..2942746b04 100644 --- a/pkg/publish/layout_test.go +++ b/pkg/publish/layout_test.go @@ -16,7 +16,6 @@ package publish import ( "context" - "io/ioutil" "os" "strings" "testing" @@ -31,7 +30,7 @@ func TestLayout(t *testing.T) { } importpath := "github.com/Google/go-containerregistry/cmd/crane" - tmp, err := ioutil.TempDir("/tmp", "ko") + tmp, err := os.MkdirTemp("/tmp", "ko") if err != nil { t.Fatal(err) } diff --git a/pkg/publish/multi_test.go b/pkg/publish/multi_test.go index 3c4de02677..b21870f50f 100644 --- a/pkg/publish/multi_test.go +++ b/pkg/publish/multi_test.go @@ -17,7 +17,6 @@ package publish_test import ( "context" "fmt" - "io/ioutil" "os" "testing" @@ -34,7 +33,7 @@ func TestMulti(t *testing.T) { repoName := fmt.Sprintf("%s/%s", "example.com", base) importpath := "github.com/Google/go-containerregistry/cmd/crane" - fp, err := ioutil.TempFile("", "") + fp, err := os.CreateTemp("", "") if err != nil { t.Fatal(err) } @@ -43,7 +42,7 @@ func TestMulti(t *testing.T) { tp := publish.NewTarball(fp.Name(), repoName, md5Hash, []string{}) - tmp, err := ioutil.TempDir("/tmp", "ko") + tmp, err := os.MkdirTemp("/tmp", "ko") if err != nil { t.Fatal(err) } diff --git a/pkg/publish/tarball_test.go b/pkg/publish/tarball_test.go index c17e105939..8a0854ef70 100644 --- a/pkg/publish/tarball_test.go +++ b/pkg/publish/tarball_test.go @@ -17,7 +17,6 @@ package publish_test import ( "context" "fmt" - "io/ioutil" "os" "strings" "testing" @@ -35,7 +34,7 @@ func TestTarball(t *testing.T) { base := "blah" importpath := "github.com/Google/go-containerregistry/cmd/crane" - fp, err := ioutil.TempFile("", "") + fp, err := os.CreateTemp("", "") if err != nil { t.Fatal(err) } diff --git a/test/main.go b/test/main.go index 010855b3f4..aa4d6b43a1 100644 --- a/test/main.go +++ b/test/main.go @@ -17,7 +17,6 @@ package main import ( "flag" "fmt" - "io/ioutil" "log" "os" "os/signal" @@ -63,7 +62,7 @@ func main() { dp := os.Getenv("KO_DATA_PATH") file := filepath.Join(dp, *f) - bytes, err := ioutil.ReadFile(file) + bytes, err := os.ReadFile(file) if err != nil { log.Fatalf("Error reading %q: %v", file, err) }