@@ -75,21 +75,18 @@ func buildBackupPolicyApiType(nn types.NamespacedName, obcluster string, p *Crea
7575 JobKeepWindow : numberToDay (p .JobKeepDays ),
7676 LogArchive : v1alpha1.LogArchiveConfig {
7777 Destination : apitypes.BackupDestination {
78- Path : p .ArchivePath ,
79- Type : apitypes .BackupDestType (p .DestType ),
80- OSSAccessSecret : "" ,
78+ Path : p .ArchivePath ,
79+ Type : apitypes .BackupDestType (p .DestType ),
8180 },
8281 SwitchPieceInterval : "1d" ,
8382 },
8483 DataBackup : v1alpha1.DataBackupConfig {
8584 Destination : apitypes.BackupDestination {
86- Path : p .BakDataPath ,
87- Type : apitypes .BackupDestType (p .DestType ),
88- OSSAccessSecret : "" ,
85+ Path : p .BakDataPath ,
86+ Type : apitypes .BackupDestType (p .DestType ),
8987 },
9088 FullCrontab : p .FullCrontab ,
9189 IncrementalCrontab : p .IncrementalCrontab ,
92- EncryptionSecret : "" ,
9390 },
9491 DataClean : v1alpha1.CleanPolicy {
9592 RecoveryWindow : numberToDay (p .RecoveryDays ),
@@ -114,6 +111,10 @@ func CreateTenantBackupPolicy(ctx context.Context, o *CreateOptions) (*v1alpha1.
114111 if err := util .CheckTenantStatus (tenant ); err != nil {
115112 return nil , err
116113 }
114+ // Check if backup policy already exists
115+ if backupPolicy , _ := clients .GetTenantBackupPolicy (ctx , nn ); backupPolicy != nil {
116+ return nil , errors .New ("Backup policy already exists" )
117+ }
117118 backupPolicy , err := buildBackupPolicyApiType (nn , tenant .Spec .ClusterName , o )
118119 if err != nil {
119120 return nil , err
@@ -154,11 +155,17 @@ func CreateTenantBackupPolicy(ctx context.Context, o *CreateOptions) (*v1alpha1.
154155 return nil , err
155156 }
156157 }
158+ blockOwnerDeletion := true
159+ backupPolicy .SetOwnerReferences ([]metav1.OwnerReference {{
160+ APIVersion : tenant .APIVersion ,
161+ Kind : tenant .Kind ,
162+ Name : tenant .GetObjectMeta ().GetName (),
163+ UID : tenant .GetObjectMeta ().GetUID (),
164+ BlockOwnerDeletion : & blockOwnerDeletion ,
165+ }})
157166 // set labels for backup policy
158167 backupPolicy .Labels = map [string ]string {
159- oceanbaseconst .LabelTenantName : o .Name ,
160- oceanbaseconst .LabelRefUID : string (tenant .GetObjectMeta ().GetUID ()),
161- oceanbaseconst .LabelRefBackupPolicy : o .Name + "-backup-policy" ,
168+ oceanbaseconst .LabelRefOBServer : string (tenant .Spec .ClusterName ),
162169 }
163170 policy , err := clients .CreateTenantBackupPolicy (ctx , backupPolicy )
164171 if err != nil {
0 commit comments