diff --git a/cmd/coreos-assembler.go b/cmd/coreos-assembler.go index 4abd005af4895fb50ec338d738b748811c696ca0..1e2ffe7d8c89af72928334aa8469348d60df6ef1 100644 --- a/cmd/coreos-assembler.go +++ b/cmd/coreos-assembler.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "os" "os/exec" "sort" @@ -160,8 +160,8 @@ func initializeGlobalState(argv []string) error { // This was taken from 'Support Arbitrary User IDs' section of: // https://docs.openshift.com/container-platform/3.10/creating_images/guidelines.html c := exec.Command("whoami") - c.Stdout = ioutil.Discard - c.Stderr = ioutil.Discard + c.Stdout = io.Discard + c.Stderr = io.Discard if err := c.Run(); err != nil { fmt.Fprintln(os.Stderr, "notice: failed to look up uid in /etc/passwd; enabling workaround") home := fmt.Sprintf("/var/tmp/%s", user) diff --git a/mantle/auth/azure.go b/mantle/auth/azure.go index c6023c52ea54acf240753428eca273155a8201e5..1da3e3a1c069acf7f32413ccbad0e908b12a1953 100644 --- a/mantle/auth/azure.go +++ b/mantle/auth/azure.go @@ -17,7 +17,7 @@ package auth import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" "os/user" "path/filepath" @@ -150,5 +150,5 @@ func decodeBOMFile(path string) ([]byte, error) { defer f.Close() decoder := unicode.UTF8.NewDecoder() reader := transform.NewReader(f, unicode.BOMOverride(decoder)) - return ioutil.ReadAll(reader) + return io.ReadAll(reader) } diff --git a/mantle/auth/google.go b/mantle/auth/google.go index c36fccb23c05dafdb3ccf8337e3b126310c06c0d..767ec9c2fe01b566e0c497b13089242cd98f5fd8 100644 --- a/mantle/auth/google.go +++ b/mantle/auth/google.go @@ -17,8 +17,8 @@ package auth import ( "context" - "io/ioutil" "net/http" + "os" "os/user" "path/filepath" @@ -58,7 +58,7 @@ func GoogleClientFromKeyFile(path string, scope ...string) (*http.Client, error) } path = filepath.Join(user.HomeDir, GCEConfigPath) } - b, err := ioutil.ReadFile(path) + b, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/mantle/cmd/kola/console.go b/mantle/cmd/kola/console.go index 9c542bfba05341c2cb8275ac7478e865bdff54f3..9073dd944a9af8f4706563048c104243bbf05ef5 100644 --- a/mantle/cmd/kola/console.go +++ b/mantle/cmd/kola/console.go @@ -17,7 +17,7 @@ package main import ( "errors" "fmt" - "io/ioutil" + "io" "os" "github.com/spf13/cobra" @@ -65,9 +65,9 @@ func runCheckConsole(cmd *cobra.Command, args []string) error { if checkConsoleVerbose { fmt.Printf("Reading input from %s...\n", sourceName) } - console, err = ioutil.ReadAll(os.Stdin) + console, err = io.ReadAll(os.Stdin) } else { - console, err = ioutil.ReadFile(arg) + console, err = os.ReadFile(arg) } if err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) diff --git a/mantle/cmd/kola/devshell.go b/mantle/cmd/kola/devshell.go index 229db5c7790258e6585ac02a430d8c50959c1e44..29309117388b66276e7af47b243cd834b86f6323 100644 --- a/mantle/cmd/kola/devshell.go +++ b/mantle/cmd/kola/devshell.go @@ -21,7 +21,6 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" "os" "os/exec" "os/signal" @@ -72,7 +71,7 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co termMaxWidth = 100 } - tmpd, err := ioutil.TempDir("", "kola-devshell") + tmpd, err := os.MkdirTemp("", "kola-devshell") if err != nil { return err } @@ -109,7 +108,7 @@ func runDevShellSSH(ctx context.Context, builder *platform.QemuBuilder, conf *co if err != nil { return err } - serialLog, err := ioutil.TempFile(tmpd, "cosa-run-serial") + serialLog, err = os.CreateTemp(tmpd, "cosa-run-serial") if err != nil { return err } diff --git a/mantle/cmd/kola/kola.go b/mantle/cmd/kola/kola.go index ec4ce253efc6c2928de2833bc99e2e218c271f1d..e0dc1359428db309ff13cc141c9fa51220c9e5a5 100644 --- a/mantle/cmd/kola/kola.go +++ b/mantle/cmd/kola/kola.go @@ -17,7 +17,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "math/rand" "net/http" "os" @@ -585,7 +584,7 @@ func syncFindParentImageOptions() error { switch kolaPlatform { case "qemu-unpriv": if qemuImageDir == "" { - if qemuImageDir, err = ioutil.TempDir("/var/tmp", "kola-run-upgrade"); err != nil { + if qemuImageDir, err = os.MkdirTemp("/var/tmp", "kola-run-upgrade"); err != nil { return err } qemuImageDirIsTemp = true diff --git a/mantle/cmd/kola/qemuexec.go b/mantle/cmd/kola/qemuexec.go index 0fc1982eb34690869229559909c0400db18f0769..950dd3e1a7fc619a45e56d36705d267d50af9cd4 100644 --- a/mantle/cmd/kola/qemuexec.go +++ b/mantle/cmd/kola/qemuexec.go @@ -19,7 +19,7 @@ package main import ( "context" "fmt" - "io/ioutil" + "os" "path/filepath" "strconv" "strings" @@ -207,7 +207,7 @@ func runQemuExec(cmd *cobra.Command, args []string) error { var config *conf.Conf if butane != "" { - buf, err := ioutil.ReadFile(butane) + buf, err := os.ReadFile(butane) if err != nil { return err } @@ -216,7 +216,7 @@ func runQemuExec(cmd *cobra.Command, args []string) error { return errors.Wrapf(err, "parsing %s", butane) } } else if !directIgnition && ignition != "" { - buf, err := ioutil.ReadFile(ignition) + buf, err := os.ReadFile(ignition) if err != nil { return err } diff --git a/mantle/cmd/kola/spawn.go b/mantle/cmd/kola/spawn.go index 7bffbc87833c73a1b5c059091ecc0f3d28fea58d..26043f5e04ca71befdd57e787df5612f8699eeb7 100644 --- a/mantle/cmd/kola/spawn.go +++ b/mantle/cmd/kola/spawn.go @@ -17,7 +17,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "net" "os" "os/user" @@ -99,7 +98,7 @@ func runSpawn(cmd *cobra.Command, args []string) error { var userdata *conf.UserData if spawnUserData != "" { - userbytes, err := ioutil.ReadFile(spawnUserData) + userbytes, err := os.ReadFile(spawnUserData) if err != nil { return errors.Wrapf(err, "Reading userdata failed") } @@ -167,7 +166,7 @@ func runSpawn(cmd *cobra.Command, args []string) error { DisablePDeathSig: !spawnRemove, } if spawnMachineOptions != "" { - b, err := ioutil.ReadFile(spawnMachineOptions) + b, err := os.ReadFile(spawnMachineOptions) if err != nil { return errors.Wrapf(err, "Could not read machine options") } @@ -272,7 +271,7 @@ func addSSHKeys(userdata *conf.UserData) (*conf.UserData, error) { // read key files, failing if any are missing for _, path := range spawnSSHKeys { - keybytes, err := ioutil.ReadFile(path) + keybytes, err := os.ReadFile(path) if err != nil { return nil, err } diff --git a/mantle/cmd/kola/switchkernel.go b/mantle/cmd/kola/switchkernel.go index c4f06651fdc5ec6faf0572728c21717455ec490e..0fb5b7d5fe7a58f5c69b6ad9a0fbaa51c15f3ff5 100644 --- a/mantle/cmd/kola/switchkernel.go +++ b/mantle/cmd/kola/switchkernel.go @@ -17,7 +17,6 @@ package main import ( "encoding/base64" "fmt" - "io/ioutil" "os" "regexp" "strings" @@ -151,7 +150,7 @@ func runSwitchKernel(cmd *cobra.Command, args []string) error { func dropRpmFilesAll(m platform.Machine, localPath string) error { fmt.Println("Dropping RT Kernel RPMs...") re := regexp.MustCompile(`^kernel-rt-.*\.rpm$`) - files, err := ioutil.ReadDir(localPath) + files, err := os.ReadDir(localPath) if err != nil { return err } diff --git a/mantle/cmd/kola/testiso.go b/mantle/cmd/kola/testiso.go index 72ce91b74da4869809273f498918f341745a268a..b6a569e36fb82f1b753b34fc66af5dac4fb700e7 100644 --- a/mantle/cmd/kola/testiso.go +++ b/mantle/cmd/kola/testiso.go @@ -24,7 +24,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -524,7 +523,7 @@ func awaitCompletion(ctx context.Context, inst *platform.QemuInstance, outdir st if errBuf != "" { plog.Info("entered emergency.target in initramfs") path := filepath.Join(outdir, "ignition-virtio-dump.txt") - if err := ioutil.WriteFile(path, []byte(errBuf), 0644); err != nil { + if err := os.WriteFile(path, []byte(errBuf), 0644); err != nil { plog.Errorf("Failed to write journal: %v", err) } err = platform.ErrInitramfsEmergency @@ -613,7 +612,7 @@ func testPXE(ctx context.Context, inst platform.Install, outdir string, offline if addNmKeyfile { return 0, errors.New("--add-nm-keyfile not yet supported for PXE") } - tmpd, err := ioutil.TempDir("", "kola-testiso") + tmpd, err := os.MkdirTemp("", "kola-testiso") if err != nil { return 0, err } @@ -666,7 +665,7 @@ func testPXE(ctx context.Context, inst platform.Install, outdir string, offline } func testLiveIso(ctx context.Context, inst platform.Install, outdir string, offline, minimal bool) (time.Duration, error) { - tmpd, err := ioutil.TempDir("", "kola-testiso") + tmpd, err := os.MkdirTemp("", "kola-testiso") if err != nil { return 0, err } diff --git a/mantle/cmd/kolet/kolet.go b/mantle/cmd/kolet/kolet.go index 638ebca3bc68c82211f70626d1e0221715b7d5d4..3d84166b800202ee8d8fb0219985ee4418191f58 100644 --- a/mantle/cmd/kolet/kolet.go +++ b/mantle/cmd/kolet/kolet.go @@ -18,7 +18,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "os" "os/exec" @@ -262,10 +262,10 @@ func initiateReboot(mark string) error { func runExtUnit(cmd *cobra.Command, args []string) error { rebootOff, _ := cmd.Flags().GetBool("deny-reboots") // Write the autopkgtest wrappers - if err := ioutil.WriteFile(autopkgTestRebootPath, []byte(autopkgtestRebootScript), 0755); err != nil { + if err := os.WriteFile(autopkgTestRebootPath, []byte(autopkgtestRebootScript), 0755); err != nil { return err } - if err := ioutil.WriteFile(autopkgTestRebootPreparePath, []byte(autopkgtestRebootPrepareScript), 0755); err != nil { + if err := os.WriteFile(autopkgTestRebootPreparePath, []byte(autopkgtestRebootPrepareScript), 0755); err != nil { return err } @@ -287,7 +287,7 @@ func runExtUnit(cmd *cobra.Command, args []string) error { return } defer rebootReader.Close() - buf, err := ioutil.ReadAll(rebootReader) + buf, err := io.ReadAll(rebootReader) if err != nil { errChan <- err } @@ -370,7 +370,7 @@ func runReboot(cmd *cobra.Command, args []string) error { if err != nil { return err } - err = ioutil.WriteFile(rebootRequestFifo, []byte(mark), 0644) + err = os.WriteFile(rebootRequestFifo, []byte(mark), 0644) if err != nil { return err } diff --git a/mantle/cmd/ore/gcloud/upload.go b/mantle/cmd/ore/gcloud/upload.go index 46a02b8287806969bc57142b13986f1f626dd476..b0989d45dc640270ab06651635ccf1e5f4b7ed66 100644 --- a/mantle/cmd/ore/gcloud/upload.go +++ b/mantle/cmd/ore/gcloud/upload.go @@ -17,7 +17,6 @@ package gcloud import ( "context" "fmt" - "io/ioutil" "net/url" "os" "strings" @@ -200,7 +199,7 @@ func runUpload(cmd *cobra.Command, args []string) { } if uploadWriteUrl != "" { - err = ioutil.WriteFile(uploadWriteUrl, []byte(imageStorageURL), 0644) + err = os.WriteFile(uploadWriteUrl, []byte(imageStorageURL), 0644) if err != nil { fmt.Fprintf(os.Stderr, "Writing file (%v) failed: %v\n", uploadWriteUrl, err) os.Exit(1) diff --git a/mantle/cmd/ore/ibmcloud/ibmcloud.go b/mantle/cmd/ore/ibmcloud/ibmcloud.go index 0ea395f08a2b49dd5c5cd8bc0e689b6d07032e06..b3216a5234a381ff2f6dbdd0a6dd54c409b7e95c 100644 --- a/mantle/cmd/ore/ibmcloud/ibmcloud.go +++ b/mantle/cmd/ore/ibmcloud/ibmcloud.go @@ -19,7 +19,7 @@ package ibmcloud import ( "encoding/json" "fmt" - "io/ioutil" + "io" "os" "os/user" "path/filepath" @@ -96,7 +96,7 @@ func preflightCheck(cmd *cobra.Command, args []string) error { defer file.Close() var apiKeyValues apiKeyFile - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { fmt.Fprintf(os.Stderr, "could not read apikey file: %v\n", err) os.Exit(1) diff --git a/mantle/cmd/ore/packet/create-device.go b/mantle/cmd/ore/packet/create-device.go index 448ef32679e892e08f818e98a185d1213cdc9f15..8cb72ce7a08b24d58fc6a8534b2f9abd8d111365 100644 --- a/mantle/cmd/ore/packet/create-device.go +++ b/mantle/cmd/ore/packet/create-device.go @@ -17,7 +17,6 @@ package packet import ( "encoding/json" "fmt" - "io/ioutil" "os" "github.com/spf13/cobra" @@ -55,7 +54,7 @@ func runCreateDevice(cmd *cobra.Command, args []string) error { userdata := conf.Empty() if userDataPath != "" { - data, err := ioutil.ReadFile(userDataPath) + data, err := os.ReadFile(userDataPath) if err != nil { fmt.Fprintf(os.Stderr, "Couldn't read userdata file %v: %v\n", userDataPath, err) os.Exit(1) diff --git a/mantle/cmd/plume/cosa2stream.go b/mantle/cmd/plume/cosa2stream.go index b43f2afd2bec15f96faf8c94221d8184f1633bd7..51178cca7cf3aa7832bf45b70300258b7adef7fa 100644 --- a/mantle/cmd/plume/cosa2stream.go +++ b/mantle/cmd/plume/cosa2stream.go @@ -19,7 +19,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "os" "os/exec" "strings" @@ -66,7 +65,7 @@ func runCosaBuildToStream(cmd *cobra.Command, args []string) error { var outStream stream.Stream if target != "" { - buf, err := ioutil.ReadFile(target) + buf, err := os.ReadFile(target) if err != nil { return err } @@ -102,7 +101,7 @@ func runCosaBuildToStream(cmd *cobra.Command, args []string) error { } for _, arg := range args { - releaseTmpf, err := ioutil.TempFile("", "release") + releaseTmpf, err := os.CreateTemp("", "release") if err != nil { return err } @@ -143,7 +142,7 @@ func runCosaBuildToStream(cmd *cobra.Command, args []string) error { } var rel release.Release - buf, err := ioutil.ReadAll(releaseTmpf) + buf, err := io.ReadAll(releaseTmpf) if err != nil { return err } diff --git a/mantle/cmd/plume/release.go b/mantle/cmd/plume/release.go index 79c187d133a00840304dcb4f82468c938f2b0dc1..f15116d2d04ca2529fae0cdbddeee9899856aa6c 100644 --- a/mantle/cmd/plume/release.go +++ b/mantle/cmd/plume/release.go @@ -18,7 +18,7 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" + "io" "net/url" "path/filepath" "time" @@ -136,7 +136,7 @@ func modifyReleaseMetadataIndex() { return []byte{}, fmt.Errorf("downloading release metadata index: %v", err) } defer f.Close() - d, err := ioutil.ReadAll(f) + d, err := io.ReadAll(f) if err != nil { return []byte{}, fmt.Errorf("reading release metadata index: %v", err) } diff --git a/mantle/cmd/plume/stream_mirror.go b/mantle/cmd/plume/stream_mirror.go index 661c3e333e4491673a528f4ed5e23ac693991e66..1be5e2a066e5430fa6509fbe59ad0c994b8cee31 100644 --- a/mantle/cmd/plume/stream_mirror.go +++ b/mantle/cmd/plume/stream_mirror.go @@ -17,7 +17,6 @@ package main import ( "encoding/json" "fmt" - "io/ioutil" "net/url" "os" "path/filepath" @@ -131,7 +130,7 @@ func runStreamMirror(cmd *cobra.Command, args []string) error { return fmt.Errorf("Must specify --dest-file with --url") } var srcStream stream.Stream - buf, err := ioutil.ReadFile(srcFile) + buf, err := os.ReadFile(srcFile) if err != nil { return err } @@ -174,7 +173,7 @@ func runStreamMirror(cmd *cobra.Command, args []string) error { if err != nil { return err } - err = ioutil.WriteFile(destFile, buf, 0644) + err = os.WriteFile(destFile, buf, 0644) if err != nil { return err } diff --git a/mantle/fcos/metadata.go b/mantle/fcos/metadata.go index 7ce45c20ab4383047add0991a018c6d5eb2fb977..9f3dcad4b67c4578646d4bfd17ea9d79b54494da 100644 --- a/mantle/fcos/metadata.go +++ b/mantle/fcos/metadata.go @@ -17,7 +17,7 @@ package fcos import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" @@ -34,7 +34,7 @@ func fetchURL(u url.URL) ([]byte, error) { return nil, err } - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { return nil, err diff --git a/mantle/harness/harness.go b/mantle/harness/harness.go index 9808f95c5a07475c09b943fed8cce2a180fc9777..8bc8740e55f8eaa7ae89d75a4cbca794c09ab068 100644 --- a/mantle/harness/harness.go +++ b/mantle/harness/harness.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "os" "path/filepath" @@ -437,7 +436,7 @@ func (h *H) TempDir(prefix string) string { h.log(err.Error()) h.FailNow() } - tmp, err := ioutil.TempDir(dir, prefix) + tmp, err := os.MkdirTemp(dir, prefix) if err != nil { h.log(fmt.Sprintf("Failed to create temp dir: %v", err)) h.FailNow() @@ -453,7 +452,7 @@ func (h *H) TempFile(prefix string) *os.File { h.log(err.Error()) h.FailNow() } - tmp, err := ioutil.TempFile(dir, prefix) + tmp, err := os.CreateTemp(dir, prefix) if err != nil { h.log(fmt.Sprintf("Failed to create temp file: %v", err)) h.FailNow() diff --git a/mantle/harness/reporters/json.go b/mantle/harness/reporters/json.go index 98cb486072d64d24bcdda94fffc719ed9d23f13b..38feec17d9711a2446aa1f7e6f472722cd64ae34 100644 --- a/mantle/harness/reporters/json.go +++ b/mantle/harness/reporters/json.go @@ -16,7 +16,7 @@ package reporters import ( "encoding/json" - "io/ioutil" + "io" "os" "path/filepath" "sync" @@ -51,7 +51,7 @@ func DeserialiseReport(filename string) (*jsonReporter, error) { return nil, err } - bytes, err := ioutil.ReadAll(file) + bytes, err := io.ReadAll(file) if err != nil { return nil, err } diff --git a/mantle/kola/tests/coretest/helpers.go b/mantle/kola/tests/coretest/helpers.go index 8aa48107394ed7b798fb67b85047e5bc4af8460f..7cfec8ded4ebea962fa81a8c4cc9d1813471e045 100644 --- a/mantle/kola/tests/coretest/helpers.go +++ b/mantle/kola/tests/coretest/helpers.go @@ -2,7 +2,7 @@ package coretest import ( "bufio" - "io/ioutil" + "io" "net" "os" "strings" @@ -52,7 +52,7 @@ func MachineID() string { defer f.Close() - buf, err := ioutil.ReadAll(f) + buf, err := io.ReadAll(f) if err != nil { panic(err) } diff --git a/mantle/kola/tests/crio/crio.go b/mantle/kola/tests/crio/crio.go index 3fbaa1704faaa60363de37a38466d40710b04e76..f77dcc52a5c0d21753d9a059bd2f593052f067dc 100644 --- a/mantle/kola/tests/crio/crio.go +++ b/mantle/kola/tests/crio/crio.go @@ -17,7 +17,7 @@ package crio import ( "encoding/json" "fmt" - "io/ioutil" + "os" "path" "strings" "time" @@ -220,7 +220,7 @@ func crioBaseTests(c cluster.TestCluster) { func generateCrioConfig(podName, imageName string, command []string) (string, string, error) { fileContentsPod := fmt.Sprintf(crioPodTemplate, podName, imageName) - tmpFilePod, err := ioutil.TempFile("", podName+"Pod") + tmpFilePod, err := os.CreateTemp("", podName+"Pod") if err != nil { return "", "", err } @@ -231,7 +231,7 @@ func generateCrioConfig(podName, imageName string, command []string) (string, st cmd := strings.Join(command, " ") fileContentsContainer := fmt.Sprintf(crioContainerTemplate, imageName, imageName, cmd) - tmpFileContainer, err := ioutil.TempFile("", imageName+"Container") + tmpFileContainer, err := os.CreateTemp("", imageName+"Container") if err != nil { return "", "", err } diff --git a/mantle/kola/tests/ignition/security.go b/mantle/kola/tests/ignition/security.go index bcf25d7c38b5cb04bcfe1f1e1d1064e788e3a64b..e964604a47debe978f1fd9fb6f2a17926142291e 100644 --- a/mantle/kola/tests/ignition/security.go +++ b/mantle/kola/tests/ignition/security.go @@ -17,10 +17,10 @@ package ignition import ( "crypto/tls" "fmt" - "io/ioutil" "net" "net/http" "net/http/httptest" + "os" "strings" "time" @@ -107,12 +107,12 @@ EOF } func ServeTLS(customFile []byte) error { - publicKey, err := ioutil.ReadFile("/var/tls/server.crt") + publicKey, err := os.ReadFile("/var/tls/server.crt") if err != nil { return fmt.Errorf("reading public key: %v", err) } - privateKey, err := ioutil.ReadFile("/var/tls/server.key") + privateKey, err := os.ReadFile("/var/tls/server.key") if err != nil { return fmt.Errorf("reading private key: %v", err) } diff --git a/mantle/network/journal/record_test.go b/mantle/network/journal/record_test.go index 2f413d40d5f8049343375dd27df6e7f34fff49ad..01ec4400a165ecba4028f368592afe0a8ad29767 100644 --- a/mantle/network/journal/record_test.go +++ b/mantle/network/journal/record_test.go @@ -17,7 +17,6 @@ package journal import ( "context" "io" - "io/ioutil" "strings" "testing" "time" @@ -50,7 +49,7 @@ func (d discardCloser) Close() error { } func (d discardCloser) Write(b []byte) (int, error) { - return ioutil.Discard.Write(b) + return io.Discard.Write(b) } // Escapes ; chars in cursor with \ diff --git a/mantle/network/ssh.go b/mantle/network/ssh.go index 3c066cbfe0e2f80a6df2c2eb15625ace7b3824c4..3c31fc5077c6d75e7b70e104a2fb10a9c30f8925 100644 --- a/mantle/network/ssh.go +++ b/mantle/network/ssh.go @@ -18,7 +18,6 @@ import ( "crypto/rand" "crypto/rsa" "fmt" - "io/ioutil" "net" "os" "strings" @@ -77,7 +76,7 @@ func NewSSHAgent(dialer Dialer) (*SSHAgent, error) { var ok, sockdirOwned bool if sockDir, ok = os.LookupEnv("MANTLE_SSH_DIR"); !ok { if DefaultSSHDir == "" { - sockDir, err = ioutil.TempDir("", "mantle-ssh-") + sockDir, err = os.MkdirTemp("", "mantle-ssh-") sockdirOwned = true if err != nil { return nil, err diff --git a/mantle/platform/api/aws/s3.go b/mantle/platform/api/aws/s3.go index 1baac93f39753486ae5466cf3a1bb83820e48099..0cee42fc3b9be3ea9a9461abbf894378ef474b6d 100644 --- a/mantle/platform/api/aws/s3.go +++ b/mantle/platform/api/aws/s3.go @@ -17,7 +17,6 @@ package aws import ( "fmt" "io" - "io/ioutil" "net/url" "os" @@ -204,7 +203,7 @@ func (a *API) UpdateBucketObjectsACL(srcBucket, prefix, policy string) error { // Downloads a file from S3 to a temporary file. This file must be closed by the caller. func (a *API) DownloadFile(srcBucket, srcPath string) (*os.File, error) { - f, err := ioutil.TempFile("", "mantle-file") + f, err := os.CreateTemp("", "mantle-file") if err != nil { return nil, err } diff --git a/mantle/platform/api/azure/instance.go b/mantle/platform/api/azure/instance.go index 431b9577de56e6205b084dde869f91dba6a66c5e..51886aaf1fae6a514e7557e005fa5e053f819c99 100644 --- a/mantle/platform/api/azure/instance.go +++ b/mantle/platform/api/azure/instance.go @@ -19,7 +19,6 @@ import ( "encoding/base64" "fmt" "io" - "io/ioutil" "math" "math/big" "regexp" @@ -252,5 +251,5 @@ func (a *API) GetConsoleOutput(name, resourceGroup, storageAccount string) ([]by return nil, err } - return ioutil.ReadAll(data) + return io.ReadAll(data) } diff --git a/mantle/platform/api/esx/api.go b/mantle/platform/api/esx/api.go index ca44cf95cf4bc6e9fbb740f9a4a749185028b993..4b9075026a309d5b80142d33fd126ba42e13f8e7 100644 --- a/mantle/platform/api/esx/api.go +++ b/mantle/platform/api/esx/api.go @@ -20,7 +20,7 @@ import ( "encoding/base64" "errors" "fmt" - "io/ioutil" + "io" "net" "net/url" "path" @@ -275,7 +275,7 @@ func (a *API) GetConsoleOutput(name string) (string, error) { } defer f.Close() - buf, err := ioutil.ReadAll(f) + buf, err := io.ReadAll(f) if err != nil { return "", fmt.Errorf("couldn't read serial output: %v", err) } diff --git a/mantle/platform/api/esx/archive.go b/mantle/platform/api/esx/archive.go index 80d8a68b12a949dded0e7df0cc2472c3375e03c5..913e673eec88881e9d69eae1fea376554357e380 100644 --- a/mantle/platform/api/esx/archive.go +++ b/mantle/platform/api/esx/archive.go @@ -19,7 +19,6 @@ import ( "archive/tar" "fmt" "io" - "io/ioutil" "os" "path" @@ -46,7 +45,7 @@ func (t *archive) readOvf(fpath string) ([]byte, error) { } defer r.Close() - return ioutil.ReadAll(r) + return io.ReadAll(r) } func (t *archive) readEnvelope(fpath string) (*ovf.Envelope, error) { diff --git a/mantle/platform/api/openstack/api.go b/mantle/platform/api/openstack/api.go index 29961d4516b304f394eb8cae20f612b74c036f6f..a3f62981a3eb9ee58c8dc2e04a11d49a57bd9685 100644 --- a/mantle/platform/api/openstack/api.go +++ b/mantle/platform/api/openstack/api.go @@ -16,7 +16,6 @@ package openstack import ( "fmt" - "io/ioutil" "os" "strings" "time" @@ -90,7 +89,7 @@ func (opts Options) LoadCloudsYAML() (map[string]clientconfig.Cloud, error) { // If provided a path to a config file then we load it here. if opts.ConfigPath != "" { var clouds clientconfig.Clouds - if content, err := ioutil.ReadFile(opts.ConfigPath); err != nil { + if content, err := os.ReadFile(opts.ConfigPath); err != nil { return nil, err } else if err := yaml.Unmarshal(content, &clouds); err != nil { return nil, fmt.Errorf("failed to unmarshal yaml %s: %v", opts.ConfigPath, err) diff --git a/mantle/platform/conf/conf.go b/mantle/platform/conf/conf.go index 76b216aff4d64d34e825722943bb03a9f3d104ac..832a4fc29f9efe97ca53cba3ad4833dd131fab83 100644 --- a/mantle/platform/conf/conf.go +++ b/mantle/platform/conf/conf.go @@ -21,7 +21,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "strings" @@ -455,7 +454,7 @@ func (c *Conf) ValidConfig() bool { // WriteFile writes the userdata in Conf to a local file. func (c *Conf) WriteFile(name string) error { - return ioutil.WriteFile(name, []byte(c.String()), 0666) + return os.WriteFile(name, []byte(c.String()), 0666) } // Bytes returns the serialized userdata in Conf. diff --git a/mantle/platform/journal.go b/mantle/platform/journal.go index 7030a0779b0dd98bcc839548c786c8e4009b5bc0..8742edbd06885994630a1ca2d6138fb6492a32b9 100644 --- a/mantle/platform/journal.go +++ b/mantle/platform/journal.go @@ -19,7 +19,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "os" "path/filepath" "time" @@ -134,7 +133,7 @@ func (j *Journal) Read() ([]byte, error) { return nil, errors.Wrapf(err, "reading journal") } defer f.Close() - return ioutil.ReadAll(f) + return io.ReadAll(f) } func (j *Journal) Destroy() { diff --git a/mantle/platform/machine/qemuiso/machine.go b/mantle/platform/machine/qemuiso/machine.go index d984368ff62142bbe414d5cf3b762f29a97f9885..f6ff8f76456df0689c21d1bacec6c54daf4130ed 100644 --- a/mantle/platform/machine/qemuiso/machine.go +++ b/mantle/platform/machine/qemuiso/machine.go @@ -17,7 +17,7 @@ package qemuiso import ( "context" "errors" - "io/ioutil" + "os" "time" "golang.org/x/crypto/ssh" @@ -92,7 +92,7 @@ func (m *machine) Destroy() { m.journal.Destroy() - if buf, err := ioutil.ReadFile(m.consolePath); err == nil { + if buf, err := os.ReadFile(m.consolePath); err == nil { m.console = string(buf) } else { plog.Errorf("Error reading console for instance %v: %v", m.ID(), err) diff --git a/mantle/platform/machine/unprivqemu/machine.go b/mantle/platform/machine/unprivqemu/machine.go index 1d5ae18f82dba714dfbaae537da0baf91df1d54f..f794c536dce1b8fc9fc9f3cebc5650a30af08158 100644 --- a/mantle/platform/machine/unprivqemu/machine.go +++ b/mantle/platform/machine/unprivqemu/machine.go @@ -17,7 +17,7 @@ package unprivqemu import ( "context" "errors" - "io/ioutil" + "os" "time" "golang.org/x/crypto/ssh" @@ -92,7 +92,7 @@ func (m *machine) Destroy() { m.journal.Destroy() - if buf, err := ioutil.ReadFile(m.consolePath); err == nil { + if buf, err := os.ReadFile(m.consolePath); err == nil { m.console = string(buf) } else { plog.Errorf("Error reading console for instance %v: %v", m.ID(), err) diff --git a/mantle/platform/metal.go b/mantle/platform/metal.go index c5a4f435d298870ed028032571d1ef5912a17710..4ca4cf78ea8e6e3a37df5035e0b9e5e6c65a371a 100644 --- a/mantle/platform/metal.go +++ b/mantle/platform/metal.go @@ -18,7 +18,6 @@ import ( "bufio" "fmt" "io" - "io/ioutil" "net" "net/http" "os" @@ -211,7 +210,7 @@ func (inst *Install) setup(kern *kernelSetup) (*installerRun, error) { builder := inst.Builder - tempdir, err := ioutil.TempDir("/var/tmp", "mantle-pxe") + tempdir, err := os.MkdirTemp("/var/tmp", "mantle-pxe") if err != nil { return nil, err } @@ -382,7 +381,7 @@ func (t *installerRun) completePxeSetup(kargs []string) error { if coreosarch.CurrentRpmArch() == "s390x" { pxeconfig = []byte(kargsStr) } - if err := ioutil.WriteFile(filepath.Join(pxeconfigdir, "default"), pxeconfig, 0777); err != nil { + if err := os.WriteFile(filepath.Join(pxeconfigdir, "default"), pxeconfig, 0777); err != nil { return err } @@ -415,7 +414,7 @@ func (t *installerRun) completePxeSetup(kargs []string) error { return err } } - if err := ioutil.WriteFile(filepath.Join(t.tftpdir, "boot/grub2/grub.cfg"), []byte(fmt.Sprintf(` + if err := os.WriteFile(filepath.Join(t.tftpdir, "boot/grub2/grub.cfg"), []byte(fmt.Sprintf(` default=0 timeout=1 menuentry "CoreOS (BIOS/UEFI)" { @@ -598,7 +597,7 @@ func (inst *Install) InstallViaISOEmbed(kargs []string, liveIgnition, targetIgni inst.ignition = targetIgnition inst.liveIgnition = liveIgnition - tempdir, err := ioutil.TempDir("/var/tmp", "mantle-metal") + tempdir, err := os.MkdirTemp("/var/tmp", "mantle-metal") if err != nil { return nil, err } @@ -700,7 +699,7 @@ func (inst *Install) InstallViaISOEmbed(kargs []string, liveIgnition, targetIgni var keyfileArgs []string for nmName, nmContents := range inst.NmKeyfiles { path := filepath.Join(tempdir, nmName) - if err := ioutil.WriteFile(path, []byte(nmContents), 0600); err != nil { + if err := os.WriteFile(path, []byte(nmContents), 0600); err != nil { return nil, err } keyfileArgs = append(keyfileArgs, "--keyfile", path) diff --git a/mantle/platform/qemu.go b/mantle/platform/qemu.go index 7c561c366d87d12bb236d7d975b61c8ec3e6a688..c467e2574154dfdca7b3de32dd909480e3e4251c 100644 --- a/mantle/platform/qemu.go +++ b/mantle/platform/qemu.go @@ -34,7 +34,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "math/rand" "net" "os" @@ -475,7 +474,7 @@ func (builder *QemuBuilder) ensureTempdir() error { if builder.tempdir != "" { return nil } - tempdir, err := ioutil.TempDir("/var/tmp", "mantle-qemu") + tempdir, err := os.MkdirTemp("/var/tmp", "mantle-qemu") if err != nil { return err } @@ -495,13 +494,13 @@ func (builder *QemuBuilder) SetConfig(config *conf.Conf) { builder.ignitionSet = true } -// Small wrapper around ioutil.Tempfile() to avoid leaking our tempdir to +// Small wrapper around os.CreateTemp() to avoid leaking our tempdir to // others. func (builder *QemuBuilder) TempFile(pattern string) (*os.File, error) { if err := builder.ensureTempdir(); err != nil { return nil, err } - return ioutil.TempFile(builder.tempdir, pattern) + return os.CreateTemp(builder.tempdir, pattern) } // renderIgnition lazily renders a parsed config if one is set @@ -700,7 +699,7 @@ func newGuestfish(diskImagePath string, diskSectorSize int) (*coreosGuestfish, e if err := cmd.Start(); err != nil { return nil, errors.Wrapf(err, "running guestfish") } - buf, err := ioutil.ReadAll(stdout) + buf, err := io.ReadAll(stdout) if err != nil { return nil, errors.Wrapf(err, "reading guestfish output") } @@ -827,7 +826,7 @@ func (disk *Disk) prepare(builder *QemuBuilder) error { if err := builder.ensureTempdir(); err != nil { return err } - tmpf, err := ioutil.TempFile(builder.tempdir, "disk") + tmpf, err := os.CreateTemp(builder.tempdir, "disk") if err != nil { return err } @@ -1149,7 +1148,7 @@ func (builder *QemuBuilder) setupUefi(secureBoot bool) error { return err } defer varsSrc.Close() - vars, err := ioutil.TempFile("", "mantle-qemu") + vars, err := os.CreateTemp("", "mantle-qemu") if err != nil { return err } @@ -1169,7 +1168,7 @@ func (builder *QemuBuilder) setupUefi(secureBoot bool) error { if secureBoot { return fmt.Errorf("architecture %s doesn't have support for secure boot in kola", coreosarch.CurrentRpmArch()) } - vars, err := ioutil.TempFile("", "mantle-qemu") + vars, err := os.CreateTemp("", "mantle-qemu") if err != nil { return err } diff --git a/mantle/platform/util.go b/mantle/platform/util.go index ef3bd7ae4b111465344841380976d51c6232381e..e352ca2f8a952629b1a332365802f3172f71d9ca 100644 --- a/mantle/platform/util.go +++ b/mantle/platform/util.go @@ -19,7 +19,6 @@ import ( "crypto/rand" "crypto/rsa" "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -196,7 +195,7 @@ func StartMachine(m Machine, j *Journal) error { msg := fmt.Sprintf("machine %s entered emergency.target in initramfs", m.ID()) plog.Info(msg) path := filepath.Join(filepath.Dir(j.journalPath), "ignition-virtio-dump.txt") - if err := ioutil.WriteFile(path, []byte(err.Error()), 0644); err != nil { + if err := os.WriteFile(path, []byte(err.Error()), 0644); err != nil { plog.Errorf("Failed to write journal: %v", err) } errchan <- errors.New(msg) diff --git a/mantle/rhcos/metadata.go b/mantle/rhcos/metadata.go index ec7529ee85c6e0c99f3346b643d88628d0491119..917ebcd2a33d630e160dd53c44e0dda58579a5d3 100644 --- a/mantle/rhcos/metadata.go +++ b/mantle/rhcos/metadata.go @@ -17,7 +17,7 @@ package rhcos import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" @@ -36,7 +36,7 @@ func fetchURL(u url.URL) ([]byte, error) { return nil, err } - body, err := ioutil.ReadAll(res.Body) + body, err := io.ReadAll(res.Body) res.Body.Close() if err != nil { return nil, err diff --git a/mantle/system/copy_test.go b/mantle/system/copy_test.go index 12cc3a72051f6428e3d1285b9172a2a42bd5efbc..d1fa22718668b52357ad07c63442d13360247bac 100644 --- a/mantle/system/copy_test.go +++ b/mantle/system/copy_test.go @@ -16,7 +16,7 @@ package system import ( "bytes" - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -37,7 +37,7 @@ func checkFile(t *testing.T, path string, data []byte, mode os.FileMode) { t.Fatalf("Unexpected mode: %s != %s %s", info.Mode(), mode, path) } - newData, err := ioutil.ReadAll(file) + newData, err := io.ReadAll(file) if err != nil { t.Fatal(err) } @@ -51,7 +51,7 @@ func TestCopyRegularFile(t *testing.T) { tmp := t.TempDir() src := filepath.Join(tmp, "src") - if err := ioutil.WriteFile(src, data, 0600); err != nil { + if err := os.WriteFile(src, data, 0600); err != nil { t.Fatal(err) } checkFile(t, src, data, 0600) diff --git a/mantle/util/common.go b/mantle/util/common.go index f597d1df6f6e20a6d68373e9e052647cd8f09ed1..d78d7fa2ff276adc2d624a1942a84b54348af961 100644 --- a/mantle/util/common.go +++ b/mantle/util/common.go @@ -16,7 +16,6 @@ package util import ( "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -86,7 +85,7 @@ func CreateSSHAuthorizedKey(tmpd string) ([]byte, string, error) { if err != nil { return nil, "", errors.Wrapf(err, "running ssh-keygen") } - sshPubKeyBuf, err := ioutil.ReadFile(sshPubKeyPath) + sshPubKeyBuf, err := os.ReadFile(sshPubKeyPath) if err != nil { return nil, "", errors.Wrapf(err, "reading pubkey") } diff --git a/mantle/util/repo.go b/mantle/util/repo.go index d957a0ba2554cb4b748f4b46e3ea573506957895..0dd96568a57f9a25e267856cba20a05c4a5de546 100644 --- a/mantle/util/repo.go +++ b/mantle/util/repo.go @@ -16,7 +16,6 @@ package util import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -67,7 +66,7 @@ func GetLocalFastBuildQemu() (string, error) { } return "", err } - ents, err := ioutil.ReadDir(fastBuildCosaDir) + ents, err := os.ReadDir(fastBuildCosaDir) if err != nil { return "", err }