mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-07 05:46:37 +00:00
Make parallel restore configurable
Signed-off-by: Ming Qiu <mqiu@vmware.com>
This commit is contained in:
@@ -99,6 +99,7 @@ type CreateOptions struct {
|
||||
ItemOperationTimeout time.Duration
|
||||
ResourceModifierConfigMap string
|
||||
WriteSparseFiles flag.OptionalBool
|
||||
ParallelFilesDownload int
|
||||
client kbclient.WithWatch
|
||||
}
|
||||
|
||||
@@ -151,6 +152,8 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) {
|
||||
|
||||
f = flags.VarPF(&o.WriteSparseFiles, "write-sparse-files", "", "Whether to write sparse files during restoring volumes")
|
||||
f.NoOptDefVal = cmd.TRUE
|
||||
|
||||
flags.IntVar(&o.ParallelFilesDownload, "parallel-files-download", 0, "The number of restore operations to run in parallel. If set to 0, the default parallelism will be the number of CPUs for the node that node agent pod is running.")
|
||||
}
|
||||
|
||||
func (o *CreateOptions) Complete(args []string, f client.Factory) error {
|
||||
@@ -200,6 +203,10 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto
|
||||
return errors.New("existing-resource-policy has invalid value, it accepts only none, update as value")
|
||||
}
|
||||
|
||||
if o.ParallelFilesDownload < 0 {
|
||||
return errors.New("parallel-files-download cannot be negative")
|
||||
}
|
||||
|
||||
switch {
|
||||
case o.BackupName != "":
|
||||
backup := new(api.Backup)
|
||||
@@ -324,7 +331,8 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error {
|
||||
Duration: o.ItemOperationTimeout,
|
||||
},
|
||||
UploaderConfig: &api.UploaderConfigForRestore{
|
||||
WriteSparseFiles: o.WriteSparseFiles.Value,
|
||||
WriteSparseFiles: o.WriteSparseFiles.Value,
|
||||
ParallelFilesDownload: o.ParallelFilesDownload,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func TestCreateCommand(t *testing.T) {
|
||||
allowPartiallyFailed := "true"
|
||||
itemOperationTimeout := "10m0s"
|
||||
writeSparseFiles := "true"
|
||||
|
||||
parallel := 2
|
||||
flags := new(pflag.FlagSet)
|
||||
o := NewCreateOptions()
|
||||
o.BindFlags(flags)
|
||||
@@ -108,6 +108,7 @@ func TestCreateCommand(t *testing.T) {
|
||||
flags.Parse([]string{"--allow-partially-failed", allowPartiallyFailed})
|
||||
flags.Parse([]string{"--item-operation-timeout", itemOperationTimeout})
|
||||
flags.Parse([]string{"--write-sparse-files", writeSparseFiles})
|
||||
flags.Parse([]string{"--parallel-files-download", "2"})
|
||||
client := velerotest.NewFakeControllerRuntimeClient(t).(kbclient.WithWatch)
|
||||
|
||||
f.On("Namespace").Return(mock.Anything)
|
||||
@@ -144,6 +145,7 @@ func TestCreateCommand(t *testing.T) {
|
||||
require.Equal(t, allowPartiallyFailed, o.AllowPartiallyFailed.String())
|
||||
require.Equal(t, itemOperationTimeout, o.ItemOperationTimeout.String())
|
||||
require.Equal(t, writeSparseFiles, o.WriteSparseFiles.String())
|
||||
require.Equal(t, parallel, o.ParallelFilesDownload)
|
||||
})
|
||||
|
||||
t.Run("create a restore from schedule", func(t *testing.T) {
|
||||
|
||||
@@ -178,10 +178,7 @@ func DescribeRestore(ctx context.Context, kbClient kbclient.Client, restore *vel
|
||||
d.Println()
|
||||
d.Printf("Preserve Service NodePorts:\t%s\n", BoolPointerString(restore.Spec.PreserveNodePorts, "false", "true", "auto"))
|
||||
|
||||
if restore.Spec.UploaderConfig != nil && boolptr.IsSetToTrue(restore.Spec.UploaderConfig.WriteSparseFiles) {
|
||||
d.Println()
|
||||
DescribeUploaderConfigForRestore(d, restore.Spec)
|
||||
}
|
||||
describeUploaderConfigForRestore(d, restore.Spec)
|
||||
|
||||
d.Println()
|
||||
describeRestoreItemOperations(ctx, kbClient, d, restore, details, insecureSkipTLSVerify, caCertFile)
|
||||
@@ -199,10 +196,18 @@ func DescribeRestore(ctx context.Context, kbClient kbclient.Client, restore *vel
|
||||
})
|
||||
}
|
||||
|
||||
// DescribeUploaderConfigForRestore describes uploader config in human-readable format
|
||||
func DescribeUploaderConfigForRestore(d *Describer, spec velerov1api.RestoreSpec) {
|
||||
d.Printf("Uploader config:\n")
|
||||
d.Printf("\tWrite Sparse Files:\t%T\n", boolptr.IsSetToTrue(spec.UploaderConfig.WriteSparseFiles))
|
||||
// describeUploaderConfigForRestore describes uploader config in human-readable format
|
||||
func describeUploaderConfigForRestore(d *Describer, spec velerov1api.RestoreSpec) {
|
||||
if spec.UploaderConfig != nil {
|
||||
d.Println()
|
||||
d.Printf("Uploader config:\n")
|
||||
if boolptr.IsSetToTrue(spec.UploaderConfig.WriteSparseFiles) {
|
||||
d.Printf("\tWrite Sparse Files:\t%v\n", boolptr.IsSetToTrue(spec.UploaderConfig.WriteSparseFiles))
|
||||
}
|
||||
if spec.UploaderConfig.ParallelFilesDownload > 0 {
|
||||
d.Printf("\tParallel Restore:\t%d\n", spec.UploaderConfig.ParallelFilesDownload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func describeRestoreItemOperations(ctx context.Context, kbClient kbclient.Client, d *Describer, restore *velerov1api.Restore, details bool, insecureSkipTLSVerify bool, caCertPath string) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/builder"
|
||||
"github.com/vmware-tanzu/velero/pkg/itemoperation"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/results"
|
||||
)
|
||||
|
||||
@@ -181,3 +182,58 @@ func TestDescribePodVolumeRestores(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestDescribeUploaderConfigForRestore(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
spec velerov1api.RestoreSpec
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "UploaderConfigNil",
|
||||
spec: velerov1api.RestoreSpec{}, // Create a RestoreSpec with nil UploaderConfig
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
name: "test",
|
||||
spec: velerov1api.RestoreSpec{
|
||||
UploaderConfig: &velerov1api.UploaderConfigForRestore{
|
||||
WriteSparseFiles: boolptr.True(),
|
||||
ParallelFilesDownload: 4,
|
||||
},
|
||||
},
|
||||
expected: "\nUploader config:\n Write Sparse Files: true\n Parallel Restore: 4\n",
|
||||
},
|
||||
{
|
||||
name: "WriteSparseFiles test",
|
||||
spec: velerov1api.RestoreSpec{
|
||||
UploaderConfig: &velerov1api.UploaderConfigForRestore{
|
||||
WriteSparseFiles: boolptr.True(),
|
||||
},
|
||||
},
|
||||
expected: "\nUploader config:\n Write Sparse Files: true\n",
|
||||
},
|
||||
{
|
||||
name: "ParallelFilesDownload test",
|
||||
spec: velerov1api.RestoreSpec{
|
||||
UploaderConfig: &velerov1api.UploaderConfigForRestore{
|
||||
ParallelFilesDownload: 4,
|
||||
},
|
||||
},
|
||||
expected: "\nUploader config:\n Parallel Restore: 4\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
d := &Describer{
|
||||
Prefix: "",
|
||||
out: &tabwriter.Writer{},
|
||||
buf: &bytes.Buffer{},
|
||||
}
|
||||
d.out.Init(d.buf, 0, 8, 2, ' ', 0)
|
||||
describeUploaderConfigForRestore(d, tc.spec)
|
||||
d.out.Flush()
|
||||
assert.Equal(t, tc.expected, d.buf.String(), "Output should match expected")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user