mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
Merge pull request #16536 from rootfs/fix-mkfs
Auto commit by PR queue bot
This commit is contained in:
commit
9b60fb0c4f
@ -78,12 +78,15 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string,
|
||||
// It is possible that this disk is not formatted. Double check using diskLooksUnformatted
|
||||
notFormatted, err := mounter.diskLooksUnformatted(source)
|
||||
if err == nil && notFormatted {
|
||||
args := []string{source}
|
||||
// Disk is unformatted so format it.
|
||||
// Use 'ext4' as the default
|
||||
if len(fstype) == 0 {
|
||||
fstype = "ext4"
|
||||
}
|
||||
args := []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", source}
|
||||
if fstype == "ext4" || fstype == "ext3" {
|
||||
args = []string{"-E", "lazy_itable_init=0,lazy_journal_init=0", "-F", source}
|
||||
}
|
||||
cmd := mounter.Runner.Command("mkfs."+fstype, args...)
|
||||
_, err := cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
|
@ -61,7 +61,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
||||
fstype: "ext4",
|
||||
},
|
||||
|
||||
{ // Test that 'file' is called and fails
|
||||
{ // Test that 'lsblk' is called and fails
|
||||
fstype: "ext4",
|
||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")},
|
||||
execScripts: []ExecArgs{
|
||||
@ -69,7 +69,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
||||
},
|
||||
expectedError: fmt.Errorf("unknown filesystem type '(null)'"),
|
||||
},
|
||||
{ // Test that 'file' is called and confirms unformatted disk, format fails
|
||||
{ // Test that 'lsblk' is called and confirms unformatted disk, format fails
|
||||
fstype: "ext4",
|
||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'")},
|
||||
execScripts: []ExecArgs{
|
||||
@ -78,7 +78,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
||||
},
|
||||
expectedError: fmt.Errorf("formatting failed"),
|
||||
},
|
||||
{ // Test that 'file' is called and confirms unformatted disk, format passes, second mount fails
|
||||
{ // Test that 'lsblk' is called and confirms unformatted disk, format passes, second mount fails
|
||||
fstype: "ext4",
|
||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), fmt.Errorf("Still cannot mount")},
|
||||
execScripts: []ExecArgs{
|
||||
@ -87,7 +87,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
||||
},
|
||||
expectedError: fmt.Errorf("Still cannot mount"),
|
||||
},
|
||||
{ // Test that 'file' is called and confirms unformatted disk, format passes, second mount passes
|
||||
{ // Test that 'lsblk' is called and confirms unformatted disk, format passes, second mount passes
|
||||
fstype: "ext4",
|
||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil},
|
||||
execScripts: []ExecArgs{
|
||||
@ -96,7 +96,7 @@ func TestSafeFormatAndMount(t *testing.T) {
|
||||
},
|
||||
expectedError: nil,
|
||||
},
|
||||
{ // Test that 'file' is called and confirms unformatted disk, format passes, second mount passes with ext3
|
||||
{ // Test that 'lsblk' is called and confirms unformatted disk, format passes, second mount passes with ext3
|
||||
fstype: "ext3",
|
||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil},
|
||||
execScripts: []ExecArgs{
|
||||
@ -105,6 +105,16 @@ func TestSafeFormatAndMount(t *testing.T) {
|
||||
},
|
||||
expectedError: nil,
|
||||
},
|
||||
{ // Test that 'lsblk' is called and confirms unformatted disk, format passes, second mount passes
|
||||
// test that none ext4 fs does not get called with ext4 options.
|
||||
fstype: "xfs",
|
||||
mountErrs: []error{fmt.Errorf("unknown filesystem type '(null)'"), nil},
|
||||
execScripts: []ExecArgs{
|
||||
{"lsblk", []string{"-nd", "-o", "FSTYPE", "/dev/foo"}, "", nil},
|
||||
{"mkfs.xfs", []string{"/dev/foo"}, "", nil},
|
||||
},
|
||||
expectedError: nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user