Skip to content

Commit 42e15e6

Browse files
drivebyercndoit18
authored andcommitted
fix: recurrent backup remote delete policy can not update
1 parent b7ea748 commit 42e15e6

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
1515
### Fixed
1616
* `orchestrator.secretName` is ignored in helm charts
1717
* Operator service account have no access to update mysqlbackups/status
18+
* Recurrent backup remote delete policy can not update according to the `cluster.Spec.BackupRemoteDeletePolicy`
1819

1920
## [0.6.1] - 2021-12-22
2021
### Changed

pkg/controller/mysqlbackupcron/mysqlbackupcron_controller.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,8 @@ func (r *ReconcileMysqlBackup) updateClusterSchedule(cluster *mysqlv1alpha1.Mysq
166166

167167
// change scheduler for already added crons
168168
if !reflect.DeepEqual(entry.Schedule, schedule) {
169-
log.Info("update cluster scheduler", "key", cluster,
170-
"scheduler", cluster.Spec.BackupSchedule)
171-
169+
log.Info("update cluster scheduler", "key", cluster, "scheduler", cluster.Spec.BackupSchedule)
172170
r.cron.Remove(entry.ID)
173-
174171
break
175172
}
176173

@@ -182,9 +179,14 @@ func (r *ReconcileMysqlBackup) updateClusterSchedule(cluster *mysqlv1alpha1.Mysq
182179
}
183180
log.Info("update cluster backup limit", "key", cluster, "limit_val", newValFmt)
184181
r.cron.Remove(entry.ID)
185-
186182
break
183+
}
187184

185+
// update backup remote delete policy for already added crons
186+
if !reflect.DeepEqual(cluster.Spec.BackupRemoteDeletePolicy, j.BackupRemoteDeletePolicy) {
187+
log.Info("update cluster backup remote delete policy", "key", cluster, "policy", cluster.Spec.BackupRemoteDeletePolicy)
188+
r.cron.Remove(entry.ID)
189+
break
188190
}
189191

190192
// nothing to change for this cluster, return

pkg/controller/mysqlbackupcron/mysqlbackupcron_controller_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,30 @@ var _ = Describe("MysqlBackupCron controller", func() {
200200
})))
201201
})
202202

203+
It("should update backup remote delete policy", func() {
204+
cluster.Spec.BackupRemoteDeletePolicy = api.Delete
205+
Expect(c.Update(context.TODO(), cluster)).To(Succeed())
206+
Eventually(requests, timeout).Should(Receive(Equal(expectedRequest)))
207+
Expect(cron.Entries()).To(ContainElement(MatchFields(IgnoreExtras, Fields{
208+
"Job": PointTo(MatchFields(IgnoreExtras, Fields{
209+
"ClusterName": Equal(cluster.Name),
210+
"BackupRemoteDeletePolicy": Equal(api.Delete),
211+
})),
212+
})))
213+
214+
cluster.Spec.BackupRemoteDeletePolicy = api.Retain
215+
Expect(c.Update(context.TODO(), cluster)).To(Succeed())
216+
Eventually(requests, timeout).Should(Receive(Equal(expectedRequest)))
217+
Expect(cron.Entries()).To(ContainElement(MatchFields(IgnoreExtras, Fields{
218+
"Job": PointTo(MatchFields(IgnoreExtras, Fields{
219+
"ClusterName": Equal(cluster.Name),
220+
"BackupRemoteDeletePolicy": Equal(api.Retain),
221+
})),
222+
})))
223+
224+
Expect(cron.Entries()).To(HaveLen(1))
225+
})
226+
203227
When("backup is executed once per second", func() {
204228
var (
205229
timeout = 5 * time.Second

0 commit comments

Comments
 (0)