Skip to content

Commit 87bf03f

Browse files
author
Milla Samuel
committed
Add Versionstamp To Restore CRD
1 parent f1b7839 commit 87bf03f

File tree

13 files changed

+99
-22
lines changed

13 files changed

+99
-22
lines changed

api/v1beta2/foundationdbrestore_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ type FoundationDBRestoreSpec struct {
6565
// The path to the encryption key used to encrypt the backup.
6666
// +kubebuilder:validation:MaxLength=4096
6767
EncryptionKeyPath string `json:"encryptionKeyPath,omitempty"`
68+
69+
// Instead of the latest version the backup can be restored to, restore to the specified version.
70+
// +nullable
71+
BackupVersion *uint64 `json:"backupVersion,omitempty"`
6872
}
6973

7074
// FoundationDBRestoreStatus describes the current status of the restore for a cluster.

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/apps.foundationdb.org_foundationdbrestores.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ spec:
3636
type: object
3737
spec:
3838
properties:
39+
backupVersion:
40+
format: int64
41+
nullable: true
42+
type: integer
3943
blobStoreConfiguration:
4044
properties:
4145
accountName:

controllers/admin_client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ var _ = Describe("admin_client_test", func() {
364364
Expect(
365365
mockAdminClient.StartRestore(
366366
"blobstore://test@test-service/test-backup",
367-
nil,
368-
"",
369-
),
370-
).To(Succeed())
367+
fdbv1beta2.FoundationDBRestore{
368+
Spec: fdbv1beta2.FoundationDBRestoreSpec{
369+
DestinationClusterName: cluster.Name,
370+
}})).To(Succeed())
371371

372372
restoreStatus, err = mockAdminClient.GetRestoreStatus()
373373
Expect(err).NotTo(HaveOccurred())

controllers/start_restore.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ func (s startRestore) reconcile(
5454
if len(strings.TrimSpace(status)) == 0 {
5555
err = adminClient.StartRestore(
5656
restore.BackupURL(),
57-
restore.Spec.KeyRanges,
58-
restore.Spec.EncryptionKeyPath,
57+
*restore,
5958
)
6059
if err != nil {
6160
return &requeue{curError: err}

docs/restore_spec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ FoundationDBRestoreSpec describes the desired state of the backup for a cluster.
5656
| blobStoreConfiguration | This is the configuration of the target blobstore for this backup. | *BlobStoreConfiguration | false |
5757
| customParameters | CustomParameters defines additional parameters to pass to the backup agents. | FoundationDBCustomParameters | false |
5858
| encryptionKeyPath | The path to the encryption key used to encrypt the backup. | string | false |
59+
| backupVersion | Instead of the latest version the backup can be restored to, restore to the specified version. | *uint64 | false |
5960

6061
[Back to TOC](#table-of-contents)
6162

e2e/fixtures/fdb_backup.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ func (fdbBackup *FdbBackup) WaitForReconciliation() {
221221
}
222222

223223
// WaitForRestorableVersion will wait until the back is restorable.
224-
func (fdbBackup *FdbBackup) WaitForRestorableVersion(version uint64) {
224+
func (fdbBackup *FdbBackup) WaitForRestorableVersion(version uint64) uint64 {
225+
var restorableVersion uint64
225226
gomega.Eventually(func(g gomega.Gomega) uint64 {
226227
backupPod := fdbBackup.GetBackupPod()
227228
out, _, err := fdbBackup.fdbCluster.ExecuteCmdOnPod(
@@ -241,6 +242,7 @@ func (fdbBackup *FdbBackup) WaitForRestorableVersion(version uint64) {
241242

242243
return ptr.Deref(status.LatestRestorablePoint.Version, 0)
243244
}).WithTimeout(10*time.Minute).WithPolling(2*time.Second).Should(gomega.BeNumerically(">", version), "error waiting for restorable version")
245+
return restorableVersion
244246
}
245247

246248
// GetBackupPod returns a random backup Pod for the provided backup.

e2e/fixtures/fdb_restore.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
// CreateRestoreForCluster will create a FoundationDBRestore resource based on the provided backup resource.
3737
// For more information how the backup system with the operator is working please look at
3838
// the operator documentation: https://github.com/FoundationDB/fdb-kubernetes-operator/v2/blob/master/docs/manual/backup.md
39-
func (factory *Factory) CreateRestoreForCluster(backup *FdbBackup) {
39+
func (factory *Factory) CreateRestoreForCluster(backup *FdbBackup, backupVersion *uint64) {
4040
gomega.Expect(backup).NotTo(gomega.BeNil())
4141
restore := &fdbv1beta2.FoundationDBRestore{
4242
ObjectMeta: metav1.ObjectMeta{
@@ -49,6 +49,11 @@ func (factory *Factory) CreateRestoreForCluster(backup *FdbBackup) {
4949
CustomParameters: backup.backup.Spec.CustomParameters,
5050
},
5151
}
52+
53+
if backupVersion != nil {
54+
restore.Spec.BackupVersion = backupVersion
55+
}
56+
5257
gomega.Expect(factory.CreateIfAbsent(restore)).NotTo(gomega.HaveOccurred())
5358

5459
factory.AddShutdownHook(func() error {

e2e/test_operator_backups/operator_backup_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ var _ = Describe("Operator Backup", Label("e2e", "pr"), func() {
8282
var keyValues []fixtures.KeyValue
8383
var prefix byte = 'a'
8484
var backup *fixtures.FdbBackup
85-
8685
// Delete the backup resource after each test. Note that this will not delete the data
8786
// in the backup store.
8887
AfterEach(func() {
@@ -104,7 +103,7 @@ var _ = Describe("Operator Backup", Label("e2e", "pr"), func() {
104103

105104
It("should restore the cluster successfully", func() {
106105
fdbCluster.ClearRange([]byte{prefix}, 60)
107-
factory.CreateRestoreForCluster(backup)
106+
factory.CreateRestoreForCluster(backup, nil)
108107
Expect(fdbCluster.GetRange([]byte{prefix}, 25, 60)).Should(Equal(keyValues))
109108
})
110109
})
@@ -174,7 +173,18 @@ var _ = Describe("Operator Backup", Label("e2e", "pr"), func() {
174173

175174
It("should restore the cluster successfully", func() {
176175
fdbCluster.ClearRange([]byte{prefix}, 60)
177-
factory.CreateRestoreForCluster(backup)
176+
factory.CreateRestoreForCluster(backup, nil)
177+
Expect(fdbCluster.GetRange([]byte{prefix}, 25, 60)).Should(Equal(keyValues))
178+
})
179+
180+
It("should restore the cluster successfully with a restorable version", func() {
181+
var prefix byte = 'b'
182+
var keyValues = fdbCluster.GenerateRandomValues(10, prefix)
183+
fdbCluster.WriteKeyValues(keyValues)
184+
var restorableVersion = backup.WaitForRestorableVersion(fdbCluster.GetClusterVersion())
185+
backup.Stop()
186+
fdbCluster.ClearRange([]byte{prefix}, 60)
187+
factory.CreateRestoreForCluster(backup, &restorableVersion)
178188
Expect(fdbCluster.GetRange([]byte{prefix}, 25, 60)).Should(Equal(keyValues))
179189
})
180190

fdbclient/admin_client.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,7 @@ func (client *cliAdminClient) GetBackupStatus() (*fdbv1beta2.FoundationDBLiveBac
919919
// StartRestore starts a new restore.
920920
func (client *cliAdminClient) StartRestore(
921921
url string,
922-
keyRanges []fdbv1beta2.FoundationDBKeyRange,
923-
encryptionKeyPath string,
922+
restore fdbv1beta2.FoundationDBRestore,
924923
) error {
925924
args := []string{
926925
"start",
@@ -933,13 +932,17 @@ func (client *cliAdminClient) StartRestore(
933932
return verErr
934933
}
935934

936-
if encryptionKeyPath != "" && fdbVersion.SupportsBackupEncryption() {
937-
args = append(args, "--encryption-key-file", encryptionKeyPath)
935+
if restore.Spec.EncryptionKeyPath != "" && fdbVersion.SupportsBackupEncryption() {
936+
args = append(args, "--encryption-key-file", restore.Spec.EncryptionKeyPath)
937+
}
938+
939+
if restore.Spec.BackupVersion != nil {
940+
args = append(args, "-v", strconv.FormatUint(*restore.Spec.BackupVersion, 10))
938941
}
939942

940-
if keyRanges != nil {
943+
if restore.Spec.KeyRanges != nil {
941944
keyRangeString := ""
942-
for _, keyRange := range keyRanges {
945+
for _, keyRange := range restore.Spec.KeyRanges {
943946
if keyRangeString != "" {
944947
keyRangeString += ";"
945948
}

0 commit comments

Comments
 (0)