diff --git a/src/runtime/cmd/kata-runtime/kata-iptables.go b/src/runtime/cmd/kata-runtime/kata-iptables.go index 8e2bd93c60..a9953bfad1 100644 --- a/src/runtime/cmd/kata-runtime/kata-iptables.go +++ b/src/runtime/cmd/kata-runtime/kata-iptables.go @@ -7,7 +7,7 @@ package main import ( "fmt" - "io/ioutil" + "os" containerdshim "github.com/kata-containers/kata-containers/src/runtime/pkg/containerd-shim-v2" "github.com/kata-containers/kata-containers/src/runtime/pkg/katautils" @@ -103,7 +103,7 @@ var setIPTablesCommand = cli.Command{ } // Read file into buffer, and make request to the appropriate shim - buf, err := ioutil.ReadFile(iptablesFile) + buf, err := os.ReadFile(iptablesFile) if err != nil { return err } diff --git a/src/runtime/pkg/containerd-shim-v2/shim_management.go b/src/runtime/pkg/containerd-shim-v2/shim_management.go index a6b9bdba34..cfb3004605 100644 --- a/src/runtime/pkg/containerd-shim-v2/shim_management.go +++ b/src/runtime/pkg/containerd-shim-v2/shim_management.go @@ -11,7 +11,6 @@ import ( "expvar" "fmt" "io" - "io/ioutil" "net/http" "net/http/pprof" "net/url" @@ -173,7 +172,7 @@ func (s *service) serveVolumeStats(w http.ResponseWriter, r *http.Request) { } func (s *service) serveVolumeResize(w http.ResponseWriter, r *http.Request) { - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { shimMgtLog.WithError(err).Error("failed to read request body") w.WriteHeader(http.StatusInternalServerError) @@ -212,7 +211,7 @@ func (s *service) genericIPTablesHandler(w http.ResponseWriter, r *http.Request, switch r.Method { case http.MethodPut: - body, err := ioutil.ReadAll(r.Body) + body, err := io.ReadAll(r.Body) if err != nil { logger.WithError(err).Error("failed to read request body") w.WriteHeader(http.StatusInternalServerError) diff --git a/src/runtime/pkg/direct-volume/utils.go b/src/runtime/pkg/direct-volume/utils.go index 8520ddd35e..9e13a4d227 100644 --- a/src/runtime/pkg/direct-volume/utils.go +++ b/src/runtime/pkg/direct-volume/utils.go @@ -10,7 +10,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "path/filepath" ) @@ -75,7 +74,7 @@ func Add(volumePath string, mountInfo string) error { return err } - return ioutil.WriteFile(filepath.Join(volumeDir, mountInfoFileName), []byte(mountInfo), 0600) + return os.WriteFile(filepath.Join(volumeDir, mountInfoFileName), []byte(mountInfo), 0600) } // Remove deletes the direct volume path including all the files inside it. @@ -89,7 +88,7 @@ func VolumeMountInfo(volumePath string) (*MountInfo, error) { if _, err := os.Stat(mountInfoFilePath); err != nil { return nil, err } - buf, err := ioutil.ReadFile(mountInfoFilePath) + buf, err := os.ReadFile(mountInfoFilePath) if err != nil { return nil, err } @@ -108,11 +107,11 @@ func RecordSandboxId(sandboxId string, volumePath string) error { return err } - return ioutil.WriteFile(filepath.Join(kataDirectVolumeRootPath, encodedPath, sandboxId), []byte(""), 0600) + return os.WriteFile(filepath.Join(kataDirectVolumeRootPath, encodedPath, sandboxId), []byte(""), 0600) } func GetSandboxIdForVolume(volumePath string) (string, error) { - files, err := ioutil.ReadDir(filepath.Join(kataDirectVolumeRootPath, b64.URLEncoding.EncodeToString([]byte(volumePath)))) + files, err := os.ReadDir(filepath.Join(kataDirectVolumeRootPath, b64.URLEncoding.EncodeToString([]byte(volumePath)))) if err != nil { return "", err } diff --git a/src/runtime/pkg/govmm/qemu/image.go b/src/runtime/pkg/govmm/qemu/image.go index b17efdd162..405ea5a008 100644 --- a/src/runtime/pkg/govmm/qemu/image.go +++ b/src/runtime/pkg/govmm/qemu/image.go @@ -8,7 +8,6 @@ package qemu import ( "context" "fmt" - "io/ioutil" "os" "os/exec" "path" @@ -44,12 +43,12 @@ func CreateCloudInitISO(ctx context.Context, scratchDir, isoPath string, dataDirPath, err) } - err = ioutil.WriteFile(metaDataPath, metaData, 0644) + err = os.WriteFile(metaDataPath, metaData, 0644) if err != nil { return fmt.Errorf("unable to create %s : %v", metaDataPath, err) } - err = ioutil.WriteFile(userDataPath, userData, 0644) + err = os.WriteFile(userDataPath, userData, 0644) if err != nil { return fmt.Errorf("unable to create %s : %v", userDataPath, err) } diff --git a/src/runtime/pkg/govmm/qemu/qemu_test.go b/src/runtime/pkg/govmm/qemu/qemu_test.go index ae4030fb70..501c07fdf1 100644 --- a/src/runtime/pkg/govmm/qemu/qemu_test.go +++ b/src/runtime/pkg/govmm/qemu/qemu_test.go @@ -7,7 +7,6 @@ package qemu import ( "fmt" - "io/ioutil" "os" "reflect" "strings" @@ -186,8 +185,8 @@ func TestAppendDeviceNetwork(t *testing.T) { } func TestAppendDeviceNetworkMq(t *testing.T) { - foo, _ := ioutil.TempFile(os.TempDir(), "govmm-qemu-test") - bar, _ := ioutil.TempFile(os.TempDir(), "govmm-qemu-test") + foo, _ := os.CreateTemp(os.TempDir(), "govmm-qemu-test") + bar, _ := os.CreateTemp(os.TempDir(), "govmm-qemu-test") defer func() { _ = foo.Close() diff --git a/src/runtime/pkg/katautils/config.go b/src/runtime/pkg/katautils/config.go index d334c61713..b67c0c2dda 100644 --- a/src/runtime/pkg/katautils/config.go +++ b/src/runtime/pkg/katautils/config.go @@ -10,7 +10,6 @@ package katautils import ( "errors" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -1410,7 +1409,7 @@ func decodeDropIns(mainConfigPath string, tomlConf *tomlConfig) error { configDir := filepath.Dir(mainConfigPath) dropInDir := filepath.Join(configDir, "config.d") - files, err := ioutil.ReadDir(dropInDir) + files, err := os.ReadDir(dropInDir) if err != nil { if !os.IsNotExist(err) { return fmt.Errorf("error reading %q directory: %s", dropInDir, err) diff --git a/src/runtime/pkg/utils/shimclient/shim_management_client.go b/src/runtime/pkg/utils/shimclient/shim_management_client.go index 3f9e686507..1b9635c179 100644 --- a/src/runtime/pkg/utils/shimclient/shim_management_client.go +++ b/src/runtime/pkg/utils/shimclient/shim_management_client.go @@ -9,7 +9,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "net" "net/http" "time" @@ -91,7 +90,7 @@ func DoPut(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentTyp }() if resp.StatusCode != http.StatusOK { - data, _ := ioutil.ReadAll(resp.Body) + data, _ := io.ReadAll(resp.Body) return fmt.Errorf("error sending put: url: %s, status code: %d, response data: %s", urlPath, resp.StatusCode, string(data)) } @@ -117,7 +116,7 @@ func DoPost(sandboxID string, timeoutInSeconds time.Duration, urlPath, contentTy }() if resp.StatusCode != http.StatusOK { - data, _ := ioutil.ReadAll(resp.Body) + data, _ := io.ReadAll(resp.Body) return fmt.Errorf("error sending post: url: %s, status code: %d, response data: %s", urlPath, resp.StatusCode, string(data)) } diff --git a/src/runtime/virtcontainers/clh.go b/src/runtime/virtcontainers/clh.go index 090e074755..6989237254 100644 --- a/src/runtime/virtcontainers/clh.go +++ b/src/runtime/virtcontainers/clh.go @@ -14,7 +14,7 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "net" "net/http" "net/http/httputil" @@ -213,13 +213,13 @@ var vmAddNetPutRequest = func(clh *cloudHypervisor) error { return err } - respBody, err := ioutil.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) if err != nil { return err } resp.Body.Close() - resp.Body = ioutil.NopCloser(bytes.NewBuffer(respBody)) + resp.Body = io.NopCloser(bytes.NewBuffer(respBody)) if resp.StatusCode != 204 { clh.Logger().Errorf("vmAddNetPut failed with error '%d'. Response: %+v", resp.StatusCode, resp) diff --git a/src/runtime/virtcontainers/clh_test.go b/src/runtime/virtcontainers/clh_test.go index d36ace88fb..e8f02101e8 100644 --- a/src/runtime/virtcontainers/clh_test.go +++ b/src/runtime/virtcontainers/clh_test.go @@ -10,7 +10,6 @@ package virtcontainers import ( "context" - "io/ioutil" "net/http" "os" "path/filepath" @@ -134,7 +133,7 @@ func TestCloudHypervisorAddNetCheckNetConfigListValues(t *testing.T) { macTest := "00:00:00:00:00" - file, err := ioutil.TempFile("", "netFd") + file, err := os.CreateTemp("", "netFd") assert.Nil(err) defer os.Remove(file.Name()) @@ -172,7 +171,7 @@ func TestCloudHypervisorAddNetCheckEnpointTypes(t *testing.T) { macTest := "00:00:00:00:00" - file, err := ioutil.TempFile("", "netFd") + file, err := os.CreateTemp("", "netFd") assert.Nil(err) defer os.Remove(file.Name()) @@ -214,7 +213,7 @@ func TestCloudHypervisorAddNetCheckEnpointTypes(t *testing.T) { func TestCloudHypervisorNetRateLimiter(t *testing.T) { assert := assert.New(t) - file, err := ioutil.TempFile("", "netFd") + file, err := os.CreateTemp("", "netFd") assert.Nil(err) defer os.Remove(file.Name()) diff --git a/src/runtime/virtcontainers/kata_agent_test.go b/src/runtime/virtcontainers/kata_agent_test.go index 27a6837e9c..ba2e4e9472 100644 --- a/src/runtime/virtcontainers/kata_agent_test.go +++ b/src/runtime/virtcontainers/kata_agent_test.go @@ -9,7 +9,6 @@ import ( "bufio" "context" "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -1168,7 +1167,7 @@ func TestHandleHugepages(t *testing.T) { // are present (default is 1M, can only be changed on LPAR). See // https://www.ibm.com/docs/en/linuxonibm/pdf/lku5dd05.pdf, p. 345 for more information. if runtime.GOARCH == "s390x" { - dirs, err := ioutil.ReadDir(sysHugepagesDir) + dirs, err := os.ReadDir(sysHugepagesDir) assert.Nil(err) for _, dir := range dirs { formattedSizes = append(formattedSizes, strings.TrimPrefix(dir.Name(), "hugepages-")) diff --git a/src/runtime/virtcontainers/nydusd.go b/src/runtime/virtcontainers/nydusd.go index 38d9738d37..177e3044d1 100644 --- a/src/runtime/virtcontainers/nydusd.go +++ b/src/runtime/virtcontainers/nydusd.go @@ -13,7 +13,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net" "net/http" "os" @@ -398,7 +397,7 @@ func (c *NydusClient) CheckStatus() (DaemonInfo, error) { return DaemonInfo{}, err } defer resp.Body.Close() - b, err := ioutil.ReadAll(resp.Body) + b, err := io.ReadAll(resp.Body) if err != nil { return DaemonInfo{}, err } @@ -470,7 +469,7 @@ func (c *NydusClient) Umount(mountPoint string) error { } func handleMountError(r io.Reader) error { - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return err } diff --git a/src/tools/log-parser/hexbytes.go b/src/tools/log-parser/hexbytes.go index b919d92bbe..f075b37a03 100644 --- a/src/tools/log-parser/hexbytes.go +++ b/src/tools/log-parser/hexbytes.go @@ -9,7 +9,6 @@ package main import ( "errors" "io" - "io/ioutil" "os" "strings" ) @@ -56,7 +55,7 @@ func (r *HexByteReader) Read(p []byte) (n int, err error) { } // read the entire file - bytes, err := ioutil.ReadAll(r.f) + bytes, err := io.ReadAll(r.f) if err != nil { return 0, err } diff --git a/src/tools/log-parser/hexbytes_test.go b/src/tools/log-parser/hexbytes_test.go index f8c07350cb..53b5d2e512 100644 --- a/src/tools/log-parser/hexbytes_test.go +++ b/src/tools/log-parser/hexbytes_test.go @@ -7,7 +7,7 @@ package main import ( - "io/ioutil" + "io" "os" "path/filepath" "testing" @@ -36,7 +36,7 @@ func TestNewHexByteReaderStdin(t *testing.T) { func TestHexByteReaderRead(t *testing.T) { assert := assert.New(t) - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -68,7 +68,7 @@ func TestHexByteReaderRead(t *testing.T) { assert.NoError(err) reader := NewHexByteReader(file) - bytes, err := ioutil.ReadAll(reader) + bytes, err := io.ReadAll(reader) if d.expectError { assert.Errorf(err, "test[%d]: %+v", i, d) diff --git a/src/tools/log-parser/main_test.go b/src/tools/log-parser/main_test.go index 669a2bc4c2..2fd032cb76 100644 --- a/src/tools/log-parser/main_test.go +++ b/src/tools/log-parser/main_test.go @@ -6,12 +6,12 @@ package main -import "io/ioutil" +import "os" func createEmptyFile(path string) (err error) { - return ioutil.WriteFile(path, []byte(""), testFileMode) + return os.WriteFile(path, []byte(""), testFileMode) } func createFile(file, contents string) error { - return ioutil.WriteFile(file, []byte(contents), testFileMode) + return os.WriteFile(file, []byte(contents), testFileMode) } diff --git a/src/tools/log-parser/parse_test.go b/src/tools/log-parser/parse_test.go index 57e36780d9..ef82510e21 100644 --- a/src/tools/log-parser/parse_test.go +++ b/src/tools/log-parser/parse_test.go @@ -9,7 +9,6 @@ package main import ( "fmt" "io" - "io/ioutil" "os" "path/filepath" "regexp" @@ -52,7 +51,7 @@ func (r *TestReaderData) Read(p []byte) (n int, err error) { func TestParseLogFile(t *testing.T) { assert := assert.New(t) - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -201,7 +200,7 @@ func TestParseLogFiles(t *testing.T) { }, } - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } diff --git a/src/tools/log-parser/utils_test.go b/src/tools/log-parser/utils_test.go index 58be2db9b4..8f0cf58af3 100644 --- a/src/tools/log-parser/utils_test.go +++ b/src/tools/log-parser/utils_test.go @@ -7,7 +7,6 @@ package main import ( - "io/ioutil" "os" "path" "path/filepath" @@ -32,7 +31,7 @@ func TestUtilsResolvePathEmptyPath(t *testing.T) { func TestUtilsResolvePathValidPath(t *testing.T) { assert := assert.New(t) - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) } @@ -70,7 +69,7 @@ func TestUtilsResolvePathValidPath(t *testing.T) { func TestUtilsResolvePathENOENT(t *testing.T) { assert := assert.New(t) - dir, err := ioutil.TempDir("", "") + dir, err := os.MkdirTemp("", "") if err != nil { t.Fatal(err) }