diff --git a/pkg/volume/csi/csi_attacher_test.go b/pkg/volume/csi/csi_attacher_test.go index 1494316eac0..d2ed6ba37e4 100644 --- a/pkg/volume/csi/csi_attacher_test.go +++ b/pkg/volume/csi/csi_attacher_test.go @@ -20,7 +20,6 @@ import ( "context" "crypto/sha256" "fmt" - "io/ioutil" "os" "os/user" "path/filepath" @@ -1644,7 +1643,7 @@ func TestAttacherUnmountDevice(t *testing.T) { // Make JSON for this object if tc.jsonFile != "" { dataPath := filepath.Join(dir, volDataFileName) - if err := ioutil.WriteFile(dataPath, []byte(tc.jsonFile), 0644); err != nil { + if err := os.WriteFile(dataPath, []byte(tc.jsonFile), 0644); err != nil { t.Fatalf("error creating %s: %s", dataPath, err) } } diff --git a/pkg/volume/csi/csi_mounter_test.go b/pkg/volume/csi/csi_mounter_test.go index c1c487f2d95..a5e542ea6a4 100644 --- a/pkg/volume/csi/csi_mounter_test.go +++ b/pkg/volume/csi/csi_mounter_test.go @@ -19,7 +19,6 @@ package csi import ( "context" "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" @@ -1065,7 +1064,7 @@ func TestUnmounterTeardown(t *testing.T) { } func TestIsCorruptedDir(t *testing.T) { - existingMountPath, err := ioutil.TempDir(os.TempDir(), "blobfuse-csi-mount-test") + existingMountPath, err := os.MkdirTemp(os.TempDir(), "blobfuse-csi-mount-test") if err != nil { t.Fatalf("failed to create tmp dir: %v", err) } diff --git a/pkg/volume/csi/csi_util_test.go b/pkg/volume/csi/csi_util_test.go index 4450c268161..1a20f6e1754 100644 --- a/pkg/volume/csi/csi_util_test.go +++ b/pkg/volume/csi/csi_util_test.go @@ -21,7 +21,6 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" "os" "path/filepath" "testing" @@ -143,7 +142,7 @@ func TestSaveVolumeData(t *testing.T) { } // validate content - data, err := ioutil.ReadFile(file) + data, err := os.ReadFile(file) if !tc.shouldFail && err != nil { t.Errorf("failed to read data file: %v", err) } diff --git a/pkg/volume/csi/fake/fake_client.go b/pkg/volume/csi/fake/fake_client.go index 6883edefda6..037beaa4909 100644 --- a/pkg/volume/csi/fake/fake_client.go +++ b/pkg/volume/csi/fake/fake_client.go @@ -20,7 +20,6 @@ import ( "context" "errors" "fmt" - "io/ioutil" "os" "strings" @@ -205,7 +204,7 @@ func (f *NodeClient) NodePublishVolume(ctx context.Context, req *csipb.NodePubli // "Creation of target_path is the responsibility of the SP." // Our plugin depends on it. if req.VolumeCapability.GetBlock() != nil { - if err := ioutil.WriteFile(req.TargetPath, []byte{}, 0644); err != nil { + if err := os.WriteFile(req.TargetPath, []byte{}, 0644); err != nil { return nil, fmt.Errorf("cannot create target path %s for block file: %s", req.TargetPath, err) } } else { diff --git a/pkg/volume/metrics_du_test.go b/pkg/volume/metrics_du_test.go index b4c72924e7a..cd764fc1f51 100644 --- a/pkg/volume/metrics_du_test.go +++ b/pkg/volume/metrics_du_test.go @@ -17,7 +17,6 @@ limitations under the License. package volume_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -60,7 +59,7 @@ func TestMetricsDuGetCapacity(t *testing.T) { } // Write a file and expect Used to increase - ioutil.WriteFile(filepath.Join(tmpDir, "f1"), []byte("Hello World"), os.ModeTemporary) + os.WriteFile(filepath.Join(tmpDir, "f1"), []byte("Hello World"), os.ModeTemporary) actual, err = metrics.GetMetrics() if err != nil { t.Errorf("Unexpected error when calling GetMetrics %v", err) diff --git a/pkg/volume/projected/projected_test.go b/pkg/volume/projected/projected_test.go index ac24859d167..880755b2649 100644 --- a/pkg/volume/projected/projected_test.go +++ b/pkg/volume/projected/projected_test.go @@ -18,7 +18,6 @@ package projected import ( "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -874,7 +873,7 @@ func TestCollectDataWithServiceAccountToken(t *testing.T) { } func newTestHost(t *testing.T, clientset clientset.Interface) (string, volume.VolumeHost) { - tempDir, err := ioutil.TempDir("", "projected_volume_test.") + tempDir, err := os.MkdirTemp("", "projected_volume_test.") if err != nil { t.Fatalf("can't make a temp rootdir: %v", err) } @@ -1139,7 +1138,7 @@ func TestPluginOptional(t *testing.T) { } datadirPath := filepath.Join(volumePath, datadir) - infos, err := ioutil.ReadDir(volumePath) + infos, err := os.ReadDir(volumePath) if err != nil { t.Fatalf("couldn't find volume path, %s", volumePath) } @@ -1151,7 +1150,7 @@ func TestPluginOptional(t *testing.T) { } } - infos, err = ioutil.ReadDir(datadirPath) + infos, err = os.ReadDir(datadirPath) if err != nil { t.Fatalf("couldn't find volume data path, %s", datadirPath) } @@ -1292,7 +1291,7 @@ func doTestSecretDataInVolume(volumePath string, secret v1.Secret, t *testing.T) if _, err := os.Stat(secretDataHostPath); err != nil { t.Fatalf("SetUp() failed, couldn't find secret data on disk: %v", secretDataHostPath) } else { - actualSecretBytes, err := ioutil.ReadFile(secretDataHostPath) + actualSecretBytes, err := os.ReadFile(secretDataHostPath) if err != nil { t.Fatalf("Couldn't read secret data from: %v", secretDataHostPath) } diff --git a/pkg/volume/util/atomic_writer.go b/pkg/volume/util/atomic_writer.go index 91ee77a9f69..7a1f0515e9e 100644 --- a/pkg/volume/util/atomic_writer.go +++ b/pkg/volume/util/atomic_writer.go @@ -19,7 +19,6 @@ package util import ( "bytes" "fmt" - "io/ioutil" "os" "path" "path/filepath" @@ -327,7 +326,7 @@ func shouldWriteFile(path string, content []byte) (bool, error) { return true, nil } - contentOnFs, err := ioutil.ReadFile(path) + contentOnFs, err := os.ReadFile(path) if err != nil { return false, err } @@ -379,7 +378,7 @@ func (w *AtomicWriter) pathsToRemove(payload map[string]FileProjection, oldTsDir // newTimestampDir creates a new timestamp directory func (w *AtomicWriter) newTimestampDir() (string, error) { - tsDir, err := ioutil.TempDir(w.targetDir, time.Now().UTC().Format("..2006_01_02_15_04_05.")) + tsDir, err := os.MkdirTemp(w.targetDir, time.Now().UTC().Format("..2006_01_02_15_04_05.")) if err != nil { klog.Errorf("%s: unable to create new temp directory: %v", w.logContext, err) return "", err @@ -411,11 +410,11 @@ func (w *AtomicWriter) writePayloadToDir(payload map[string]FileProjection, dir return err } - if err := ioutil.WriteFile(fullPath, content, mode); err != nil { + if err := os.WriteFile(fullPath, content, mode); err != nil { klog.Errorf("%s: unable to write file %s with mode %v: %v", w.logContext, fullPath, mode, err) return err } - // Chmod is needed because ioutil.WriteFile() ends up calling + // Chmod is needed because os.WriteFile() ends up calling // open(2) to create the file, so the final mode used is "mode & // ~umask". But we want to make sure the specified mode is used // in the file no matter what the umask is. diff --git a/pkg/volume/util/atomic_writer_test.go b/pkg/volume/util/atomic_writer_test.go index d463d0ba023..394d252e262 100644 --- a/pkg/volume/util/atomic_writer_test.go +++ b/pkg/volume/util/atomic_writer_test.go @@ -22,7 +22,6 @@ package util import ( "encoding/base64" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -766,7 +765,7 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec return nil } - content, err := ioutil.ReadFile(path) + content, err := os.ReadFile(path) if err != nil { return err } @@ -781,7 +780,7 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec return nil } - d, err := ioutil.ReadDir(targetDir) + d, err := os.ReadDir(targetDir) if err != nil { t.Errorf("Unable to read dir %v: %v", targetDir, err) return @@ -790,7 +789,7 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec if strings.HasPrefix(info.Name(), "..") { continue } - if info.Mode()&os.ModeSymlink != 0 { + if info.Type()&os.ModeSymlink != 0 { p := filepath.Join(targetDir, info.Name()) actual, err := os.Readlink(p) if err != nil { diff --git a/pkg/volume/util/fs/fs_windows_test.go b/pkg/volume/util/fs/fs_windows_test.go index a5ded068910..b525999c3ee 100644 --- a/pkg/volume/util/fs/fs_windows_test.go +++ b/pkg/volume/util/fs/fs_windows_test.go @@ -18,7 +18,6 @@ package fs import ( "fmt" - "io/ioutil" "os" "testing" @@ -28,21 +27,21 @@ import ( func TestDiskUsage(t *testing.T) { - dir1, err := ioutil.TempDir("", "dir_1") + dir1, err := os.MkdirTemp("", "dir_1") if err != nil { t.Fatalf("TestDiskUsage failed: %s", err.Error()) } defer os.RemoveAll(dir1) - tmpfile1, err := ioutil.TempFile(dir1, "test") + tmpfile1, err := os.CreateTemp(dir1, "test") if _, err = tmpfile1.WriteString("just for testing"); err != nil { t.Fatalf("TestDiskUsage failed: %s", err.Error()) } - dir2, err := ioutil.TempDir(dir1, "dir_2") + dir2, err := os.MkdirTemp(dir1, "dir_2") if err != nil { t.Fatalf("TestDiskUsage failed: %s", err.Error()) } - tmpfile2, err := ioutil.TempFile(dir2, "test") + tmpfile2, err := os.CreateTemp(dir2, "test") if _, err = tmpfile2.WriteString("just for testing"); err != nil { t.Fatalf("TestDiskUsage failed: %s", err.Error()) } @@ -92,7 +91,7 @@ func TestDiskUsage(t *testing.T) { } func TestInfo(t *testing.T) { - dir1, err := ioutil.TempDir("", "dir_1") + dir1, err := os.MkdirTemp("", "dir_1") if err != nil { t.Fatalf("TestInfo failed: %s", err.Error()) } @@ -107,7 +106,7 @@ func TestInfo(t *testing.T) { validateInfo(t, availablebytes, capacity, usage, inodesTotal, inodeUsage, inodesFree) // should pass for file - tmpfile1, err := ioutil.TempFile(dir1, "test") + tmpfile1, err := os.CreateTemp(dir1, "test") if _, err = tmpfile1.WriteString("just for testing"); err != nil { t.Fatalf("TestInfo failed: %s", err.Error()) } diff --git a/pkg/volume/util/fsquota/common/quota_common_linux_impl.go b/pkg/volume/util/fsquota/common/quota_common_linux_impl.go index 7f24ca1cd7d..5e8e3850cfe 100644 --- a/pkg/volume/util/fsquota/common/quota_common_linux_impl.go +++ b/pkg/volume/util/fsquota/common/quota_common_linux_impl.go @@ -22,7 +22,6 @@ package common import ( "bufio" "fmt" - "io/ioutil" "os" "os/exec" "regexp" @@ -144,7 +143,7 @@ func doRunXFSQuotaCommand(mountpoint string, mountsFile, command string) (string // See https://bugzilla.redhat.com/show_bug.cgi?id=237120 for an example // of the problem that could be caused if this were to happen. func runXFSQuotaCommand(mountpoint string, command string) (string, error) { - tmpMounts, err := ioutil.TempFile("", "mounts") + tmpMounts, err := os.CreateTemp("", "mounts") if err != nil { return "", fmt.Errorf("cannot create temporary mount file: %v", err) } diff --git a/pkg/volume/util/fsquota/project.go b/pkg/volume/util/fsquota/project.go index 8ebc0068740..16d25d6c3f5 100644 --- a/pkg/volume/util/fsquota/project.go +++ b/pkg/volume/util/fsquota/project.go @@ -22,7 +22,6 @@ package fsquota import ( "bufio" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -267,7 +266,7 @@ func writeProjectFile(base *os.File, projects []projectType) (string, error) { return "", err } mode := stat.Mode() & os.ModePerm - f, err := ioutil.TempFile(filepath.Dir(oname), filepath.Base(oname)) + f, err := os.CreateTemp(filepath.Dir(oname), filepath.Base(oname)) if err != nil { return "", err } diff --git a/pkg/volume/util/fsquota/quota_linux_test.go b/pkg/volume/util/fsquota/quota_linux_test.go index 13bdd786839..14ee775695c 100644 --- a/pkg/volume/util/fsquota/quota_linux_test.go +++ b/pkg/volume/util/fsquota/quota_linux_test.go @@ -21,7 +21,6 @@ package fsquota import ( "fmt" - "io/ioutil" "os" "strings" "testing" @@ -97,7 +96,7 @@ type mountpointTest struct { } func testBackingDev1(testcase backingDevTest) error { - tmpfile, err := ioutil.TempFile("", "backingdev") + tmpfile, err := os.CreateTemp("", "backingdev") if err != nil { return err } @@ -502,7 +501,7 @@ var quotaTestCases = []quotaTestCase{ } func compareProjectsFiles(t *testing.T, testcase quotaTestCase, projectsFile string, projidFile string, enabled bool) { - bytes, err := ioutil.ReadFile(projectsFile) + bytes, err := os.ReadFile(projectsFile) if err != nil { t.Error(err.Error()) } else { @@ -515,7 +514,7 @@ func compareProjectsFiles(t *testing.T, testcase quotaTestCase, projectsFile str t.Errorf("Case %v /etc/projects miscompare: expected\n`%s`\ngot\n`%s`\n", testcase.path, p, s) } } - bytes, err = ioutil.ReadFile(projidFile) + bytes, err = os.ReadFile(projidFile) if err != nil { t.Error(err.Error()) } else { @@ -598,7 +597,7 @@ func runCaseDisabled(t *testing.T, testcase quotaTestCase, seq int) bool { func testAddRemoveQuotas(t *testing.T, enabled bool) { defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.LocalStorageCapacityIsolationFSQuotaMonitoring, enabled)() - tmpProjectsFile, err := ioutil.TempFile("", "projects") + tmpProjectsFile, err := os.CreateTemp("", "projects") if err == nil { _, err = tmpProjectsFile.WriteString(projectsHeader) } @@ -607,7 +606,7 @@ func testAddRemoveQuotas(t *testing.T, enabled bool) { } projectsFile = tmpProjectsFile.Name() tmpProjectsFile.Close() - tmpProjidFile, err := ioutil.TempFile("", "projid") + tmpProjidFile, err := os.CreateTemp("", "projid") if err == nil { _, err = tmpProjidFile.WriteString(projidHeader) } diff --git a/pkg/volume/util/hostutil/hostutil_linux_test.go b/pkg/volume/util/hostutil/hostutil_linux_test.go index 3995362f866..c720f32900d 100644 --- a/pkg/volume/util/hostutil/hostutil_linux_test.go +++ b/pkg/volume/util/hostutil/hostutil_linux_test.go @@ -20,7 +20,6 @@ limitations under the License. package hostutil import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -193,12 +192,12 @@ func TestGetSELinuxSupport(t *testing.T) { } func writeFile(content string) (string, string, error) { - tempDir, err := ioutil.TempDir("", "mounter_shared_test") + tempDir, err := os.MkdirTemp("", "mounter_shared_test") if err != nil { return "", "", err } filename := filepath.Join(tempDir, "mountinfo") - err = ioutil.WriteFile(filename, []byte(content), 0600) + err = os.WriteFile(filename, []byte(content), 0600) if err != nil { os.RemoveAll(tempDir) return "", "", err diff --git a/pkg/volume/util/io_util.go b/pkg/volume/util/io_util.go index 8d65a6e48d2..d16adffa5b5 100644 --- a/pkg/volume/util/io_util.go +++ b/pkg/volume/util/io_util.go @@ -38,7 +38,7 @@ func NewIOHandler() IoUtil { } func (handler *osIOHandler) ReadFile(filename string) ([]byte, error) { - return ioutil.ReadFile(filename) + return os.ReadFile(filename) } func (handler *osIOHandler) ReadDir(dirname string) ([]os.FileInfo, error) { return ioutil.ReadDir(dirname) diff --git a/pkg/volume/util/nested_volumes_test.go b/pkg/volume/util/nested_volumes_test.go index b3da8b7628a..9e23106e9dc 100644 --- a/pkg/volume/util/nested_volumes_test.go +++ b/pkg/volume/util/nested_volumes_test.go @@ -17,7 +17,6 @@ limitations under the License. package util import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -202,7 +201,7 @@ func TestGetNestedMountpoints(t *testing.T) { }, } for _, test := range tc { - dir, err := ioutil.TempDir("", "TestMakeNestedMountpoints.") + dir, err := os.MkdirTemp("", "TestMakeNestedMountpoints.") if err != nil { t.Errorf("Unexpected error trying to create temp directory: %v", err) return diff --git a/pkg/volume/util/util.go b/pkg/volume/util/util.go index d8db43a19c7..05415215b16 100644 --- a/pkg/volume/util/util.go +++ b/pkg/volume/util/util.go @@ -19,7 +19,6 @@ package util import ( "context" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -173,7 +172,7 @@ func LoadPodFromFile(filePath string) (*v1.Pod, error) { if filePath == "" { return nil, fmt.Errorf("file path not specified") } - podDef, err := ioutil.ReadFile(filePath) + podDef, err := os.ReadFile(filePath) if err != nil { return nil, fmt.Errorf("failed to read file path %s: %+v", filePath, err) } diff --git a/pkg/volume/util/util_test.go b/pkg/volume/util/util_test.go index 97c3ca4535b..dc7a5334cdd 100644 --- a/pkg/volume/util/util_test.go +++ b/pkg/volume/util/util_test.go @@ -17,7 +17,6 @@ limitations under the License. package util import ( - "io/ioutil" "os" "reflect" "runtime" @@ -93,7 +92,7 @@ spec: } for _, test := range tests { - tempFile, err := ioutil.TempFile("", "podfile") + tempFile, err := os.CreateTemp("", "podfile") defer os.Remove(tempFile.Name()) if err != nil { t.Fatalf("cannot create temporary file: %v", err) diff --git a/pkg/volume/util/volumepathhandler/volume_path_handler.go b/pkg/volume/util/volumepathhandler/volume_path_handler.go index 1de7c52a55d..e632843d1e1 100644 --- a/pkg/volume/util/volumepathhandler/volume_path_handler.go +++ b/pkg/volume/util/volumepathhandler/volume_path_handler.go @@ -18,7 +18,6 @@ package volumepathhandler import ( "fmt" - "io/ioutil" "os" "path/filepath" @@ -279,12 +278,12 @@ func (v VolumePathHandler) IsDeviceBindMountExist(mapPath string) (bool, error) // GetDeviceBindMountRefs searches bind mounts under global map path func (v VolumePathHandler) GetDeviceBindMountRefs(devPath string, mapPath string) ([]string, error) { var refs []string - files, err := ioutil.ReadDir(mapPath) + files, err := os.ReadDir(mapPath) if err != nil { return nil, err } for _, file := range files { - if file.Mode()&os.ModeDevice != os.ModeDevice { + if file.Type()&os.ModeDevice != os.ModeDevice { continue } filename := file.Name() diff --git a/pkg/volume/util/volumepathhandler/volume_path_handler_linux.go b/pkg/volume/util/volumepathhandler/volume_path_handler_linux.go index 2e55df4cca8..541d0b65d35 100644 --- a/pkg/volume/util/volumepathhandler/volume_path_handler_linux.go +++ b/pkg/volume/util/volumepathhandler/volume_path_handler_linux.go @@ -22,7 +22,6 @@ package volumepathhandler import ( "errors" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -133,7 +132,7 @@ func getLoopDeviceFromSysfs(path string) (string, error) { backingFile := fmt.Sprintf("%s/loop/backing_file", device) // The contents of this file is the absolute path of "path". - data, err := ioutil.ReadFile(backingFile) + data, err := os.ReadFile(backingFile) if err != nil { continue }