create backups from schedules using velero create backup (#1734)

* add --from-schedule to `velero backup create` to create backups from schedules

Signed-off-by: Adnan Abdulhussein <aadnan@vmware.com>
This commit is contained in:
Adnan Abdulhussein
2019-08-23 13:03:51 -07:00
committed by KubeKween
parent 686f41ebec
commit 6aa0215137
7 changed files with 189 additions and 56 deletions

View File

@@ -33,7 +33,7 @@ import (
"k8s.io/client-go/tools/cache"
api "github.com/heptio/velero/pkg/apis/velero/v1"
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
"github.com/heptio/velero/pkg/builder"
velerov1client "github.com/heptio/velero/pkg/generated/clientset/versioned/typed/velero/v1"
informers "github.com/heptio/velero/pkg/generated/informers/externalversions/velero/v1"
listers "github.com/heptio/velero/pkg/generated/listers/velero/v1"
@@ -286,29 +286,15 @@ func getNextRunTime(schedule *api.Schedule, cronSchedule cron.Schedule, asOf tim
}
func getBackup(item *api.Schedule, timestamp time.Time) *api.Backup {
backup := &api.Backup{
Spec: item.Spec.Template,
ObjectMeta: metav1.ObjectMeta{
Namespace: item.Namespace,
Name: fmt.Sprintf("%s-%s", item.Name, timestamp.Format("20060102150405")),
},
}
addLabelsToBackup(item, backup)
name := fmt.Sprintf("%s-%s", item.Name, timestamp.Format("20060102150405"))
backup := builder.
ForBackup(item.Namespace, name).
FromSchedule(item).
Result()
return backup
}
func addLabelsToBackup(item *api.Schedule, backup *api.Backup) {
labels := item.Labels
if labels == nil {
labels = make(map[string]string)
}
labels[velerov1api.ScheduleNameLabel] = item.Name
backup.Labels = labels
}
func patchSchedule(original, updated *api.Schedule, client velerov1client.SchedulesGetter) (*api.Schedule, error) {
origBytes, err := json.Marshal(original)
if err != nil {