From 445b5b781e6bf34f8854eb2b7938719ab42214aa Mon Sep 17 00:00:00 2001 From: Carlos Panato Date: Fri, 24 Jan 2020 09:16:13 +0100 Subject: [PATCH 1/4] remove schedule validation Signed-off-by: Carlos Panato --- pkg/cmd/cli/restore/create.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pkg/cmd/cli/restore/create.go b/pkg/cmd/cli/restore/create.go index 09f12412d..1b9f3735b 100644 --- a/pkg/cmd/cli/restore/create.go +++ b/pkg/cmd/cli/restore/create.go @@ -165,15 +165,10 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto return errors.New("Velero client is not set; unable to proceed") } - switch { - case o.BackupName != "": + if o.BackupName != "" { if _, err := o.client.VeleroV1().Backups(f.Namespace()).Get(o.BackupName, metav1.GetOptions{}); err != nil { return err } - case o.ScheduleName != "": - if _, err := o.client.VeleroV1().Schedules(f.Namespace()).Get(o.ScheduleName, metav1.GetOptions{}); err != nil { - return err - } } return nil From f7adc4dfd18915a1b5436b4c8adf681c8afb626b Mon Sep 17 00:00:00 2001 From: Carlos Panato Date: Wed, 29 Jan 2020 09:50:30 +0100 Subject: [PATCH 2/4] check if schedule have a backup Signed-off-by: Carlos Panato --- pkg/cmd/cli/restore/create.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/cli/restore/create.go b/pkg/cmd/cli/restore/create.go index 1b9f3735b..44ebc6f70 100644 --- a/pkg/cmd/cli/restore/create.go +++ b/pkg/cmd/cli/restore/create.go @@ -165,10 +165,19 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto return errors.New("Velero client is not set; unable to proceed") } - if o.BackupName != "" { + switch { + case o.BackupName != "": if _, err := o.client.VeleroV1().Backups(f.Namespace()).Get(o.BackupName, metav1.GetOptions{}); err != nil { return err } + case o.ScheduleName != "": + scheduleItems, err := o.client.VeleroV1().Backups(f.Namespace()).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", api.ScheduleNameLabel, o.ScheduleName)}) + if err != nil { + return err + } + if len(scheduleItems.Items) == 0 { + return errors.Errorf("No backups found for the schedule %s", o.ScheduleName) + } } return nil From 4a5a63fc92704407cb9c0ffeac82fec463a904a7 Mon Sep 17 00:00:00 2001 From: Carlos Panato Date: Wed, 29 Jan 2020 18:23:29 +0100 Subject: [PATCH 3/4] add changelog Signed-off-by: Carlos Panato --- changelogs/unreleased/2218-cpanato | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelogs/unreleased/2218-cpanato diff --git a/changelogs/unreleased/2218-cpanato b/changelogs/unreleased/2218-cpanato new file mode 100644 index 000000000..eb3001f70 --- /dev/null +++ b/changelogs/unreleased/2218-cpanato @@ -0,0 +1 @@ +remove the schedule validation and instead of checking the schedule because we might be in another cluster we check if a backup exist with the schedule name. \ No newline at end of file From 42b612645863c2b3e451b447f9bf798295dd7dba Mon Sep 17 00:00:00 2001 From: Carlos Panato Date: Fri, 31 Jan 2020 09:22:46 +0100 Subject: [PATCH 4/4] update variable name Signed-off-by: Carlos Panato --- pkg/cmd/cli/restore/create.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/cli/restore/create.go b/pkg/cmd/cli/restore/create.go index 44ebc6f70..f30ee1307 100644 --- a/pkg/cmd/cli/restore/create.go +++ b/pkg/cmd/cli/restore/create.go @@ -171,11 +171,11 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto return err } case o.ScheduleName != "": - scheduleItems, err := o.client.VeleroV1().Backups(f.Namespace()).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", api.ScheduleNameLabel, o.ScheduleName)}) + backupItems, err := o.client.VeleroV1().Backups(f.Namespace()).List(metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", api.ScheduleNameLabel, o.ScheduleName)}) if err != nil { return err } - if len(scheduleItems.Items) == 0 { + if len(backupItems.Items) == 0 { return errors.Errorf("No backups found for the schedule %s", o.ScheduleName) } }