|
| 1 | +diff a/e2e/fixtures/fdb_restore.go b/e2e/fixtures/fdb_restore.go (rejected hunks) |
| 2 | +@@ -33,49 +35,62 @@ import ( |
| 3 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 4 | + ) |
| 5 | + |
| 6 | ++// FdbRestore represents a fdbv1beta2.FoundationDBRestore resource for doing restores to a FdbCluster. |
| 7 | ++type FdbRestore struct { |
| 8 | ++ restore *fdbv1beta2.FoundationDBRestore |
| 9 | ++ fdbCluster *FdbCluster |
| 10 | ++} |
| 11 | ++ |
| 12 | + // CreateRestoreForCluster will create a FoundationDBRestore resource based on the provided backup resource. |
| 13 | + // For more information how the backup system with the operator is working please look at |
| 14 | + // the operator documentation: https://github.com/FoundationDB/fdb-kubernetes-operator/v2/blob/master/docs/manual/backup.md |
| 15 | +-func (factory *Factory) CreateRestoreForCluster(backup *FdbBackup) { |
| 16 | ++func (factory *Factory) CreateRestoreForCluster(backup *FdbBackup) *FdbRestore { |
| 17 | + gomega.Expect(backup).NotTo(gomega.BeNil()) |
| 18 | +- restore := &fdbv1beta2.FoundationDBRestore{ |
| 19 | +- ObjectMeta: metav1.ObjectMeta{ |
| 20 | +- Name: backup.fdbCluster.Name(), |
| 21 | +- Namespace: backup.fdbCluster.Namespace(), |
| 22 | +- }, |
| 23 | +- Spec: fdbv1beta2.FoundationDBRestoreSpec{ |
| 24 | +- DestinationClusterName: backup.fdbCluster.Name(), |
| 25 | +- BlobStoreConfiguration: backup.backup.Spec.BlobStoreConfiguration, |
| 26 | +- CustomParameters: backup.backup.Spec.CustomParameters, |
| 27 | ++ restore := &FdbRestore{ |
| 28 | ++ restore: &fdbv1beta2.FoundationDBRestore{ |
| 29 | ++ ObjectMeta: metav1.ObjectMeta{ |
| 30 | ++ Name: backup.fdbCluster.Name(), |
| 31 | ++ Namespace: backup.fdbCluster.Namespace(), |
| 32 | ++ }, |
| 33 | ++ Spec: fdbv1beta2.FoundationDBRestoreSpec{ |
| 34 | ++ DestinationClusterName: backup.fdbCluster.Name(), |
| 35 | ++ BlobStoreConfiguration: backup.backup.Spec.BlobStoreConfiguration, |
| 36 | ++ CustomParameters: backup.backup.Spec.CustomParameters, |
| 37 | ++ }, |
| 38 | + }, |
| 39 | ++ fdbCluster: backup.fdbCluster, |
| 40 | + } |
| 41 | +- gomega.Expect(factory.CreateIfAbsent(restore)).NotTo(gomega.HaveOccurred()) |
| 42 | ++ |
| 43 | ++ gomega.Expect(factory.CreateIfAbsent(restore.restore)).NotTo(gomega.HaveOccurred()) |
| 44 | + |
| 45 | + factory.AddShutdownHook(func() error { |
| 46 | +- return factory.GetControllerRuntimeClient().Delete(context.Background(), restore) |
| 47 | ++ restore.Destroy() |
| 48 | ++ return nil |
| 49 | + }) |
| 50 | + |
| 51 | +- waitForRestoreToComplete(backup) |
| 52 | ++ restore.waitForRestoreToComplete(backup) |
| 53 | ++ |
| 54 | ++ return restore |
| 55 | + } |
| 56 | + |
| 57 | + // waitForRestoreToComplete waits until the restore completed. |
| 58 | +-func waitForRestoreToComplete(backup *FdbBackup) { |
| 59 | +- ctrlClient := backup.fdbCluster.getClient() |
| 60 | ++func (restore *FdbRestore) waitForRestoreToComplete(backup *FdbBackup) { |
| 61 | ++ ctrlClient := restore.fdbCluster.getClient() |
| 62 | + |
| 63 | + lastReconcile := time.Now() |
| 64 | + gomega.Eventually(func(g gomega.Gomega) fdbv1beta2.FoundationDBRestoreState { |
| 65 | +- restore := &fdbv1beta2.FoundationDBRestore{} |
| 66 | +- g.Expect(ctrlClient.Get(context.Background(), client.ObjectKeyFromObject(backup.backup), restore)). |
| 67 | ++ currentRestore := &fdbv1beta2.FoundationDBRestore{} |
| 68 | ++ g.Expect(ctrlClient.Get(context.Background(), client.ObjectKeyFromObject(restore.restore), currentRestore)). |
| 69 | + To(gomega.Succeed()) |
| 70 | +- log.Println("restore state:", restore.Status.State) |
| 71 | ++ log.Println("restore state:", currentRestore.Status.State) |
| 72 | + |
| 73 | + if time.Since(lastReconcile) > time.Minute { |
| 74 | + lastReconcile = time.Now() |
| 75 | +- patch := client.MergeFrom(restore.DeepCopy()) |
| 76 | +- if restore.Annotations == nil { |
| 77 | +- restore.Annotations = make(map[string]string) |
| 78 | ++ patch := client.MergeFrom(currentRestore.DeepCopy()) |
| 79 | ++ if currentRestore.Annotations == nil { |
| 80 | ++ currentRestore.Annotations = make(map[string]string) |
| 81 | + } |
| 82 | +- restore.Annotations["foundationdb.org/reconcile"] = strconv.FormatInt( |
| 83 | ++ currentRestore.Annotations["foundationdb.org/reconcile"] = strconv.FormatInt( |
| 84 | + time.Now().UnixNano(), |
| 85 | + 10, |
| 86 | + ) |
0 commit comments