Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <guoguangwu@magic-shield.com>
  • Loading branch information
testwill committed Aug 1, 2023
1 parent 8187952 commit 6fe05ef
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 29 deletions.
6 changes: 3 additions & 3 deletions api-service/node/services/hugepages.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package services

import (
"context"
"io/ioutil"
"os"
"strconv"
"strings"

Expand All @@ -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")
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions cmd/ndm_daemonset/controller/ndmconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package controller

import (
"encoding/json"
"io/ioutil"
"os"

"k8s.io/klog/v2"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions cmd/ndm_daemonset/controller/ndmconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package controller

import (
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
3 changes: 1 addition & 2 deletions cmd/ndm_daemonset/controller/sparsefilegenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package controller

import (
"io/ioutil"
"strings"

"github.com/openebs/node-disk-manager/blockdevice"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions cmd/ndm_daemonset/probe/mountprobe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package probe

import (
"io/ioutil"
"os"
"path"
"syscall"
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions integration_tests/sanity/mount_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package sanity

import (
"io/ioutil"
"os"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions integration_tests/utils/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/mount/mountutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package mount

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/sysfs/syspath.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package sysfs

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/sysfs/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package sysfs

import (
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/udev/mockdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ package udev
import "C"
import (
"bufio"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 6fe05ef

Please sign in to comment.