diff --git a/backend/daemon.go b/backend/daemon.go index 32c7d7d14..459d377b8 100644 --- a/backend/daemon.go +++ b/backend/daemon.go @@ -69,7 +69,7 @@ func getListener(addr string) (net.Listener, error) { func (s *CriDockerService) Start() error { // Start the internal service. if err := s.service.Start(); err != nil { - logrus.Error(err, "Unable to start cri-dockerd service") + logrus.Errorf("Unable to start cri-dockerd service: %v", err) return err } @@ -93,7 +93,7 @@ func (s *CriDockerService) Start() error { go func() { if err := s.server.Serve(l); err != nil { - logrus.Error(err, "Failed to serve connections from cri-dockerd") + logrus.Errorf("Failed to serve connections from cri-dockerd: %v", err) os.Exit(1) } }() diff --git a/config/os.go b/config/os.go index a1234d8ee..8a9f0436e 100644 --- a/config/os.go +++ b/config/os.go @@ -97,7 +97,7 @@ func (RealOS) Pipe() (r *os.File, w *os.File, err error) { return os.Pipe() } -// ReadDir will call ioutil.ReadDir to return the files under the directory. +// ReadDir will call os.ReadDir to return the files under the directory. func (RealOS) ReadDir(dirname string) ([]os.DirEntry, error) { return os.ReadDir(dirname) } diff --git a/containermanager/container_manager_linux.go b/containermanager/container_manager_linux.go index 66e8eca7e..6b631c853 100644 --- a/containermanager/container_manager_linux.go +++ b/containermanager/container_manager_linux.go @@ -21,7 +21,7 @@ package containermanager import ( "fmt" - "io/ioutil" + "os" "regexp" "strconv" "time" @@ -142,7 +142,7 @@ func createCgroupManager(name string) (cgroups.Manager, error) { // getMemoryCapacity returns the memory capacity on the machine in bytes. func getMemoryCapacity() (uint64, error) { - out, err := ioutil.ReadFile("/proc/meminfo") + out, err := os.ReadFile("/proc/meminfo") if err != nil { return 0, err } diff --git a/core/imagefs_linux.go b/core/imagefs_linux.go index dc90dba25..136462c05 100644 --- a/core/imagefs_linux.go +++ b/core/imagefs_linux.go @@ -35,7 +35,7 @@ func (ds *dockerService) imageFsInfo() (*runtimeapi.ImageFsInfoResponse, error) stat := &syscall.Statfs_t{} err := syscall.Statfs(ds.dockerRootDir, stat) if err != nil { - logrus.Error(err, "Failed to get filesystem info for %s", ds.dockerRootDir) + logrus.Errorf("Failed to get filesystem info for %s: %v", ds.dockerRootDir, err) return nil, err } usedBytes := (stat.Blocks - stat.Bfree) * uint64(stat.Bsize) @@ -45,7 +45,7 @@ func (ds *dockerService) imageFsInfo() (*runtimeapi.ImageFsInfoResponse, error) // compute total used bytes by docker images images, err := ds.client.ListImages(image.ListOptions{All: true, SharedSize: true}) if err != nil { - logrus.Error(err, "Failed to get image list from docker") + logrus.Errorf("Failed to get image list from docker: %v", err) return nil, err } var totalImageSize uint64 diff --git a/core/security_context.go b/core/security_context.go index d28dd28e9..9d6773c73 100644 --- a/core/security_context.go +++ b/core/security_context.go @@ -21,7 +21,7 @@ import ( "crypto/md5" "encoding/json" "fmt" - "io/ioutil" + "os" "path/filepath" "strconv" "strings" @@ -277,7 +277,7 @@ func getSeccompDockerOpts(seccomp *runtimeapi.SecurityProfile, privileged bool) fname, ) } - file, err := ioutil.ReadFile(filepath.FromSlash(fname)) + file, err := os.ReadFile(filepath.FromSlash(fname)) if err != nil { return nil, fmt.Errorf("cannot load seccomp profile %q: %v", fname, err) } diff --git a/libdocker/kube_docker_client.go b/libdocker/kube_docker_client.go index 9263b2af9..6a5b2b87f 100644 --- a/libdocker/kube_docker_client.go +++ b/libdocker/kube_docker_client.go @@ -23,7 +23,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "regexp" "sync" "time" @@ -650,10 +649,10 @@ func (d *kubeDockerClient) redirectResponseToOutputStream( resp io.Reader, ) error { if outputStream == nil { - outputStream = ioutil.Discard + outputStream = io.Discard } if errorStream == nil { - errorStream = ioutil.Discard + errorStream = io.Discard } var err error if tty { diff --git a/network/cni/cni_test.go b/network/cni/cni_test.go index bf2ba384c..e7d1cef7c 100644 --- a/network/cni/cni_test.go +++ b/network/cni/cni_test.go @@ -1,3 +1,4 @@ +//go:build linux // +build linux /* @@ -22,7 +23,6 @@ import ( "bytes" "encoding/json" "fmt" - "io/ioutil" "math/rand" "net" "os" @@ -327,8 +327,8 @@ func TestCNIPlugin(t *testing.T) { if err != nil { t.Errorf("Expected nil: %v", err) } - eo, eerr := ioutil.ReadFile(outputEnv) - output, err := ioutil.ReadFile(outputFile) + eo, eerr := os.ReadFile(outputEnv) + output, err := os.ReadFile(outputFile) if err != nil || eerr != nil { t.Errorf("Failed to read output file %s: %v (env %s err %v)", outputFile, err, eo, eerr) } @@ -350,7 +350,7 @@ func TestCNIPlugin(t *testing.T) { IPRanges [][]map[string]interface{} `json:"IPRanges"` } `json:"runtimeConfig"` }{} - inputBytes, inerr := ioutil.ReadFile(inputFile) + inputBytes, inerr := os.ReadFile(inputFile) parseerr := json.Unmarshal(inputBytes, &inputConfig) if inerr != nil || parseerr != nil { t.Errorf( @@ -411,7 +411,7 @@ func TestCNIPlugin(t *testing.T) { if err != nil { t.Errorf("Expected nil: %v", err) } - output, err = ioutil.ReadFile(outputFile) + output, err = os.ReadFile(outputFile) require.NoError(t, err) expectedOutput = "DEL /proc/12345/ns/net podNamespace podName test_infra_container" if string(output) != expectedOutput { diff --git a/network/hairpin/hairpin.go b/network/hairpin/hairpin.go index 157ee7af1..75b733377 100644 --- a/network/hairpin/hairpin.go +++ b/network/hairpin/hairpin.go @@ -18,7 +18,6 @@ package hairpin import ( "fmt" - "io/ioutil" "net" "os" "path" @@ -104,5 +103,5 @@ func setUpInterface(ifName string) error { return nil } hairpinModeFile := path.Join(brportPath, hairpinModeRelativePath) - return ioutil.WriteFile(hairpinModeFile, []byte(hairpinEnable), 0644) + return os.WriteFile(hairpinModeFile, []byte(hairpinEnable), 0644) } diff --git a/network/kubenet/kubenet_linux.go b/network/kubenet/kubenet_linux.go index 9f23ee395..bcf98354e 100644 --- a/network/kubenet/kubenet_linux.go +++ b/network/kubenet/kubenet_linux.go @@ -22,8 +22,8 @@ package kubenet import ( "context" "fmt" - "io/ioutil" "net" + "os" "strings" "sync" "time" @@ -744,7 +744,7 @@ func (plugin *kubenetNetworkPlugin) checkRequiredCNIPlugins() bool { // checkRequiredCNIPluginsInOneDir returns true if all required cni plugins are placed in dir func (plugin *kubenetNetworkPlugin) checkRequiredCNIPluginsInOneDir(dir string) bool { - files, err := ioutil.ReadDir(dir) + files, err := os.ReadDir(dir) if err != nil { return false } diff --git a/store/filesystem.go b/store/filesystem.go index e6e7e649f..aee496843 100644 --- a/store/filesystem.go +++ b/store/filesystem.go @@ -32,11 +32,11 @@ type Filesystem interface { Chtimes(name string, atime time.Time, mtime time.Time) error RemoveAll(path string) error Remove(name string) error - - // from "io/ioutil" ReadFile(filename string) ([]byte, error) TempDir(dir, prefix string) (string, error) TempFile(dir, prefix string) (File, error) + + // from "io/ioutil" ReadDir(dirname string) ([]os.FileInfo, error) Walk(root string, walkFn filepath.WalkFunc) error } diff --git a/store/fs.go b/store/fs.go index 66b955c47..2e0d54ef9 100644 --- a/store/fs.go +++ b/store/fs.go @@ -67,19 +67,19 @@ func (DefaultFs) Remove(name string) error { return os.Remove(name) } -// ReadFile via ioutil.ReadFile +// ReadFile via os.ReadFile func (DefaultFs) ReadFile(filename string) ([]byte, error) { - return ioutil.ReadFile(filename) + return os.ReadFile(filename) } -// TempDir via ioutil.TempDir +// TempDir via os.MkdirTemp func (DefaultFs) TempDir(dir, prefix string) (string, error) { - return ioutil.TempDir(dir, prefix) + return os.MkdirTemp(dir, prefix) } -// TempFile via ioutil.TempFile +// TempFile via os.CreateTemp func (DefaultFs) TempFile(dir, prefix string) (File, error) { - file, err := ioutil.TempFile(dir, prefix) + file, err := os.CreateTemp(dir, prefix) if err != nil { return nil, err } diff --git a/streaming/remotecommand/errorstream.go b/streaming/remotecommand/errorstream.go index 5f64df633..6653ecc3a 100644 --- a/streaming/remotecommand/errorstream.go +++ b/streaming/remotecommand/errorstream.go @@ -19,7 +19,6 @@ package remotecommand import ( "fmt" "io" - "io/ioutil" "k8s.io/apimachinery/pkg/util/runtime" ) @@ -39,7 +38,7 @@ func watchErrorStream(errorStream io.Reader, d errorStreamDecoder) chan error { go func() { defer runtime.HandleCrash() - message, err := ioutil.ReadAll(errorStream) + message, err := io.ReadAll(errorStream) switch { case err != nil && err != io.EOF: errorChan <- fmt.Errorf("error reading from error stream: %s", err) diff --git a/utils/io.go b/utils/io.go index 06d77a129..6fdfa1ea8 100644 --- a/utils/io.go +++ b/utils/io.go @@ -36,7 +36,7 @@ func WriteCloserWrapper(w io.Writer) io.WriteCloser { return &writeCloserWrapper{w} } -// LimitWriter is a copy of the standard library ioutils.LimitReader, +// LimitWriter is a copy of the standard library io.LimitReader, // applied to the writer interface. // LimitWriter returns a Writer that writes to w // but stops with EOF after n bytes.