From 9b6d157ae67be9c8c7fa73584a07fbc3d6e2558d Mon Sep 17 00:00:00 2001 From: Antony Bett Date: Tue, 22 Oct 2019 07:50:54 -0700 Subject: [PATCH] Add --backup-sync-period flag to backup location create command Signed-off-by: Antony Bett --- pkg/cmd/cli/backuplocation/create.go | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/pkg/cmd/cli/backuplocation/create.go b/pkg/cmd/cli/backuplocation/create.go index c2981370f2..a4dfd5ad45 100644 --- a/pkg/cmd/cli/backuplocation/create.go +++ b/pkg/cmd/cli/backuplocation/create.go @@ -19,6 +19,7 @@ package backuplocation import ( "fmt" "strings" + "time" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -54,13 +55,14 @@ func NewCreateCommand(f client.Factory, use string) *cobra.Command { } type CreateOptions struct { - Name string - Provider string - Bucket string - Prefix string - Config flag.Map - Labels flag.Map - AccessMode *flag.Enum + Name string + Provider string + Bucket string + Prefix string + BackupSyncPeriod time.Duration + Config flag.Map + Labels flag.Map + AccessMode *flag.Enum } func NewCreateOptions() *CreateOptions { @@ -78,6 +80,7 @@ func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) { flags.StringVar(&o.Provider, "provider", o.Provider, "name of the backup storage provider (e.g. aws, azure, gcp)") flags.StringVar(&o.Bucket, "bucket", o.Bucket, "name of the object storage bucket where backups should be stored") flags.StringVar(&o.Prefix, "prefix", o.Prefix, "prefix under which all Velero data should be stored within the bucket. Optional.") + flags.DurationVar(&o.BackupSyncPeriod, "backup-sync-period", o.BackupSyncPeriod, "how often to ensure all Velero backups in object storage exist as Backup API objects in the cluster. Optional. Set this to `0s` to disable sync") flags.Var(&o.Config, "config", "configuration key-value pairs") flags.Var(&o.Labels, "labels", "labels to apply to the backup storage location") flags.Var( @@ -100,6 +103,10 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto return errors.New("--bucket is required") } + if o.BackupSyncPeriod < 0 { + return errors.New("--backup-sync-period must be non-negative") + } + return nil } @@ -109,6 +116,12 @@ func (o *CreateOptions) Complete(args []string, f client.Factory) error { } func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { + var backupSyncPeriod *metav1.Duration + + if c.Flags().Changed("backup-sync-period") { + backupSyncPeriod = &metav1.Duration{Duration: o.BackupSyncPeriod} + } + backupStorageLocation := &velerov1api.BackupStorageLocation{ ObjectMeta: metav1.ObjectMeta{ Namespace: f.Namespace(), @@ -123,8 +136,9 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { Prefix: o.Prefix, }, }, - Config: o.Config.Data(), - AccessMode: velerov1api.BackupStorageLocationAccessMode(o.AccessMode.String()), + Config: o.Config.Data(), + AccessMode: velerov1api.BackupStorageLocationAccessMode(o.AccessMode.String()), + BackupSyncPeriod: backupSyncPeriod, }, }