From 6fe05ef066f23124cf6ec2922dd7fc55690cdbac Mon Sep 17 00:00:00 2001 From: guoguangwu Date: Tue, 1 Aug 2023 18:05:47 +0800 Subject: [PATCH] chore: remove refs to deprecated io/ioutil Signed-off-by: guoguangwu --- api-service/node/services/hugepages.go | 6 +++--- cmd/ndm_daemonset/controller/ndmconfig.go | 4 ++-- cmd/ndm_daemonset/controller/ndmconfig_test.go | 7 +++---- cmd/ndm_daemonset/controller/sparsefilegenerator.go | 3 +-- cmd/ndm_daemonset/probe/mountprobe_test.go | 3 +-- integration_tests/sanity/mount_change_test.go | 4 ++-- integration_tests/utils/file.go | 3 +-- pkg/mount/mountutil_test.go | 3 +-- pkg/sysfs/syspath.go | 7 +++---- pkg/sysfs/util.go | 6 +++--- pkg/udev/mockdata.go | 5 ++--- 11 files changed, 22 insertions(+), 29 deletions(-) diff --git a/api-service/node/services/hugepages.go b/api-service/node/services/hugepages.go index ba2c4f4b5..a5cec963f 100644 --- a/api-service/node/services/hugepages.go +++ b/api-service/node/services/hugepages.go @@ -15,7 +15,7 @@ package services import ( "context" - "io/ioutil" + "os" "strconv" "strings" @@ -41,7 +41,7 @@ func (n *Node) SetHugepages(ctx context.Context, h *protos.Hugepages) (*protos.H } msg := []byte(strconv.Itoa(int(hugepages.Pages))) - err := ioutil.WriteFile(hugepagesPath, msg, 0644) + err := os.WriteFile(hugepagesPath, msg, 0644) if err != nil { klog.Errorf("Error setting huge pages: %v", err) return nil, status.Errorf(codes.Internal, "Error setting hugepages") @@ -55,7 +55,7 @@ func (n *Node) GetHugepages(ctx context.Context, null *protos.Null) (*protos.Hug klog.Info("Getting the number of hugepages") - hugepages, err := ioutil.ReadFile(hugepagesPath) + hugepages, err := os.ReadFile(hugepagesPath) if err != nil { klog.Errorf("Error fetching number of hugepages %v", err) return nil, status.Errorf(codes.Internal, "Error fetching the number of hugepages set on the node") diff --git a/cmd/ndm_daemonset/controller/ndmconfig.go b/cmd/ndm_daemonset/controller/ndmconfig.go index 9f0fbd2d1..342db7045 100644 --- a/cmd/ndm_daemonset/controller/ndmconfig.go +++ b/cmd/ndm_daemonset/controller/ndmconfig.go @@ -18,7 +18,7 @@ package controller import ( "encoding/json" - "io/ioutil" + "os" "k8s.io/klog/v2" "sigs.k8s.io/yaml" @@ -73,7 +73,7 @@ type MetaConfig struct { // SetNDMConfig sets config for probes and filters which user provides via configmap. If // no configmap present then ndm will load default config for each probes and filters. func (c *Controller) SetNDMConfig(opts NDMOptions) { - data, err := ioutil.ReadFile(opts.ConfigFilePath) + data, err := os.ReadFile(opts.ConfigFilePath) if err != nil { c.NDMConfig = nil klog.Error("unable to set ndm config : ", err) diff --git a/cmd/ndm_daemonset/controller/ndmconfig_test.go b/cmd/ndm_daemonset/controller/ndmconfig_test.go index 635fb1f5d..bc4c3a2b8 100644 --- a/cmd/ndm_daemonset/controller/ndmconfig_test.go +++ b/cmd/ndm_daemonset/controller/ndmconfig_test.go @@ -17,7 +17,6 @@ limitations under the License. package controller import ( - "io/ioutil" "os" "testing" @@ -47,7 +46,7 @@ func TestSetNDMConfig(t *testing.T) { }, ] }`) - err := ioutil.WriteFile(fakeConfigFilePath, fileContent, 0644) + err := os.WriteFile(fakeConfigFilePath, fileContent, 0644) if err != nil { t.Fatal(err) } @@ -88,7 +87,7 @@ func TestSetNDMConfig(t *testing.T) { expectedNDMConfig.FilterConfigs = append(expectedNDMConfig.FilterConfigs, expectedFilterConfig) expectedNDMConfig.ProbeConfigs = append(expectedNDMConfig.ProbeConfigs, expectedProbeConfig) - err = ioutil.WriteFile(fakeConfigFilePath, fileContent, 0644) + err = os.WriteFile(fakeConfigFilePath, fileContent, 0644) if err != nil { t.Fatal(err) } @@ -135,6 +134,6 @@ filterconfigs: exclude: /,/etc/hosts,/boot ` - err := ioutil.WriteFile(fpath, []byte(data), 0644) + err := os.WriteFile(fpath, []byte(data), 0644) assert.NoError(t, err) } diff --git a/cmd/ndm_daemonset/controller/sparsefilegenerator.go b/cmd/ndm_daemonset/controller/sparsefilegenerator.go index f053034d7..115376a6d 100644 --- a/cmd/ndm_daemonset/controller/sparsefilegenerator.go +++ b/cmd/ndm_daemonset/controller/sparsefilegenerator.go @@ -17,7 +17,6 @@ limitations under the License. package controller import ( - "io/ioutil" "strings" "github.com/openebs/node-disk-manager/blockdevice" @@ -183,7 +182,7 @@ func GetSparseBlockDeviceUUID(hostname, sparseFile string) string { func GetActiveSparseBlockDevicesUUID(hostname string) []string { sparseFileLocation := GetSparseFileDir() sparseUuids := make([]string, 0) - files, err := ioutil.ReadDir(sparseFileLocation) + files, err := os.ReadDir(sparseFileLocation) if err != nil { klog.Error("Failed to read sparse file names : ", err) return sparseUuids diff --git a/cmd/ndm_daemonset/probe/mountprobe_test.go b/cmd/ndm_daemonset/probe/mountprobe_test.go index 336941f21..efef0c509 100644 --- a/cmd/ndm_daemonset/probe/mountprobe_test.go +++ b/cmd/ndm_daemonset/probe/mountprobe_test.go @@ -17,7 +17,6 @@ limitations under the License. package probe import ( - "io/ioutil" "os" "path" "syscall" @@ -141,5 +140,5 @@ func exitFakeRoot() error { } func createMountsFile(dest string) error { - return ioutil.WriteFile(dest, []byte(sampleMountsFile), 0444) + return os.WriteFile(dest, []byte(sampleMountsFile), 0444) } diff --git a/integration_tests/sanity/mount_change_test.go b/integration_tests/sanity/mount_change_test.go index 833328964..4d6af290b 100644 --- a/integration_tests/sanity/mount_change_test.go +++ b/integration_tests/sanity/mount_change_test.go @@ -17,7 +17,7 @@ limitations under the License. package sanity import ( - "io/ioutil" + "os" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -78,7 +78,7 @@ func tearDown(kcli *k8s.K8sClient, disk *udev.Disk) func() { func generateMountPath(mountPath *string) func() { return func() { - mp, err := ioutil.TempDir("", "ndm-integration-tests") + mp, err := os.MkdirTemp("", "ndm-integration-tests") Expect(err).ToNot(HaveOccurred()) *mountPath = mp } diff --git a/integration_tests/utils/file.go b/integration_tests/utils/file.go index 974cefce5..19f8b2f02 100644 --- a/integration_tests/utils/file.go +++ b/integration_tests/utils/file.go @@ -18,14 +18,13 @@ package utils import ( "fmt" - "io/ioutil" "os" "path/filepath" ) // GetYAMLString gets the yaml-string from the given YAML file func GetYAMLString(fileName string) (string, error) { - fileBytes, err := ioutil.ReadFile(filepath.Clean(fileName)) + fileBytes, err := os.ReadFile(filepath.Clean(fileName)) if err != nil { return "", err } diff --git a/pkg/mount/mountutil_test.go b/pkg/mount/mountutil_test.go index 7c0d64086..25d65f4b4 100644 --- a/pkg/mount/mountutil_test.go +++ b/pkg/mount/mountutil_test.go @@ -18,7 +18,6 @@ package mount import ( "errors" - "io/ioutil" "os" "path/filepath" "strings" @@ -164,7 +163,7 @@ func TestGetMountAttr(t *testing.T) { mountUtil := NewMountUtil(filePath, test.devPath, test.mountPoint) // create the temp file which will be read for getting attributes - err := ioutil.WriteFile(filePath, test.fileContent, 0644) + err := os.WriteFile(filePath, test.fileContent, 0644) if err != nil { t.Fatal(err) } diff --git a/pkg/sysfs/syspath.go b/pkg/sysfs/syspath.go index 8f12a6f9c..5b13e0436 100644 --- a/pkg/sysfs/syspath.go +++ b/pkg/sysfs/syspath.go @@ -18,7 +18,6 @@ package sysfs import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -112,7 +111,7 @@ func (s Device) getPartitions() ([]string, bool) { partitions := make([]string, 0) - files, err := ioutil.ReadDir(s.sysPath) + files, err := os.ReadDir(s.sysPath) if err != nil { return nil, false } @@ -135,7 +134,7 @@ func (s Device) getHolders() ([]string, bool) { return nil, false } - files, err := ioutil.ReadDir(holderPath) + files, err := os.ReadDir(holderPath) if err != nil { return nil, false } @@ -157,7 +156,7 @@ func (s Device) getSlaves() ([]string, bool) { return nil, false } - files, err := ioutil.ReadDir(slavePath) + files, err := os.ReadDir(slavePath) if err != nil { return nil, false } diff --git a/pkg/sysfs/util.go b/pkg/sysfs/util.go index c3ef30162..84360c23a 100644 --- a/pkg/sysfs/util.go +++ b/pkg/sysfs/util.go @@ -17,7 +17,7 @@ limitations under the License. package sysfs import ( - "io/ioutil" + "os" "path/filepath" "strconv" "strings" @@ -26,7 +26,7 @@ import ( // readSysFSFileAsInt64 reads a file and // converts that content into int64 func readSysFSFileAsInt64(sysFilePath string) (int64, error) { - b, err := ioutil.ReadFile(filepath.Clean(sysFilePath)) + b, err := os.ReadFile(filepath.Clean(sysFilePath)) if err != nil { return 0, err } @@ -35,7 +35,7 @@ func readSysFSFileAsInt64(sysFilePath string) (int64, error) { } func readSysFSFileAsString(sysFilePath string) (string, error) { - b, err := ioutil.ReadFile(filepath.Clean(sysFilePath)) + b, err := os.ReadFile(filepath.Clean(sysFilePath)) if err != nil { return "", err } diff --git a/pkg/udev/mockdata.go b/pkg/udev/mockdata.go index 4c5e2079d..188bc08ff 100644 --- a/pkg/udev/mockdata.go +++ b/pkg/udev/mockdata.go @@ -25,7 +25,6 @@ package udev import "C" import ( "bufio" - "io/ioutil" "os" "path" "path/filepath" @@ -145,7 +144,7 @@ func OsDiskName() (string, string, error) { // getSyspathOfOsDisk returns syspath of os disk in success func getSyspathOfOsDisk(osDiskName string) (string, error) { - data, err := ioutil.ReadFile(filepath.Clean(path.Join("/sys/class/block/", osDiskName, "dev"))) + data, err := os.ReadFile(filepath.Clean(path.Join("/sys/class/block/", osDiskName, "dev"))) if err != nil { return "", err } @@ -154,7 +153,7 @@ func getSyspathOfOsDisk(osDiskName string) (string, error) { // getOsDiskSize returns size of os disk in success func getOsDiskSize(osDiskName string) (string, error) { - sizeByte, err := ioutil.ReadFile(filepath.Clean(path.Join("/sys/class/block/", osDiskName, "size"))) + sizeByte, err := os.ReadFile(filepath.Clean(path.Join("/sys/class/block/", osDiskName, "size"))) if err != nil { return "", err }