mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-08 14:21:18 +00:00
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:
committed by
KubeKween
parent
686f41ebec
commit
6aa0215137
@@ -73,6 +73,19 @@ func (b *BackupBuilder) ObjectMeta(opts ...ObjectMetaOpt) *BackupBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// FromSchedule sets the Backup's spec and labels from the Schedule template
|
||||
func (b *BackupBuilder) FromSchedule(schedule *velerov1api.Schedule) *BackupBuilder {
|
||||
labels := schedule.Labels
|
||||
if labels == nil {
|
||||
labels = make(map[string]string)
|
||||
}
|
||||
labels[velerov1api.ScheduleNameLabel] = schedule.Name
|
||||
|
||||
b.object.Spec = schedule.Spec.Template
|
||||
b.ObjectMeta(WithLabelsMap(labels))
|
||||
return b
|
||||
}
|
||||
|
||||
// IncludedNamespaces sets the Backup's included namespaces.
|
||||
func (b *BackupBuilder) IncludedNamespaces(namespaces ...string) *BackupBuilder {
|
||||
b.object.Spec.IncludedNamespaces = namespaces
|
||||
@@ -151,12 +164,6 @@ func (b *BackupBuilder) StartTimestamp(val time.Time) *BackupBuilder {
|
||||
return b
|
||||
}
|
||||
|
||||
// NoTypeMeta removes the type meta from the Backup.
|
||||
func (b *BackupBuilder) NoTypeMeta() *BackupBuilder {
|
||||
b.object.TypeMeta = metav1.TypeMeta{}
|
||||
return b
|
||||
}
|
||||
|
||||
// Hooks sets the Backup's hooks.
|
||||
func (b *BackupBuilder) Hooks(hooks velerov1api.BackupHooks) *BackupBuilder {
|
||||
b.object.Spec.Hooks = hooks
|
||||
|
||||
@@ -42,6 +42,24 @@ func WithLabels(vals ...string) func(obj metav1.Object) {
|
||||
}
|
||||
}
|
||||
|
||||
// WithLabelsMap is a functional option that applies the specified labels map to
|
||||
// an object.
|
||||
func WithLabelsMap(labels map[string]string) func(obj metav1.Object) {
|
||||
return func(obj metav1.Object) {
|
||||
objLabels := obj.GetLabels()
|
||||
if objLabels == nil {
|
||||
objLabels = make(map[string]string)
|
||||
}
|
||||
|
||||
// If the label already exists in the object, it will be overwritten
|
||||
for k, v := range labels {
|
||||
objLabels[k] = v
|
||||
}
|
||||
|
||||
obj.SetLabels(objLabels)
|
||||
}
|
||||
}
|
||||
|
||||
// WithAnnotations is a functional option that applies the specified
|
||||
// annotation keys/values to an object.
|
||||
func WithAnnotations(vals ...string) func(obj metav1.Object) {
|
||||
@@ -66,6 +84,7 @@ func setMapEntries(m map[string]string, vals ...string) map[string]string {
|
||||
key := vals[i]
|
||||
val := vals[i+1]
|
||||
|
||||
// If the label already exists in the object, it will be overwritten
|
||||
m[key] = val
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user