mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #14109 from BugRoger/replace_file_with_lsblk_command_for_volume_checks
Auto commit by PR queue bot
This commit is contained in:
commit
755ff241e3
@ -98,9 +98,10 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string,
|
|||||||
|
|
||||||
// diskLooksUnformatted uses 'file' to see if the given disk is unformated
|
// diskLooksUnformatted uses 'file' to see if the given disk is unformated
|
||||||
func (mounter *SafeFormatAndMount) diskLooksUnformatted(disk string) (bool, error) {
|
func (mounter *SafeFormatAndMount) diskLooksUnformatted(disk string) (bool, error) {
|
||||||
args := []string{"-L", "--special-files", disk}
|
args := []string{"-nd", "-o", "FSTYPE", disk}
|
||||||
cmd := mounter.Runner.Command("file", args...)
|
cmd := mounter.Runner.Command("lsblk", args...)
|
||||||
dataOut, err := cmd.CombinedOutput()
|
dataOut, err := cmd.CombinedOutput()
|
||||||
|
output := strings.TrimSpace(string(dataOut))
|
||||||
|
|
||||||
// TODO (#13212): check if this disk has partitions and return false, and
|
// TODO (#13212): check if this disk has partitions and return false, and
|
||||||
// an error if so.
|
// an error if so.
|
||||||
@ -109,7 +110,7 @@ func (mounter *SafeFormatAndMount) diskLooksUnformatted(disk string) (bool, erro
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return !strings.Contains(string(dataOut), "filesystem"), nil
|
return output == "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a mount.Interface for the current system.
|
// New returns a mount.Interface for the current system.
|
||||||
|
@ -65,7 +65,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
|||||||
fstype: "ext4",
|
fstype: "ext4",
|
||||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")},
|
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")},
|
||||||
execScripts: []ExecArgs{
|
execScripts: []ExecArgs{
|
||||||
{"file", []string{"-L", "--special-files", "/dev/foo"}, "ext4 filesystem", nil},
|
{"lsblk", []string{"-nd", "-o", "FSTYPE", "/dev/foo"}, "ext4", nil},
|
||||||
},
|
},
|
||||||
expectedError: fmt.Errorf("unknown filesystem type '(null)'"),
|
expectedError: fmt.Errorf("unknown filesystem type '(null)'"),
|
||||||
},
|
},
|
||||||
@ -73,7 +73,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
|||||||
fstype: "ext4",
|
fstype: "ext4",
|
||||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")},
|
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")},
|
||||||
execScripts: []ExecArgs{
|
execScripts: []ExecArgs{
|
||||||
{"file", []string{"-L", "--special-files", "/dev/foo"}, "data", nil},
|
{"lsblk", []string{"-nd", "-o", "FSTYPE", "/dev/foo"}, "", nil},
|
||||||
{"mkfs.ext4", []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", "/dev/foo"}, "", fmt.Errorf("formatting failed")},
|
{"mkfs.ext4", []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", "/dev/foo"}, "", fmt.Errorf("formatting failed")},
|
||||||
},
|
},
|
||||||
expectedError: fmt.Errorf("formatting failed"),
|
expectedError: fmt.Errorf("formatting failed"),
|
||||||
@ -82,7 +82,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
|||||||
fstype: "ext4",
|
fstype: "ext4",
|
||||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), fmt.Errorf("Still cannot mount")},
|
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), fmt.Errorf("Still cannot mount")},
|
||||||
execScripts: []ExecArgs{
|
execScripts: []ExecArgs{
|
||||||
{"file", []string{"-L", "--special-files", "/dev/foo"}, "data", nil},
|
{"lsblk", []string{"-nd", "-o", "FSTYPE", "/dev/foo"}, "", nil},
|
||||||
{"mkfs.ext4", []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", "/dev/foo"}, "", nil},
|
{"mkfs.ext4", []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", "/dev/foo"}, "", nil},
|
||||||
},
|
},
|
||||||
expectedError: fmt.Errorf("Still cannot mount"),
|
expectedError: fmt.Errorf("Still cannot mount"),
|
||||||
@ -91,7 +91,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
|||||||
fstype: "ext4",
|
fstype: "ext4",
|
||||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil},
|
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil},
|
||||||
execScripts: []ExecArgs{
|
execScripts: []ExecArgs{
|
||||||
{"file", []string{"-L", "--special-files", "/dev/foo"}, "data", nil},
|
{"lsblk", []string{"-nd", "-o", "FSTYPE", "/dev/foo"}, "", nil},
|
||||||
{"mkfs.ext4", []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", "/dev/foo"}, "", nil},
|
{"mkfs.ext4", []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", "/dev/foo"}, "", nil},
|
||||||
},
|
},
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
@ -100,7 +100,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
|||||||
fstype: "ext3",
|
fstype: "ext3",
|
||||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil},
|
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil},
|
||||||
execScripts: []ExecArgs{
|
execScripts: []ExecArgs{
|
||||||
{"file", []string{"-L", "--special-files", "/dev/foo"}, "data", nil},
|
{"lsblk", []string{"-nd", "-o", "FSTYPE", "/dev/foo"}, "", nil},
|
||||||
{"mkfs.ext3", []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", "/dev/foo"}, "", nil},
|
{"mkfs.ext3", []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", "/dev/foo"}, "", nil},
|
||||||
},
|
},
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
|
Loading…
Reference in New Issue
Block a user