From 9f2f5635688558db86cfbc95ca32c2fea51bc5cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wenkai=20Yin=28=E5=B0=B9=E6=96=87=E5=BC=80=29?= Date: Wed, 7 Jun 2023 15:58:43 +0800 Subject: [PATCH] Add data mover related options in CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add data mover related options in CLI Fixes #6128 Signed-off-by: Wenkai Yin(尹文开) --- changelogs/unreleased/6365-ywk253100 | 1 + pkg/builder/backup_builder.go | 12 ++++++++++++ pkg/cmd/cli/backup/create.go | 12 +++++++++++- pkg/cmd/util/output/backup_describer.go | 7 +++++++ pkg/cmd/util/output/backup_structured_describer.go | 9 +++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/6365-ywk253100 diff --git a/changelogs/unreleased/6365-ywk253100 b/changelogs/unreleased/6365-ywk253100 new file mode 100644 index 000000000..1c22e6963 --- /dev/null +++ b/changelogs/unreleased/6365-ywk253100 @@ -0,0 +1 @@ +Add data mover related options in CLI \ No newline at end of file diff --git a/pkg/builder/backup_builder.go b/pkg/builder/backup_builder.go index bfaf5e3a7..275852bd1 100644 --- a/pkg/builder/backup_builder.go +++ b/pkg/builder/backup_builder.go @@ -287,3 +287,15 @@ func (b *BackupBuilder) ResourcePolicies(name string) *BackupBuilder { b.object.Spec.ResourcePolicy = &v1.TypedLocalObjectReference{Kind: resourcepolicies.ConfigmapRefType, Name: name} return b } + +// SnapshotMoveData sets the Backup's "snapshot move data" flag. +func (b *BackupBuilder) SnapshotMoveData(val bool) *BackupBuilder { + b.object.Spec.SnapshotMoveData = &val + return b +} + +// DataMover sets the Backup's data mover +func (b *BackupBuilder) DataMover(name string) *BackupBuilder { + b.object.Spec.DataMover = name + return b +} diff --git a/pkg/cmd/cli/backup/create.go b/pkg/cmd/cli/backup/create.go index a606213fe..55b221174 100644 --- a/pkg/cmd/cli/backup/create.go +++ b/pkg/cmd/cli/backup/create.go @@ -85,6 +85,8 @@ type CreateOptions struct { Name string TTL time.Duration SnapshotVolumes flag.OptionalBool + SnapshotMoveData flag.OptionalBool + DataMover string DefaultVolumesToFsBackup flag.OptionalBool IncludeNamespaces flag.StringArray ExcludeNamespaces flag.StringArray @@ -139,6 +141,9 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) { // like a normal bool flag f.NoOptDefVal = "true" + f = flags.VarPF(&o.SnapshotMoveData, "snapshot-move-data", "", "Specify whether snapshot data should be moved") + f.NoOptDefVal = "true" + f = flags.VarPF(&o.IncludeClusterResources, "include-cluster-resources", "", "Include cluster-scoped resources in the backup. Cannot work with include-cluster-scoped-resources, exclude-cluster-scoped-resources, include-namespace-scoped-resources and exclude-namespace-scoped-resources.") f.NoOptDefVal = "true" @@ -146,6 +151,7 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) { f.NoOptDefVal = "true" flags.StringVar(&o.ResPoliciesConfigmap, "resource-policies-configmap", "", "Reference to the resource policies configmap that backup using") + flags.StringVar(&o.DataMover, "data-mover", "", "Specify the data mover to be used by the backup. If the parameter is not set or set as 'velero', the built-in data mover will be used") } // BindWait binds the wait flag separately so it is not called by other create @@ -359,7 +365,8 @@ func (o *CreateOptions) BuildBackup(namespace string) (*velerov1api.Backup, erro StorageLocation(o.StorageLocation). VolumeSnapshotLocations(o.SnapshotLocations...). CSISnapshotTimeout(o.CSISnapshotTimeout). - ItemOperationTimeout(o.ItemOperationTimeout) + ItemOperationTimeout(o.ItemOperationTimeout). + DataMover(o.DataMover) if len(o.OrderedResources) > 0 { orders, err := ParseOrderedResources(o.OrderedResources) if err != nil { @@ -371,6 +378,9 @@ func (o *CreateOptions) BuildBackup(namespace string) (*velerov1api.Backup, erro if o.SnapshotVolumes.Value != nil { backupBuilder.SnapshotVolumes(*o.SnapshotVolumes.Value) } + if o.SnapshotMoveData.Value != nil { + backupBuilder.SnapshotMoveData(*o.SnapshotMoveData.Value) + } if o.IncludeClusterResources.Value != nil { backupBuilder.IncludeClusterResources(*o.IncludeClusterResources.Value) } diff --git a/pkg/cmd/util/output/backup_describer.go b/pkg/cmd/util/output/backup_describer.go index 7fa210c18..0dc42e147 100644 --- a/pkg/cmd/util/output/backup_describer.go +++ b/pkg/cmd/util/output/backup_describer.go @@ -206,6 +206,13 @@ func DescribeBackupSpec(d *Describer, spec velerov1api.BackupSpec) { d.Println() d.Printf("Velero-Native Snapshot PVs:\t%s\n", BoolPointerString(spec.SnapshotVolumes, "false", "true", "auto")) + d.Printf("Snapshot Move Data:\t%s\n", BoolPointerString(spec.SnapshotMoveData, "false", "true", "auto")) + if len(spec.DataMover) == 0 { + s = emptyDisplay + } else { + s = spec.DataMover + } + d.Printf("Data Mover:\t%s\n", s) d.Println() d.Printf("TTL:\t%s\n", spec.TTL.Duration) diff --git a/pkg/cmd/util/output/backup_structured_describer.go b/pkg/cmd/util/output/backup_structured_describer.go index b12a9b313..ad711aabc 100644 --- a/pkg/cmd/util/output/backup_structured_describer.go +++ b/pkg/cmd/util/output/backup_structured_describer.go @@ -137,6 +137,15 @@ func DescribeBackupSpecInSF(d *StructuredDescriber, spec velerov1api.BackupSpec) // describe snapshot volumes backupSpecInfo["veleroNativeSnapshotPVs"] = BoolPointerString(spec.SnapshotVolumes, "false", "true", "auto") + // describe snapshot move data + backupSpecInfo["veleroSnapshotMoveData"] = BoolPointerString(spec.SnapshotMoveData, "false", "true", "auto") + // describe data mover + if len(spec.DataMover) == 0 { + s = emptyDisplay + } else { + s = spec.DataMover + } + backupSpecInfo["dataMover"] = s // describe TTL backupSpecInfo["TTL"] = spec.TTL.Duration.String()