@@ -25,6 +25,7 @@ This test suite contains tests related to backup and restore with the operator.
2525*/
2626
2727import (
28+ "fmt"
2829 "log"
2930
3031 fdbv1beta2 "github.com/FoundationDB/fdb-kubernetes-operator/v2/api/v1beta2"
4041 factory * fixtures.Factory
4142 fdbCluster * fixtures.FdbCluster
4243 testOptions * fixtures.FactoryOptions
44+ backup * fixtures.FdbBackup
45+ restore * fixtures.FdbRestore
4346)
4447
4548func init () {
@@ -74,13 +77,115 @@ var _ = AfterSuite(func() {
7477 factory .Shutdown ()
7578})
7679
77- var _ = Describe ( "Operator Backup" , Label ( "e2e" , "pr" ), func ( ) {
78- When ( "a cluster has backups enabled and then restored" , func () {
80+ func describeBackupMode ( backupMode fdbv1beta2. BackupMode ) {
81+ Context ( fmt . Sprintf ( "when %s backup mode is used" , backupMode ) , func () {
7982 var keyValues []fixtures.KeyValue
8083 var prefix byte = 'a'
81- var backup * fixtures.FdbBackup
82- var restore * fixtures.FdbRestore
84+ var useRestorableVersion bool
85+ var backupConfiguration * fixtures.FdbBackupConfiguration
86+ var currentRestorableVersion * uint64
87+
88+ // Helper function to perform backup and setup
89+ performBackupSetup := func (shouldEnableEncryption bool , shouldUseRestorableVersion bool ) {
90+ log .Println ("creating backup for cluster" )
91+ var restorableVersion uint64
92+
93+ backupConfiguration = & fixtures.FdbBackupConfiguration {
94+ BackupType : ptr .To (fdbv1beta2 .BackupTypeDefault ),
95+ BackupMode : ptr .To (backupMode ),
96+ EncryptionEnabled : shouldEnableEncryption ,
97+ }
98+ useRestorableVersion = shouldUseRestorableVersion
99+
100+ if backupMode == fdbv1beta2 .BackupModeContinuous {
101+ // For the continuous backup we want to start the backup first and then write some data.
102+ backup = factory .CreateBackupForCluster (fdbCluster , backupConfiguration )
103+ keyValues = fdbCluster .GenerateRandomValues (10 , prefix )
104+ fdbCluster .WriteKeyValues (keyValues )
105+ restorableVersion = backup .WaitForRestorableVersion (
106+ fdbCluster .GetClusterVersion (),
107+ )
108+ backup .Stop ()
109+ } else {
110+ // In case of the one time backup we have to first write the keys and then do the backup.
111+ keyValues = fdbCluster .GenerateRandomValues (10 , prefix )
112+ fdbCluster .WriteKeyValues (keyValues )
113+ currentVersion := fdbCluster .GetClusterVersion ()
114+ backup = factory .CreateBackupForCluster (fdbCluster , backupConfiguration )
115+ restorableVersion = backup .WaitForRestorableVersion (
116+ currentVersion ,
117+ )
118+ }
119+
120+ // Delete the data and restore it again.
121+ fdbCluster .ClearRange ([]byte {prefix }, 60 )
122+ if useRestorableVersion {
123+ currentRestorableVersion = ptr .To (restorableVersion )
124+ }
125+ }
83126
127+ When ("no restorable version is specified" , func () {
128+ JustBeforeEach (func () {
129+ log .Println ("--no restorable version is specified--" )
130+ performBackupSetup (false , false )
131+ restore = factory .CreateRestoreForCluster (backup , currentRestorableVersion )
132+ })
133+
134+ It ("should restore the cluster successfully with a restorable version" , func () {
135+ Expect (fdbCluster .GetRange ([]byte {prefix }, 25 , 60 )).Should (Equal (keyValues ))
136+ })
137+ })
138+
139+ // TODO (johscheuer): Enable test once the CRD in CI is updated.
140+ PWhen ("using a restorable version" , func () {
141+ JustBeforeEach (func () {
142+ performBackupSetup (false , true )
143+ restore = factory .CreateRestoreForCluster (backup , currentRestorableVersion )
144+ })
145+
146+ It ("should restore the cluster successfully with a restorable version" , func () {
147+ Expect (fdbCluster .GetRange ([]byte {prefix }, 25 , 60 )).Should (Equal (keyValues ))
148+ })
149+ })
150+
151+ When ("encryption is enabled" , func () {
152+ JustBeforeEach (func () {
153+ if ! factory .GetFDBVersion ().IsAtLeast (fdbv1beta2 .Versions .SupportsBackupEncryption ) {
154+ Skip ("version doesn't support the encryption feature" )
155+ }
156+ performBackupSetup (true , false )
157+ })
158+
159+ When ("running describe command" , func () {
160+ var describeOutput string
161+
162+ JustBeforeEach (func () {
163+ describeOutput = backup .RunDescribeCommand ()
164+ })
165+
166+ // TODO (09harsh): Enable this test when we have the fileLevelEncryption in json parser
167+ // here: https://github.com/apple/foundationdb/blob/main/fdbclient/BackupContainer.actor.cpp#L193-L250
168+ PIt ("should have file level encryption enabled" , func () {
169+ fileLevelEncryption := gjson .Get (describeOutput , "FileLevelEncryption" ).Bool ()
170+ Expect (fileLevelEncryption ).To (BeTrue ())
171+ })
172+
173+ It ("should be able to restore the cluster successfully with a restorable version" , func () {
174+ restore = factory .CreateRestoreForCluster (backup , currentRestorableVersion )
175+ Expect (fdbCluster .GetRange ([]byte {prefix }, 25 , 60 )).Should (Equal (keyValues ))
176+ })
177+ })
178+
179+ It ("should restore the cluster successfully with a restorable version" , func () {
180+ restore = factory .CreateRestoreForCluster (backup , currentRestorableVersion )
181+ Expect (fdbCluster .GetRange ([]byte {prefix }, 25 , 60 )).Should (Equal (keyValues ))
182+ })
183+ })
184+ })
185+ }
186+
187+ var _ = Describe ("Operator Backup" , Label ("e2e" , "pr" ), func () {
188+ When ("a cluster has backups enabled and then restored" , func () {
84189 BeforeEach (func () {
85190 fdbCluster = factory .CreateFdbCluster (
86191 fixtures .DefaultClusterConfig (false ),
@@ -103,114 +208,15 @@ var _ = Describe("Operator Backup", Label("e2e", "pr"), func() {
103208 factory .RecreateOperatorPods (namespace )
104209 })
105210
106- When ("the default backup system is used" , func () {
107- DescribeTable ("backup modes" ,
108- func (backupMode fdbv1beta2.BackupMode ) {
109- var useRestorableVersion bool
110- var backupConfiguration * fixtures.FdbBackupConfiguration
111- var currentRestorableVersion * uint64
112-
113- // Helper function to perform backup and setup
114- performBackupSetup := func (shouldEnableEncryption bool , shouldUseRestorableVersion bool ) {
115- log .Println ("creating backup for cluster" )
116- var restorableVersion uint64
117-
118- backupConfiguration = & fixtures.FdbBackupConfiguration {
119- BackupType : ptr .To (fdbv1beta2 .BackupTypeDefault ),
120- BackupMode : ptr .To (backupMode ),
121- EncryptionEnabled : shouldEnableEncryption ,
122- }
123- useRestorableVersion = shouldUseRestorableVersion
124-
125- if backupMode == fdbv1beta2 .BackupModeContinuous {
126- // For the continuous backup we want to start the backup first and then write some data.
127- backup = factory .CreateBackupForCluster (fdbCluster , backupConfiguration )
128- keyValues = fdbCluster .GenerateRandomValues (10 , prefix )
129- fdbCluster .WriteKeyValues (keyValues )
130- restorableVersion = backup .WaitForRestorableVersion (
131- fdbCluster .GetClusterVersion (),
132- )
133- backup .Stop ()
134- } else {
135- // In case of the one time backup we have to first write the keys and then do the backup.
136- keyValues = fdbCluster .GenerateRandomValues (10 , prefix )
137- fdbCluster .WriteKeyValues (keyValues )
138- currentVersion := fdbCluster .GetClusterVersion ()
139- backup = factory .CreateBackupForCluster (fdbCluster , backupConfiguration )
140- restorableVersion = backup .WaitForRestorableVersion (
141- currentVersion ,
142- )
143- }
144-
145- // Delete the data and restore it again.
146- fdbCluster .ClearRange ([]byte {prefix }, 60 )
147- if useRestorableVersion {
148- currentRestorableVersion = ptr .To (restorableVersion )
149- }
150- }
151-
152- When ("no restorable version is specified" , func () {
153- JustBeforeEach (func () {
154- performBackupSetup (false , false )
155- restore = factory .CreateRestoreForCluster (backup , currentRestorableVersion )
156- })
157-
158- It ("should restore the cluster successfully with a restorable version" , func () {
159- Expect (fdbCluster .GetRange ([]byte {prefix }, 25 , 60 )).Should (Equal (keyValues ))
160- })
161- })
162-
163- // TODO (johscheuer): Enable test once the CRD in CI is updated.
164- PWhen ("using a restorable version" , func () {
165- JustBeforeEach (func () {
166- performBackupSetup (false , true )
167- restore = factory .CreateRestoreForCluster (backup , currentRestorableVersion )
168- })
169-
170- It ("should restore the cluster successfully with a restorable version" , func () {
171- Expect (fdbCluster .GetRange ([]byte {prefix }, 25 , 60 )).Should (Equal (keyValues ))
172- })
173- })
174-
175- When ("encryption is enabled" , func () {
176- JustBeforeEach (func () {
177- if ! factory .GetFDBVersion ().IsAtLeast (fdbv1beta2 .Versions .SupportsBackupEncryption ) {
178- Skip ("version doesn't support the encryption feature" )
179- }
180- performBackupSetup (true , false )
181- })
182-
183- When ("running describe command" , func () {
184- var describeOutput string
185-
186- JustBeforeEach (func () {
187- describeOutput = backup .RunDescribeCommand ()
188- })
189-
190- // TODO (09harsh): Enable this test when we have the fileLevelEncryption in json parser
191- // here: https://github.com/apple/foundationdb/blob/main/fdbclient/BackupContainer.actor.cpp#L193-L250
192- PIt ("should have file level encryption enabled" , func () {
193- fileLevelEncryption := gjson .Get (describeOutput , "FileLevelEncryption" ).Bool ()
194- Expect (fileLevelEncryption ).To (BeTrue ())
195- })
196-
197- It ("should be able to restore the cluster successfully with a restorable version" , func () {
198- restore = factory .CreateRestoreForCluster (backup , currentRestorableVersion )
199- Expect (fdbCluster .GetRange ([]byte {prefix }, 25 , 60 )).Should (Equal (keyValues ))
200- })
201- })
202-
203- It ("should restore the cluster successfully with a restorable version" , func () {
204- Expect (fdbCluster .GetRange ([]byte {prefix }, 25 , 60 )).Should (Equal (keyValues ))
205- })
206- })
207- },
208- Entry ("continuous backup mode" , fdbv1beta2 .BackupModeContinuous ),
209- Entry ("one time backup mode" , fdbv1beta2 .BackupModeOneTime ),
210- )
211+ FWhen ("the default backup system is used" , func () {
212+ describeBackupMode (fdbv1beta2 .BackupModeContinuous )
213+ describeBackupMode (fdbv1beta2 .BackupModeOneTime )
211214 })
212215
213216 When ("the partitioned backup system is used" , func () {
217+ var keyValues []fixtures.KeyValue
218+ var prefix byte = 'a'
219+
214220 BeforeEach (func () {
215221 // Versions before 7.4 have a few issues and will not work properly with the experimental feature.
216222 requiredFdbVersion , err := fdbv1beta2 .ParseFdbVersion ("7.4.5" )
0 commit comments