diff --git a/staging/src/k8s.io/mount-utils/mount_helper_test.go b/staging/src/k8s.io/mount-utils/mount_helper_test.go index 288fff803e1..1e506bb2edf 100644 --- a/staging/src/k8s.io/mount-utils/mount_helper_test.go +++ b/staging/src/k8s.io/mount-utils/mount_helper_test.go @@ -27,13 +27,12 @@ import ( ) func TestDoCleanupMountPoint(t *testing.T) { - if runtime.GOOS == "darwin" { t.Skipf("not supported on GOOS=%s", runtime.GOOS) } const testMount = "test-mount" - const defaultPerm = 0750 + const defaultPerm = 0o750 tests := map[string]struct { corruptedMnt bool @@ -106,7 +105,6 @@ func TestDoCleanupMountPoint(t *testing.T) { for name, tt := range tests { t.Run(name, func(t *testing.T) { - tmpDir, err := ioutil.TempDir("", "unmount-mount-point-test") if err != nil { t.Fatalf("failed to create tmpdir: %v", err) diff --git a/staging/src/k8s.io/mount-utils/mount_helper_unix_test.go b/staging/src/k8s.io/mount-utils/mount_helper_unix_test.go index 6fbc79e3e4d..973b8b640b8 100644 --- a/staging/src/k8s.io/mount-utils/mount_helper_unix_test.go +++ b/staging/src/k8s.io/mount-utils/mount_helper_unix_test.go @@ -33,7 +33,7 @@ func writeFile(content string) (string, string, error) { return "", "", err } filename := filepath.Join(tempDir, "mountinfo") - err = ioutil.WriteFile(filename, []byte(content), 0600) + err = ioutil.WriteFile(filename, []byte(content), 0o600) if err != nil { os.RemoveAll(tempDir) return "", "", err @@ -42,8 +42,7 @@ func writeFile(content string) (string, string, error) { } func TestParseMountInfo(t *testing.T) { - info := - `62 0 253:0 / / rw,relatime shared:1 - ext4 /dev/mapper/ssd-root rw,seclabel,data=ordered + info := `62 0 253:0 / / rw,relatime shared:1 - ext4 /dev/mapper/ssd-root rw,seclabel,data=ordered 78 62 0:41 / /tmp rw,nosuid,nodev shared:30 - tmpfs tmpfs rw,seclabel 80 62 0:42 / /var/lib/nfs/rpc_pipefs rw,relatime shared:31 - rpc_pipefs sunrpc rw 82 62 0:43 / /var/lib/foo rw,relatime shared:32 - tmpfs tmpfs rw diff --git a/staging/src/k8s.io/mount-utils/mount_linux.go b/staging/src/k8s.io/mount-utils/mount_linux.go index f0125fcb489..dc861734ad5 100644 --- a/staging/src/k8s.io/mount-utils/mount_linux.go +++ b/staging/src/k8s.io/mount-utils/mount_linux.go @@ -810,7 +810,6 @@ func tryUnmount(target string, withSafeNotMountedBehavior bool, unmountTimeout t func forceUmount(target string, withSafeNotMountedBehavior bool) error { command := exec.Command("umount", "-f", target) output, err := command.CombinedOutput() - if err != nil { return checkUmountError(target, command, output, err, withSafeNotMountedBehavior) } diff --git a/staging/src/k8s.io/mount-utils/mount_linux_test.go b/staging/src/k8s.io/mount-utils/mount_linux_test.go index 5f7a2246668..5ea22e1ac4c 100644 --- a/staging/src/k8s.io/mount-utils/mount_linux_test.go +++ b/staging/src/k8s.io/mount-utils/mount_linux_test.go @@ -36,8 +36,7 @@ import ( ) func TestReadProcMountsFrom(t *testing.T) { - successCase := - `/dev/0 /path/to/0 type0 flags 0 0 + successCase := `/dev/0 /path/to/0 type0 flags 0 0 /dev/1 /path/to/1 type1 flags 1 1 /dev/2 /path/to/2 type2 flags,1,2=3 2 2 ` @@ -148,10 +147,14 @@ func setEquivalent(set1, set2 []string) bool { func TestGetDeviceNameFromMount(t *testing.T) { fm := NewFakeMounter( []MountPoint{ - {Device: "/dev/disk/by-path/prefix-lun-1", - Path: "/mnt/111"}, - {Device: "/dev/disk/by-path/prefix-lun-1", - Path: "/mnt/222"}, + { + Device: "/dev/disk/by-path/prefix-lun-1", + Path: "/mnt/111", + }, + { + Device: "/dev/disk/by-path/prefix-lun-1", + Path: "/mnt/222", + }, }) tests := []struct { @@ -203,7 +206,6 @@ func TestGetMountRefsByDev(t *testing.T) { } for i, test := range tests { - if refs, err := getMountRefsByDev(fm, test.mountPath); err != nil || !setEquivalent(test.expectedRefs, refs) { t.Errorf("%d. getMountRefsByDev(%q) = %v, %v; expected %v, nil", i, test.mountPath, refs, err, test.expectedRefs) } @@ -294,7 +296,6 @@ func TestPathWithinBase(t *testing.T) { if PathWithinBase(test.fullPath, test.basePath) != test.expected { t.Errorf("test %q failed: expected %v", test.name, test.expected) } - } } @@ -422,8 +423,10 @@ func TestSearchMountPoints(t *testing.T) { 62 25 7:1 / /var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test rw,relatime shared:38 - ext4 /dev/loop1 rw,data=ordered 95 25 7:1 / /var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test rw,relatime shared:38 - ext4 /dev/loop1 rw,data=ordered `, - []string{"/var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test", - "/var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test"}, + []string{ + "/var/lib/kubelet/pods/f19fe4e2-5a63-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test", + "/var/lib/kubelet/pods/4854a48b-5a64-11e8-962f-000c29bb0377/volumes/kubernetes.io~local-volume/local-pv-test", + }, nil, }, } @@ -459,7 +462,6 @@ func TestSensitiveMountOptions(t *testing.T) { mountFlags []string }{ { - source: "mySrc", target: "myTarget", fstype: "myFS", @@ -468,7 +470,6 @@ func TestSensitiveMountOptions(t *testing.T) { mountFlags: []string{}, }, { - source: "mySrc", target: "myTarget", fstype: "myFS", @@ -477,7 +478,6 @@ func TestSensitiveMountOptions(t *testing.T) { mountFlags: []string{}, }, { - source: "mySrc", target: "myTarget", fstype: "myFS", @@ -486,7 +486,6 @@ func TestSensitiveMountOptions(t *testing.T) { mountFlags: []string{}, }, { - source: "mySrc", target: "myTarget", fstype: "myFS", diff --git a/staging/src/k8s.io/mount-utils/mount_test.go b/staging/src/k8s.io/mount-utils/mount_test.go index 4fa6484d59e..5823bbcce19 100644 --- a/staging/src/k8s.io/mount-utils/mount_test.go +++ b/staging/src/k8s.io/mount-utils/mount_test.go @@ -38,7 +38,6 @@ func TestMakeBindOpts(t *testing.T) { []string{}, }, { - []string{"bind", "vers=2", "ro", "_netdev"}, true, []string{"bind", "_netdev"}, @@ -80,7 +79,6 @@ func TestMakeBindOptsSensitive(t *testing.T) { expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"}, }, { - mountOptions: []string{"vers=2", "ro", "_netdev"}, sensitiveMountOptions: []string{"user=foo", "pass=bar", "bind"}, isBind: true, @@ -105,7 +103,6 @@ func TestMakeBindOptsSensitive(t *testing.T) { expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"}, }, { - mountOptions: []string{"vers=2", "bind", "ro", "_netdev"}, sensitiveMountOptions: []string{"user=foo", "remount", "pass=bar"}, isBind: true, @@ -114,7 +111,6 @@ func TestMakeBindOptsSensitive(t *testing.T) { expectedSensitiveRemountOpts: []string{"user=foo", "pass=bar"}, }, { - mountOptions: []string{"vers=2", "bind", "ro", "_netdev"}, sensitiveMountOptions: []string{"user=foo", "remount", "pass=bar"}, isBind: true, diff --git a/staging/src/k8s.io/mount-utils/mount_windows.go b/staging/src/k8s.io/mount-utils/mount_windows.go index 4f2b7aee873..e5a03ecff83 100644 --- a/staging/src/k8s.io/mount-utils/mount_windows.go +++ b/staging/src/k8s.io/mount-utils/mount_windows.go @@ -82,11 +82,11 @@ func (mounter *Mounter) MountSensitive(source string, target string, fstype stri if source == "tmpfs" { klog.V(3).Infof("mounting source (%q), target (%q), with options (%q)", source, target, sanitizedOptionsForLogging) - return os.MkdirAll(target, 0755) + return os.MkdirAll(target, 0o755) } parentDir := filepath.Dir(target) - if err := os.MkdirAll(parentDir, 0755); err != nil { + if err := os.MkdirAll(parentDir, 0o755); err != nil { return err } diff --git a/staging/src/k8s.io/mount-utils/mount_windows_test.go b/staging/src/k8s.io/mount-utils/mount_windows_test.go index 2e1b2d7cc02..524ee5f7bae 100644 --- a/staging/src/k8s.io/mount-utils/mount_windows_test.go +++ b/staging/src/k8s.io/mount-utils/mount_windows_test.go @@ -147,7 +147,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) { "Dir", "", func(base, fileName, targetLinkName string) error { - return os.Mkdir(filepath.Join(base, fileName), 0750) + return os.Mkdir(filepath.Join(base, fileName), 0o750) }, true, false, @@ -166,7 +166,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) { "targetSymLink", func(base, fileName, targetLinkName string) error { targeLinkPath := filepath.Join(base, targetLinkName) - if err := os.Mkdir(targeLinkPath, 0750); err != nil { + if err := os.Mkdir(targeLinkPath, 0o750); err != nil { return err } @@ -184,7 +184,7 @@ func TestIsLikelyNotMountPoint(t *testing.T) { "targetSymLink2", func(base, fileName, targetLinkName string) error { targeLinkPath := filepath.Join(base, targetLinkName) - if err := os.Mkdir(targeLinkPath, 0750); err != nil { + if err := os.Mkdir(targeLinkPath, 0o750); err != nil { return err } diff --git a/staging/src/k8s.io/mount-utils/resizefs_linux.go b/staging/src/k8s.io/mount-utils/resizefs_linux.go index 81386fef878..3a5fa1be7cb 100644 --- a/staging/src/k8s.io/mount-utils/resizefs_linux.go +++ b/staging/src/k8s.io/mount-utils/resizefs_linux.go @@ -45,7 +45,6 @@ func NewResizeFs(exec utilexec.Interface) *ResizeFs { // Resize perform resize of file system func (resizefs *ResizeFs) Resize(devicePath string, deviceMountPath string) (bool, error) { format, err := getDiskFormat(resizefs.exec, devicePath) - if err != nil { formatErr := fmt.Errorf("ResizeFS.Resize - error checking format for device %s: %v", devicePath, err) return false, formatErr @@ -78,7 +77,6 @@ func (resizefs *ResizeFs) extResize(devicePath string) (bool, error) { resizeError := fmt.Errorf("resize of device %s failed: %v. resize2fs output: %s", devicePath, err, string(output)) return false, resizeError - } func (resizefs *ResizeFs) xfsResize(deviceMountPath string) (bool, error) { @@ -161,6 +159,7 @@ func (resizefs *ResizeFs) NeedResize(devicePath string, deviceMountPath string) } return true, nil } + func (resizefs *ResizeFs) getDeviceSize(devicePath string) (uint64, error) { output, err := resizefs.exec.Command(blockDev, "--getsize64", devicePath).CombinedOutput() outStr := strings.TrimSpace(string(output)) diff --git a/staging/src/k8s.io/mount-utils/resizefs_linux_test.go b/staging/src/k8s.io/mount-utils/resizefs_linux_test.go index 98f13d3cfe4..5acc1632e46 100644 --- a/staging/src/k8s.io/mount-utils/resizefs_linux_test.go +++ b/staging/src/k8s.io/mount-utils/resizefs_linux_test.go @@ -28,8 +28,7 @@ import ( ) func TestGetFileSystemSize(t *testing.T) { - cmdOutputSuccessXfs := - ` + cmdOutputSuccessXfs := ` statfs.f_bsize = 4096 statfs.f_blocks = 1832448 statfs.f_bavail = 1822366 @@ -50,8 +49,7 @@ func TestGetFileSystemSize(t *testing.T) { counts.freeino = 61 counts.allocino = 64 ` - cmdOutputNoDataXfs := - ` + cmdOutputNoDataXfs := ` statfs.f_bsize = 4096 statfs.f_blocks = 1832448 statfs.f_bavail = 1822366 @@ -70,8 +68,7 @@ func TestGetFileSystemSize(t *testing.T) { counts.freeino = 61 counts.allocino = 64 ` - cmdOutputSuccessExt4 := - ` + cmdOutputSuccessExt4 := ` Filesystem volume name: cloudimg-rootfs Last mounted on: / Filesystem UUID: testUUID @@ -121,8 +118,7 @@ Journal start: 1 Journal checksum type: crc32c Journal checksum: 0xb7df3c6e ` - cmdOutputNoDataExt4 := - `Filesystem volume name: cloudimg-rootfs + cmdOutputNoDataExt4 := `Filesystem volume name: cloudimg-rootfs Last mounted on: / Filesystem UUID: testUUID Filesystem magic number: 0xEF53 @@ -169,8 +165,7 @@ Journal start: 1 Journal checksum type: crc32c Journal checksum: 0xb7df3c6e ` - cmdOutputSuccessBtrfs := - `superblock: bytenr=65536, device=/dev/loop0 + cmdOutputSuccessBtrfs := `superblock: bytenr=65536, device=/dev/loop0 --------------------------------------------------------- csum_type 0 (crc32c) csum_size 4 @@ -279,8 +274,7 @@ backup_roots[4]: backup_num_devices: 1 ` - cmdOutputNoDataBtrfs := - `superblock: bytenr=65536, device=/dev/loop0 + cmdOutputNoDataBtrfs := `superblock: bytenr=65536, device=/dev/loop0 --------------------------------------------------------- csum_type 0 (crc32c) csum_size 4 diff --git a/staging/src/k8s.io/mount-utils/safe_format_and_mount_test.go b/staging/src/k8s.io/mount-utils/safe_format_and_mount_test.go index 7d70eb0a98a..99a87ae43e2 100644 --- a/staging/src/k8s.io/mount-utils/safe_format_and_mount_test.go +++ b/staging/src/k8s.io/mount-utils/safe_format_and_mount_test.go @@ -261,7 +261,7 @@ func TestSafeFormatAndMount(t *testing.T) { t.Errorf("test \"%s\" the directory was not mounted", test.description) } - //check that the correct device was mounted + // check that the correct device was mounted mountedDevice, _, err := GetDeviceNameFromMount(fakeMounter.FakeMounter, dest) if err != nil || mountedDevice != device { t.Errorf("test \"%s\" the correct device was not mounted", test.description)