Skip to content

Commit

Permalink
fix: update backup policy's backup repo with cluster's backup repo… (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb committed Oct 11, 2023
1 parent dcc6fac commit 22f6d93
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion controllers/apps/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2128,11 +2128,18 @@ var _ = Describe("Cluster Controller", func() {
}
}

By("checking backup policy exists")
checkPolicy := func(g Gomega, policy *dpv1alpha1.BackupPolicy) {
if backup != nil && backup.RepoName != "" {
Expect(*policy.Spec.BackupRepoName).Should(BeEquivalentTo(backup.RepoName))
}
}

By("checking backup policy")
backupPolicyName := generateBackupPolicyName(clusterKey.Name, compDefName, "")
backupPolicyKey := client.ObjectKey{Name: backupPolicyName, Namespace: clusterKey.Namespace}
backupPolicy := &dpv1alpha1.BackupPolicy{}
Eventually(testapps.CheckObjExists(&testCtx, backupPolicyKey, backupPolicy, true)).Should(Succeed())
Eventually(testapps.CheckObj(&testCtx, backupPolicyKey, checkPolicy)).Should(Succeed())

By("checking backup schedule")
backupScheduleName := generateBackupScheduleName(clusterKey.Name, compDefName, "")
Expand Down
9 changes: 9 additions & 0 deletions controllers/apps/transformer_backup_policy_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ func (r *BackupPolicyTplTransformer) syncBackupPolicy(backupPolicy *dpv1alpha1.B
mergeMap(backupPolicy.Annotations, r.buildAnnotations())
mergeMap(backupPolicy.Labels, r.buildLabels())

// update backup repo of the backup policy.
if r.Cluster.Spec.Backup != nil && r.Cluster.Spec.Backup.RepoName != "" {
backupPolicy.Spec.BackupRepoName = &r.Cluster.Spec.Backup.RepoName
}

// only update the role labelSelector of the backup target instance when
// component workload is Replication/Consensus. Because the replicas of
// component will change, such as 2->1. then if the target role is 'follower'
Expand Down Expand Up @@ -320,6 +325,10 @@ func (r *BackupPolicyTplTransformer) buildBackupPolicy(backupPolicyName string)
}

bpSpec := backupPolicy.Spec
// if cluster have backup repo, set backup repo name to backup policy.
if cluster.Spec.Backup != nil && cluster.Spec.Backup.RepoName != "" {
bpSpec.BackupRepoName = &cluster.Spec.Backup.RepoName
}
bpSpec.BackupMethods = r.backupPolicy.BackupMethods
bpSpec.PathPrefix = buildBackupPathPrefix(cluster, comp.Name)
bpSpec.Target = r.buildBackupTarget(comp)
Expand Down

0 comments on commit 22f6d93

Please sign in to comment.