mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-24 17:04:32 +00:00
pass annotations from scheduler to created backup (#3067)
* pass annotations from scheduler to created backup Signed-off-by: Michael <michael.ketslah@tufin.com> * add change log Signed-off-by: Michael <michael.ketslah@tufin.com> * add test for annotations in controller Signed-off-by: Michael <michael.ketslah@tufin.com> * If no annotations are set - do not copy empty list Signed-off-by: Michael <michael.ketslah@tufin.com> * remove unneeded var Signed-off-by: Michael <michael.ketslah@tufin.com> * add empty annotations and actually check annotations in backups Signed-off-by: Michael <michael.ketslah@tufin.com> * add empty missing label and empty annotations Signed-off-by: Michael <michael.ketslah@tufin.com> * revert empty annotations as seems they are nil as expected Signed-off-by: Michael <michael.ketslah@tufin.com> * fix typo in changelog Signed-off-by: Michael <michael.ketslah@tufin.com> Co-authored-by: Michael <michael.ketslah@tufin.com>
This commit is contained in:
@@ -83,6 +83,11 @@ func (b *BackupBuilder) FromSchedule(schedule *velerov1api.Schedule) *BackupBuil
|
||||
|
||||
b.object.Spec = schedule.Spec.Template
|
||||
b.ObjectMeta(WithLabelsMap(labels))
|
||||
|
||||
if schedule.Annotations != nil {
|
||||
b.ObjectMeta(WithAnnotationsMap(schedule.Annotations))
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,24 @@ func WithAnnotations(vals ...string) func(obj metav1.Object) {
|
||||
}
|
||||
}
|
||||
|
||||
// WithAnnotationsMap is a functional option that applies the specified annotations map to
|
||||
// an object.
|
||||
func WithAnnotationsMap(annotations map[string]string) func(obj metav1.Object) {
|
||||
return func(obj metav1.Object) {
|
||||
objAnnotations := obj.GetAnnotations()
|
||||
if objAnnotations == nil {
|
||||
objAnnotations = make(map[string]string)
|
||||
}
|
||||
|
||||
// If the label already exists in the object, it will be overwritten
|
||||
for k, v := range annotations {
|
||||
objAnnotations[k] = v
|
||||
}
|
||||
|
||||
obj.SetAnnotations(objAnnotations)
|
||||
}
|
||||
}
|
||||
|
||||
func setMapEntries(m map[string]string, vals ...string) map[string]string {
|
||||
if m == nil {
|
||||
m = make(map[string]string)
|
||||
|
||||
Reference in New Issue
Block a user