diff --git a/pkg/kubelet/kubeletconfig/checkpoint/store/fsstore_test.go b/pkg/kubelet/kubeletconfig/checkpoint/store/fsstore_test.go index 6ba35a48a28..05944f17c9f 100644 --- a/pkg/kubelet/kubeletconfig/checkpoint/store/fsstore_test.go +++ b/pkg/kubelet/kubeletconfig/checkpoint/store/fsstore_test.go @@ -657,7 +657,7 @@ func mapFromCheckpoint(store *fsStore, uid, resourceVersion string) (map[string] m := map[string]string{} for _, f := range files { // expect no subdirs, only regular files - if !f.Mode().IsRegular() { + if !f.Type().IsRegular() { return nil, fmt.Errorf("expect only regular files in checkpoint dir %q", uid) } // read the file contents and build the map diff --git a/pkg/util/filesystem/defaultfs.go b/pkg/util/filesystem/defaultfs.go index b966ab31d95..a7eb01ffe36 100644 --- a/pkg/util/filesystem/defaultfs.go +++ b/pkg/util/filesystem/defaultfs.go @@ -17,14 +17,13 @@ limitations under the License. package filesystem import ( - "io/ioutil" "os" "path/filepath" "strings" "time" ) -// DefaultFs implements Filesystem using same-named functions from "os" and "io/ioutil" +// DefaultFs implements Filesystem using same-named functions from "os" and "io" type DefaultFs struct { root string } @@ -33,10 +32,7 @@ var _ Filesystem = &DefaultFs{} // NewTempFs returns a fake Filesystem in temporary directory, useful for unit tests func NewTempFs() Filesystem { - path, _ := ioutil.TempDir( - "", - "tmpfs", - ) + path, _ := os.MkdirTemp("", "tmpfs") return &DefaultFs{ root: path, } @@ -94,28 +90,28 @@ func (fs *DefaultFs) Remove(name string) error { return os.Remove(fs.prefix(name)) } -// ReadFile via ioutil.ReadFile +// ReadFile via os.ReadFile func (fs *DefaultFs) ReadFile(filename string) ([]byte, error) { - return ioutil.ReadFile(fs.prefix(filename)) + return os.ReadFile(fs.prefix(filename)) } -// TempDir via ioutil.TempDir +// TempDir via os.MkdirTemp func (fs *DefaultFs) TempDir(dir, prefix string) (string, error) { - return ioutil.TempDir(fs.prefix(dir), prefix) + return os.MkdirTemp(fs.prefix(dir), prefix) } -// TempFile via ioutil.TempFile +// TempFile via os.CreateTemp func (fs *DefaultFs) TempFile(dir, prefix string) (File, error) { - file, err := ioutil.TempFile(fs.prefix(dir), prefix) + file, err := os.CreateTemp(fs.prefix(dir), prefix) if err != nil { return nil, err } return &defaultFile{file}, nil } -// ReadDir via ioutil.ReadDir -func (fs *DefaultFs) ReadDir(dirname string) ([]os.FileInfo, error) { - return ioutil.ReadDir(fs.prefix(dirname)) +// ReadDir via os.ReadDir +func (fs *DefaultFs) ReadDir(dirname string) ([]os.DirEntry, error) { + return os.ReadDir(fs.prefix(dirname)) } // Walk via filepath.Walk diff --git a/pkg/util/filesystem/filesystem.go b/pkg/util/filesystem/filesystem.go index 9b25e14b9f5..43cd4aa7e29 100644 --- a/pkg/util/filesystem/filesystem.go +++ b/pkg/util/filesystem/filesystem.go @@ -37,7 +37,7 @@ type Filesystem interface { ReadFile(filename string) ([]byte, error) TempDir(dir, prefix string) (string, error) TempFile(dir, prefix string) (File, error) - ReadDir(dirname string) ([]os.FileInfo, error) + ReadDir(dirname string) ([]os.DirEntry, error) Walk(root string, walkFn filepath.WalkFunc) error } diff --git a/pkg/util/oom/oom_linux.go b/pkg/util/oom/oom_linux.go index b2ab3611989..380967f9c00 100644 --- a/pkg/util/oom/oom_linux.go +++ b/pkg/util/oom/oom_linux.go @@ -21,7 +21,6 @@ package oom import ( "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -66,7 +65,7 @@ func applyOOMScoreAdj(pid int, oomScoreAdj int) error { klog.V(4).Infof("attempting to set %q to %q", oomScoreAdjPath, value) var err error for i := 0; i < maxTries; i++ { - err = ioutil.WriteFile(oomScoreAdjPath, []byte(value), 0700) + err = os.WriteFile(oomScoreAdjPath, []byte(value), 0700) if err != nil { if os.IsNotExist(err) { klog.V(2).Infof("%q does not exist", oomScoreAdjPath) diff --git a/pkg/util/procfs/procfs_linux.go b/pkg/util/procfs/procfs_linux.go index 371a1d1285a..a3b89c5f39a 100644 --- a/pkg/util/procfs/procfs_linux.go +++ b/pkg/util/procfs/procfs_linux.go @@ -23,7 +23,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -61,7 +60,7 @@ func containerNameFromProcCgroup(content string) (string, error) { // return docker/nginx. Assumes that the process is part of exactly one cgroup hierarchy. func (pfs *ProcFS) GetFullContainerName(pid int) (string, error) { filePath := path.Join("/proc", strconv.Itoa(pid), "cgroup") - content, err := ioutil.ReadFile(filePath) + content, err := os.ReadFile(filePath) if err != nil { if os.IsNotExist(err) { return "", os.ErrNotExist @@ -138,7 +137,7 @@ func getPids(re *regexp.Regexp) []int { continue } - cmdline, err := ioutil.ReadFile(filepath.Join("/proc", entry.Name(), "cmdline")) + cmdline, err := os.ReadFile(filepath.Join("/proc", entry.Name(), "cmdline")) if err != nil { klog.V(4).Infof("Error reading file %s: %+v", filepath.Join("/proc", entry.Name(), "cmdline"), err) continue diff --git a/pkg/util/procfs/procfs_linux_test.go b/pkg/util/procfs/procfs_linux_test.go index 8951ca1bb55..968b5e32a71 100644 --- a/pkg/util/procfs/procfs_linux_test.go +++ b/pkg/util/procfs/procfs_linux_test.go @@ -20,7 +20,6 @@ limitations under the License. package procfs import ( - "io/ioutil" "os" "os/signal" "path/filepath" @@ -56,7 +55,7 @@ func TestContainerNameFromProcCgroup(t *testing.T) { procCgroupEmpty := "" verifyContainerName(procCgroupEmpty, "", true, t) - content, err := ioutil.ReadFile("example_proc_cgroup") + content, err := os.ReadFile("example_proc_cgroup") if err != nil { t.Errorf("Could not read example /proc cgroup file") } diff --git a/pkg/util/tail/tail.go b/pkg/util/tail/tail.go index cd9fc22c175..a3c7e7398d7 100644 --- a/pkg/util/tail/tail.go +++ b/pkg/util/tail/tail.go @@ -19,7 +19,6 @@ package tail import ( "bytes" "io" - "io/ioutil" "os" ) @@ -57,7 +56,7 @@ func ReadAtMost(path string, max int64) ([]byte, bool, error) { if err != nil { return nil, false, err } - data, err := ioutil.ReadAll(f) + data, err := io.ReadAll(f) return data, offset > 0, err } diff --git a/pkg/util/tail/tail_test.go b/pkg/util/tail/tail_test.go index 641cfb10209..fce8d2ffb1d 100644 --- a/pkg/util/tail/tail_test.go +++ b/pkg/util/tail/tail_test.go @@ -18,14 +18,13 @@ package tail import ( "bytes" - "io/ioutil" "os" "strings" "testing" ) func TestReadAtMost(t *testing.T) { - file, err := ioutil.TempFile("", "TestFileReadAtMost") + file, err := os.CreateTemp("", "TestFileReadAtMost") if err != nil { t.Fatalf("unable to create temp file") }