Skip to content

Commit

Permalink
Merge pull request #2757 from andyzhangx/noformat-workaround-1.29
Browse files Browse the repository at this point in the history
[release-1.29] feat: add noformat option to fix fsck stuck issue on Linux node
  • Loading branch information
andyzhangx authored Dec 23, 2024
2 parents 17708db + 1d9c415 commit b4a3431
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/azuredisk/azure_common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func findDiskByLun(lun int, io azureutils.IOHandler, _ *mount.SafeFormatAndMount
}

func formatAndMount(source, target, fstype string, options []string, m *mount.SafeFormatAndMount) error {
if newOptions, exists := azureutils.RemoveOptionIfExists(options, "noformat"); exists {
klog.V(2).Infof("formatAndMount - skip format for %s, old options: %v, new options: %v", target, options, newOptions)
return m.Mount(source, target, fstype, newOptions)
}
return m.FormatAndMount(source, target, fstype, options)
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,3 +862,14 @@ func RunPowershellCmd(command string, envs ...string) ([]byte, error) {
klog.V(6).Infof("Executing command: %q", cmd.String())
return cmd.CombinedOutput()
}

// RemoveOptionIfExists removes the given option from the list of options
// return the new list and a boolean indicating whether the option was found.
func RemoveOptionIfExists(options []string, removeOption string) ([]string, bool) {
for i, option := range options {
if option == removeOption {
return append(options[:i], options[i+1:]...), true
}
}
return options, false
}
61 changes: 61 additions & 0 deletions pkg/azureutils/azure_disk_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1987,3 +1987,64 @@ func TestGetRetryAfterSeconds(t *testing.T) {
}
}
}

func TestRemoveOptionIfExists(t *testing.T) {
tests := []struct {
desc string
options []string
removeOption string
expectedOptions []string
expected bool
}{
{
desc: "nil options",
removeOption: "option",
expected: false,
},
{
desc: "empty options",
options: []string{},
removeOption: "option",
expectedOptions: []string{},
expected: false,
},
{
desc: "option not found",
options: []string{"option1", "option2"},
removeOption: "option",
expectedOptions: []string{"option1", "option2"},
expected: false,
},
{
desc: "option found in the last element",
options: []string{"option1", "option2", "option"},
removeOption: "option",
expectedOptions: []string{"option1", "option2"},
expected: true,
},
{
desc: "option found in the first element",
options: []string{"option", "option1", "option2"},
removeOption: "option",
expectedOptions: []string{"option1", "option2"},
expected: true,
},
{
desc: "option found in the middle element",
options: []string{"option1", "option", "option2"},
removeOption: "option",
expectedOptions: []string{"option1", "option2"},
expected: true,
},
}

for _, test := range tests {
result, exists := RemoveOptionIfExists(test.options, test.removeOption)
if !reflect.DeepEqual(result, test.expectedOptions) {
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, result, test.expectedOptions)
}
if exists != test.expected {
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, exists, test.expected)
}
}
}

0 comments on commit b4a3431

Please sign in to comment.