Owner reference in backup when created from schedule (#3127)

* added useOwnerReferencesInBackup to crd velerio.io_schedules

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>

* added UseOwnerReferencesInBackup property to schedule.go

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>

* deepcopy schedule configured for reference the property UseOwnerReferencesInBackup

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>

* added UseOwnerReferencesInBackup property verification to modify OwnerReferences from backup

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>

* created changelog

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>

* removed deepcopy schedule configured for reference the property UseOwnerReferencesInBackup

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>

* running make update

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>

* running make update

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>

* updated the year at the top of the schedule.go file for 2020

Signed-off-by: matheusjuvelino <matheus.juvelino@outlook.com>
pull/3185/head
matheusjuvelino 2020-12-11 15:10:34 -03:00 committed by GitHub
parent f1ec10a518
commit 309d3dcf0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 2 deletions

View File

@ -0,0 +1 @@
Owner reference in backup when created from schedule

View File

@ -369,6 +369,11 @@ spec:
type: string
type: array
type: object
useOwnerReferencesInBackup:
description: UseOwnerReferencesBackup specifies whether to use OwnerReferences
on backups created by this Schedule.
nullable: true
type: boolean
required:
- schedule
- template

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
/*
Copyright 2017 the Velero contributors.
Copyright 2020 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -32,6 +32,12 @@ type ScheduleSpec struct {
// Schedule is a Cron expression defining when to run
// the Backup.
Schedule string `json:"schedule"`
// UseOwnerReferencesBackup specifies whether to use
// OwnerReferences on backups created by this Schedule.
// +optional
// +nullable
UseOwnerReferencesInBackup *bool `json:"useOwnerReferencesInBackup,omitempty"`
}
// SchedulePhase is a string representation of the lifecycle phase

View File

@ -1390,6 +1390,11 @@ func (in *ScheduleList) DeepCopyObject() runtime.Object {
func (in *ScheduleSpec) DeepCopyInto(out *ScheduleSpec) {
*out = *in
in.Template.DeepCopyInto(&out.Template)
if in.UseOwnerReferencesInBackup != nil {
in, out := &in.UseOwnerReferencesInBackup, &out.UseOwnerReferencesInBackup
*out = new(bool)
**out = **in
}
return
}

View File

@ -22,6 +22,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
)
/*
@ -88,6 +90,18 @@ func (b *BackupBuilder) FromSchedule(schedule *velerov1api.Schedule) *BackupBuil
b.ObjectMeta(WithAnnotationsMap(schedule.Annotations))
}
if boolptr.IsSetToTrue(schedule.Spec.UseOwnerReferencesInBackup) {
b.object.SetOwnerReferences([]metav1.OwnerReference{
{
APIVersion: velerov1api.SchemeGroupVersion.String(),
Kind: "Schedule",
Name: schedule.Name,
UID: schedule.UID,
Controller: boolptr.True(),
},
})
}
return b
}