mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-06 13:26:26 +00:00
Make parallel restore configurable
Signed-off-by: Ming Qiu <mqiu@vmware.com>
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
const (
|
||||
ParallelFilesUpload = "ParallelFilesUpload"
|
||||
WriteSparseFiles = "WriteSparseFiles"
|
||||
RestoreConcurrency = "ParallelFilesDownload"
|
||||
)
|
||||
|
||||
func StoreBackupConfig(config *velerov1api.UploaderConfigForBackup) map[string]string {
|
||||
@@ -42,6 +43,10 @@ func StoreRestoreConfig(config *velerov1api.UploaderConfigForRestore) map[string
|
||||
} else {
|
||||
data[WriteSparseFiles] = strconv.FormatBool(false)
|
||||
}
|
||||
|
||||
if config.ParallelFilesDownload > 0 {
|
||||
data[RestoreConcurrency] = strconv.Itoa(config.ParallelFilesDownload)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -68,3 +73,15 @@ func GetWriteSparseFiles(uploaderCfg map[string]string) (bool, error) {
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func GetRestoreConcurrency(uploaderCfg map[string]string) (int, error) {
|
||||
restoreConcurrency, ok := uploaderCfg[RestoreConcurrency]
|
||||
if ok {
|
||||
restoreConcurrencyInt, err := strconv.Atoi(restoreConcurrency)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "failed to parse RestoreConcurrency config")
|
||||
}
|
||||
return restoreConcurrencyInt, nil
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
@@ -78,6 +78,16 @@ func TestStoreRestoreConfig(t *testing.T) {
|
||||
WriteSparseFiles: "false", // Assuming default value is false for nil case
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Parallel is set",
|
||||
config: &velerov1api.UploaderConfigForRestore{
|
||||
ParallelFilesDownload: 5,
|
||||
},
|
||||
expectedData: map[string]string{
|
||||
RestoreConcurrency: "5",
|
||||
WriteSparseFiles: "false",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
@@ -180,3 +190,53 @@ func TestGetWriteSparseFiles(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRestoreConcurrency(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Name string
|
||||
UploaderCfg map[string]string
|
||||
ExpectedResult int
|
||||
ExpectedError bool
|
||||
ExpectedErrorMsg string
|
||||
}{
|
||||
{
|
||||
Name: "Valid Configuration",
|
||||
UploaderCfg: map[string]string{RestoreConcurrency: "10"},
|
||||
ExpectedResult: 10,
|
||||
ExpectedError: false,
|
||||
},
|
||||
{
|
||||
Name: "Missing Configuration",
|
||||
UploaderCfg: map[string]string{},
|
||||
ExpectedResult: 0,
|
||||
ExpectedError: false,
|
||||
},
|
||||
{
|
||||
Name: "Invalid Configuration",
|
||||
UploaderCfg: map[string]string{RestoreConcurrency: "not_an_integer"},
|
||||
ExpectedResult: 0,
|
||||
ExpectedError: true,
|
||||
ExpectedErrorMsg: "failed to parse RestoreConcurrency config: strconv.Atoi: parsing \"not_an_integer\": invalid syntax",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
result, err := GetRestoreConcurrency(tc.UploaderCfg)
|
||||
|
||||
if tc.ExpectedError {
|
||||
if err.Error() != tc.ExpectedErrorMsg {
|
||||
t.Errorf("Expected error message %s, but got %s", tc.ExpectedErrorMsg, err.Error())
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if result != tc.ExpectedResult {
|
||||
t.Errorf("Expected result %d, but got %d", tc.ExpectedResult, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user