Skip to content

Commit

Permalink
Add --backup-sync-period flag to backup location create command
Browse files Browse the repository at this point in the history
Signed-off-by: Antony Bett <[email protected]>
  • Loading branch information
betta1 committed Oct 22, 2019
1 parent 157f6d4 commit 18e6bff
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions pkg/cmd/cli/backuplocation/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package backuplocation
import (
"fmt"
"strings"
"time"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -32,6 +33,8 @@ import (
"github.com/vmware-tanzu/velero/pkg/cmd/util/output"
)

const defaultBackupSyncPeriod = time.Minute

func NewCreateCommand(f client.Factory, use string) *cobra.Command {
o := NewCreateOptions()

Expand All @@ -54,13 +57,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 {
Expand All @@ -78,6 +82,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", defaultBackupSyncPeriod, "how often to ensure all Velero backups in object storage exist as Backup API objects in the cluster. Optional. Set this to `0s` to skip 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(
Expand All @@ -100,6 +105,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
}

Expand All @@ -123,8 +132,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: &metav1.Duration{Duration: o.BackupSyncPeriod},
},
}

Expand Down

0 comments on commit 18e6bff

Please sign in to comment.