Skip to content

Commit b1e744e

Browse files
millasmlMilla Samuel
andauthored
Modify Backup URL in Reconciler (#2347)
* Allow to modify the backup URL Co-authored-by: Milla Samuel <millas@palantir.com>
1 parent 168b3f0 commit b1e744e

File tree

7 files changed

+40
-7
lines changed

7 files changed

+40
-7
lines changed

api/v1beta2/foundationdbbackup_types.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ func (backup *FoundationDBBackup) GetDesiredAgentCount() int {
321321
return ptr.Deref(backup.Spec.AgentCount, 2)
322322
}
323323

324+
// NeedsBackupReconfiguration determines if the backup needs to be reconfigured.
325+
func (backup *FoundationDBBackup) NeedsBackupReconfiguration() bool {
326+
hasSnapshotSecondsChanged := backup.SnapshotPeriodSeconds() != backup.Status.BackupDetails.SnapshotPeriodSeconds
327+
hasBackupURLChanged := backup.BackupURL() != backup.Status.BackupDetails.URL
328+
329+
return hasSnapshotSecondsChanged || hasBackupURLChanged
330+
}
331+
324332
// CheckReconciliation compares the spec and the status to determine if
325333
// reconciliation is complete.
326334
func (backup *FoundationDBBackup) CheckReconciliation() (bool, error) {
@@ -350,8 +358,7 @@ func (backup *FoundationDBBackup) CheckReconciliation() (bool, error) {
350358
reconciled = false
351359
}
352360

353-
if isRunning &&
354-
backup.SnapshotPeriodSeconds() != backup.Status.BackupDetails.SnapshotPeriodSeconds {
361+
if isRunning && backup.NeedsBackupReconfiguration() {
355362
backup.Status.Generations.NeedsBackupReconfiguration = backup.Generation
356363
reconciled = false
357364
}

api/v1beta2/foundationdbbackup_types_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ var _ = Describe("[api] FoundationDBBackup", func() {
5252
},
5353
Spec: FoundationDBBackupSpec{
5454
AgentCount: &agentCount,
55+
BlobStoreConfiguration: &BlobStoreConfiguration{
56+
AccountName: "test@test-service",
57+
},
5558
},
5659
Status: FoundationDBBackupStatus{
5760
Generations: BackupGenerationStatus{
@@ -60,7 +63,7 @@ var _ = Describe("[api] FoundationDBBackup", func() {
6063
AgentCount: 3,
6164
DeploymentConfigured: true,
6265
BackupDetails: &FoundationDBBackupStatusBackupDetails{
63-
URL: "blobstore://test@test-service/sample-cluster?bucket=fdb-backups",
66+
URL: "blobstore://test@test-service:443/sample-cluster?bucket=fdb-backups",
6467
Running: true,
6568
SnapshotPeriodSeconds: 864000,
6669
},
@@ -69,7 +72,6 @@ var _ = Describe("[api] FoundationDBBackup", func() {
6972
}
7073

7174
backup = createBackup()
72-
7375
result, err := backup.CheckReconciliation()
7476
Expect(result).To(BeTrue())
7577
Expect(err).NotTo(HaveOccurred())

controllers/admin_client_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,36 @@ var _ = Describe("admin_client_test", func() {
333333
Context("with a modification to the snapshot time", func() {
334334
BeforeEach(func() {
335335
backup.Spec.SnapshotPeriodSeconds = ptr.To(20)
336+
backup.Spec.BlobStoreConfiguration = &fdbv1beta2.BlobStoreConfiguration{
337+
BackupName: "test-backup",
338+
AccountName: "test",
339+
}
336340
Expect(mockAdminClient.ModifyBackup(backup)).NotTo(HaveOccurred())
341+
337342
})
338343

339-
It("should mark the backup as stopped", func() {
344+
It("should have modified the snapshot time", func() {
340345
Expect(
341346
status.SnapshotIntervalSeconds,
342347
).To(BeNumerically("==", backup.SnapshotPeriodSeconds()))
343348
})
344349
})
350+
351+
Context("with a modification to the backup url", func() {
352+
BeforeEach(func() {
353+
backup.Spec.BlobStoreConfiguration = &fdbv1beta2.BlobStoreConfiguration{
354+
BackupName: "test-backup-2",
355+
AccountName: "test",
356+
}
357+
Expect(mockAdminClient.ModifyBackup(backup)).NotTo(HaveOccurred())
358+
})
359+
360+
It("should have modified the backup url", func() {
361+
Expect(
362+
status.DestinationURL,
363+
).To(Equal("blobstore://test:443/test-backup-2?bucket=fdb-backups"))
364+
})
365+
})
345366
})
346367
})
347368

controllers/modify_backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s modifyBackup) reconcile(
4141
return nil
4242
}
4343

44-
if backup.Status.BackupDetails.SnapshotPeriodSeconds != backup.SnapshotPeriodSeconds() {
44+
if backup.NeedsBackupReconfiguration() {
4545
adminClient, err := r.adminClientForBackup(ctx, backup)
4646
if err != nil {
4747
return &requeue{curError: err}

docs/manual/technical_design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ The `ToggleBackupPaused` subreconciler is responsible for pausing and unpausing
387387

388388
The `ModifyBackup` command ensures that any properties that can be configured on a live backup are configured to the values in the backup spec. This will run the `modify` command in `fdbbackup` to set the properties from the spec.
389389

390-
Currently, this only supports the `snapshotPeriodSeconds` property.
390+
Currently, this only supports the `snapshotPeriodSeconds` and `url` property.
391391

392392
### UpdateBackupStatus (again)
393393

fdbclient/admin_client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,8 @@ func (client *cliAdminClient) ModifyBackup(backup *fdbv1beta2.FoundationDBBackup
882882
"modify",
883883
"-s",
884884
strconv.Itoa(backup.SnapshotPeriodSeconds()),
885+
"-d",
886+
backup.BackupURL(),
885887
},
886888
})
887889

pkg/fdbadminclient/mock/admin_client_mock.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,7 @@ func (client *AdminClient) ModifyBackup(backup *fdbv1beta2.FoundationDBBackup) e
919919

920920
currentBackup := client.Backups["default"]
921921
currentBackup.SnapshotPeriodSeconds = backup.SnapshotPeriodSeconds()
922+
currentBackup.URL = backup.BackupURL()
922923
client.Backups["default"] = currentBackup
923924
return nil
924925
}

0 commit comments

Comments
 (0)