@@ -33,6 +33,108 @@ type ApplicationBackupRestoreCase struct {
3333 PvcSuffixName string
3434}
3535
36+ // OADPDeploymentOperation is a helper to deploy OADP resources for a given backup restore type.
37+ type OADPDeploymentOperation struct {
38+ CreateDPA bool
39+ CreateVolumeSnapshotClass bool
40+ CreateBSL bool
41+ CreateVSL bool
42+ }
43+
44+ func NewOADPDeploymentOperationDefault () * OADPDeploymentOperation {
45+ return & OADPDeploymentOperation {
46+ CreateDPA : true ,
47+ CreateVolumeSnapshotClass : true ,
48+ CreateBSL : false ,
49+ CreateVSL : false ,
50+ }
51+ }
52+
53+ func NewOADPDeploymentOperationROSA () * OADPDeploymentOperation {
54+ return & OADPDeploymentOperation {
55+ CreateDPA : false ,
56+ CreateVolumeSnapshotClass : false ,
57+ CreateBSL : true ,
58+ CreateVSL : true ,
59+ }
60+ }
61+
62+ func (o * OADPDeploymentOperation ) Deploy (backupRestoreType lib.BackupRestoreType ) {
63+ if o .CreateDPA {
64+ err := dpaCR .CreateOrUpdate (dpaCR .Build (backupRestoreType ))
65+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
66+
67+ log .Print ("Checking if DPA is reconciled" )
68+ gomega .Eventually (dpaCR .IsReconciledTrue (), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
69+
70+ if backupRestoreType == lib .RESTIC || backupRestoreType == lib .KOPIA || backupRestoreType == lib .CSIDataMover {
71+ log .Printf ("Waiting for Node Agent pods to be running" )
72+ gomega .Eventually (lib .AreNodeAgentPodsRunning (kubernetesClientForSuiteRun , namespace ), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
73+ }
74+ }
75+
76+ log .Printf ("Waiting for Velero Pod to be running" )
77+ gomega .Eventually (lib .VeleroPodIsRunning (kubernetesClientForSuiteRun , namespace ), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
78+
79+ if o .CreateVolumeSnapshotClass {
80+ if backupRestoreType == lib .CSI || backupRestoreType == lib .CSIDataMover {
81+ if provider == "aws" || provider == "ibmcloud" || provider == "gcp" || provider == "azure" || provider == "openstack" {
82+ log .Printf ("Creating VolumeSnapshotClass for CSI backuprestore" )
83+ snapshotClassPath := fmt .Sprintf ("./sample-applications/snapclass-csi/%s.yaml" , provider )
84+ err := lib .InstallApplication (dpaCR .Client , snapshotClassPath )
85+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
86+ }
87+ }
88+ }
89+
90+ if o .CreateBSL {
91+ log .Print ("Creating BSL" )
92+ err := dpaCR .CreateBackupStorageLocation ()
93+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
94+ }
95+
96+ log .Print ("Checking if BSL is available" )
97+ gomega .Eventually (dpaCR .BSLsAreAvailable (), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
98+
99+ if o .CreateVSL {
100+ log .Print ("Creating VSL" )
101+ err := dpaCR .CreateVolumeSnapshotLocation ()
102+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
103+ // Velero does not change status of VSL objects.
104+ // Users can only confirm if VSLs are correct configured when running a native snapshot backup/restore
105+ }
106+ }
107+
108+ func (o * OADPDeploymentOperation ) Undeploy (backupRestoreType lib.BackupRestoreType ) {
109+ if o .CreateVolumeSnapshotClass {
110+ if backupRestoreType == lib .CSI || backupRestoreType == lib .CSIDataMover {
111+ log .Printf ("Deleting VolumeSnapshot for CSI backuprestore" )
112+ snapshotClassPath := fmt .Sprintf ("./sample-applications/snapclass-csi/%s.yaml" , provider )
113+ err := lib .UninstallApplication (dpaCR .Client , snapshotClassPath )
114+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
115+ }
116+ }
117+
118+ if o .CreateDPA {
119+ log .Printf ("Deleting DPA" )
120+ err := dpaCR .Delete ()
121+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
122+ gomega .Eventually (dpaCR .IsDeleted (), time .Minute * 2 , time .Second * 5 ).Should (gomega .BeTrue ())
123+ }
124+
125+ if o .CreateBSL {
126+ log .Printf ("Deleting BSL" )
127+ err := dpaCR .DeleteBackupStorageLocation ()
128+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
129+ }
130+
131+ if o .CreateVSL {
132+ log .Printf ("Deleting VSL" )
133+ err := dpaCR .DeleteVolumeSnapshotLocation ()
134+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
135+ }
136+ }
137+
36138func todoListReady (preBackupState bool , twoVol bool , database string ) VerificationFunction {
37139 return VerificationFunction (func (ocClient client.Client , namespace string ) error {
38140 log .Printf ("checking for the NAMESPACE: %s" , namespace )
@@ -49,40 +151,10 @@ func todoListReady(preBackupState bool, twoVol bool, database string) Verificati
49151 })
50152}
51153
52- func waitOADPReadiness (backupRestoreType lib.BackupRestoreType ) {
53- err := dpaCR .CreateOrUpdate (dpaCR .Build (backupRestoreType ))
54- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
55-
56- log .Print ("Checking if DPA is reconciled" )
57- gomega .Eventually (dpaCR .IsReconciledTrue (), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
58-
59- log .Printf ("Waiting for Velero Pod to be running" )
60- gomega .Eventually (lib .VeleroPodIsRunning (kubernetesClientForSuiteRun , namespace ), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
61-
62- if backupRestoreType == lib .RESTIC || backupRestoreType == lib .KOPIA || backupRestoreType == lib .CSIDataMover {
63- log .Printf ("Waiting for Node Agent pods to be running" )
64- gomega .Eventually (lib .AreNodeAgentPodsRunning (kubernetesClientForSuiteRun , namespace ), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
65- }
66-
67- // Velero does not change status of VSL objects. Users can only confirm if VSLs are correct configured when running a native snapshot backup/restore
68-
69- log .Print ("Checking if BSL is available" )
70- gomega .Eventually (dpaCR .BSLsAreAvailable (), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
71- }
72-
73154func prepareBackupAndRestore (brCase BackupRestoreCase , updateLastInstallTime func ()) (string , string ) {
74155 updateLastInstallTime ()
75156
76- waitOADPReadiness (brCase .BackupRestoreType )
77-
78- if brCase .BackupRestoreType == lib .CSI || brCase .BackupRestoreType == lib .CSIDataMover {
79- if provider == "aws" || provider == "ibmcloud" || provider == "gcp" || provider == "azure" || provider == "openstack" {
80- log .Printf ("Creating VolumeSnapshotClass for CSI backuprestore of %s" , brCase .Name )
81- snapshotClassPath := fmt .Sprintf ("./sample-applications/snapclass-csi/%s.yaml" , provider )
82- err := lib .InstallApplication (dpaCR .Client , snapshotClassPath )
83- gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
84- }
85- }
157+ NewOADPDeploymentOperationDefault ().Deploy (brCase .BackupRestoreType )
86158
87159 // TODO: check registry deployments are deleted
88160 // TODO: check S3 for images
@@ -257,22 +329,10 @@ func getFailedTestLogs(oadpNamespace string, appNamespace string, installTime ti
257329func tearDownBackupAndRestore (brCase BackupRestoreCase , installTime time.Time , report ginkgo.SpecReport ) {
258330 log .Println ("Post backup and restore state: " , report .State .String ())
259331 gatherLogs (brCase , installTime , report )
260- tearDownDPAResources ( brCase )
332+ NewOADPDeploymentOperationDefault (). Undeploy ( brCase . BackupRestoreType )
261333 deleteNamespace (brCase .Namespace )
262334}
263335
264- func tearDownDPAResources (brCase BackupRestoreCase ) {
265- if brCase .BackupRestoreType == lib .CSI || brCase .BackupRestoreType == lib .CSIDataMover {
266- log .Printf ("Deleting VolumeSnapshot for CSI backuprestore of %s" , brCase .Name )
267- snapshotClassPath := fmt .Sprintf ("./sample-applications/snapclass-csi/%s.yaml" , provider )
268- err := lib .UninstallApplication (dpaCR .Client , snapshotClassPath )
269- gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
270- }
271-
272- err := dpaCR .Delete ()
273- gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
274- }
275-
276336func gatherLogs (brCase BackupRestoreCase , installTime time.Time , report ginkgo.SpecReport ) {
277337 if report .Failed () {
278338 knownFlake = lib .CheckIfFlakeOccurred (accumulatedTestLogs )
@@ -304,7 +364,7 @@ var _ = ginkgo.Describe("Backup and restore tests", ginkgo.Ordered, func() {
304364 var _ = ginkgo .AfterAll (func () {
305365 // DPA just needs to have BSL so gathering of backups/restores logs/describe work
306366 // using kopia to collect more info (DaemonSet)
307- waitOADPReadiness (lib .KOPIA )
367+ NewOADPDeploymentOperationDefault (). Deploy (lib .KOPIA )
308368
309369 log .Printf ("Creating real DataProtectionTest before must-gather" )
310370 bsls , err := dpaCR .ListBSLs ()
0 commit comments