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:
Misha Ketslah
2020-11-19 13:19:42 -08:00
committed by GitHub
co-authored by Michael
parent c10feb2cc3
commit 8c8385aabb
5 changed files with 37 additions and 2 deletions
+5
View File
@@ -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
}
+18
View File
@@ -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)