@@ -43,6 +43,108 @@ type ApplicationBackupRestoreCase struct {
4343 PvcSuffixName string
4444}
4545
46+ // OADPDeploymentOperation is a helper to deploy OADP resources for a given backup restore type.
47+ type OADPDeploymentOperation struct {
48+ CreateDPA bool
49+ CreateVolumeSnapshotClass bool
50+ CreateBSL bool
51+ CreateVSL bool
52+ }
53+
54+ func NewOADPDeploymentOperationDefault () * OADPDeploymentOperation {
55+ return & OADPDeploymentOperation {
56+ CreateDPA : true ,
57+ CreateVolumeSnapshotClass : true ,
58+ CreateBSL : false ,
59+ CreateVSL : false ,
60+ }
61+ }
62+
63+ func NewOADPDeploymentOperationROSA () * OADPDeploymentOperation {
64+ return & OADPDeploymentOperation {
65+ CreateDPA : false ,
66+ CreateVolumeSnapshotClass : false ,
67+ CreateBSL : true ,
68+ CreateVSL : true ,
69+ }
70+ }
71+
72+ func (o * OADPDeploymentOperation ) Deploy (backupRestoreType lib.BackupRestoreType ) {
73+ if o .CreateDPA {
74+ err := dpaCR .CreateOrUpdate (dpaCR .Build (backupRestoreType ))
75+ gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
76+
77+ log .Print ("Checking if DPA is reconciled" )
78+ gomega .Eventually (dpaCR .IsReconciledTrue (), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
79+
80+ if backupRestoreType == lib .KOPIA || backupRestoreType == lib .CSIDataMover {
81+ log .Printf ("Waiting for Node Agent pods to be running" )
82+ gomega .Eventually (lib .AreNodeAgentPodsRunning (kubernetesClientForSuiteRun , namespace ), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
83+ }
84+ }
85+
86+ log .Printf ("Waiting for Velero Pod to be running" )
87+ gomega .Eventually (lib .VeleroPodIsRunning (kubernetesClientForSuiteRun , namespace ), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
88+
89+ if o .CreateVolumeSnapshotClass {
90+ if backupRestoreType == lib .CSI || backupRestoreType == lib .CSIDataMover {
91+ if provider == "aws" || provider == "ibmcloud" || provider == "gcp" || provider == "azure" || provider == "openstack" {
92+ log .Printf ("Creating VolumeSnapshotClass for CSI backuprestore" )
93+ snapshotClassPath := fmt .Sprintf ("./sample-applications/snapclass-csi/%s.yaml" , provider )
94+ err := lib .InstallApplication (dpaCR .Client , snapshotClassPath )
95+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
96+ }
97+ }
98+ }
99+
100+ if o .CreateBSL {
101+ log .Print ("Creating BSL" )
102+ err := dpaCR .CreateBackupStorageLocation ()
103+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
104+ }
105+
106+ log .Print ("Checking if BSL is available" )
107+ gomega .Eventually (dpaCR .BSLsAreAvailable (), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
108+
109+ if o .CreateVSL {
110+ log .Print ("Creating VSL" )
111+ err := dpaCR .CreateVolumeSnapshotLocation ()
112+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
113+ // Velero does not change status of VSL objects.
114+ // Users can only confirm if VSLs are correct configured when running a native snapshot backup/restore
115+ }
116+ }
117+
118+ func (o * OADPDeploymentOperation ) Undeploy (backupRestoreType lib.BackupRestoreType ) {
119+ if o .CreateVolumeSnapshotClass {
120+ if backupRestoreType == lib .CSI || backupRestoreType == lib .CSIDataMover {
121+ log .Printf ("Deleting VolumeSnapshot for CSI backuprestore" )
122+ snapshotClassPath := fmt .Sprintf ("./sample-applications/snapclass-csi/%s.yaml" , provider )
123+ err := lib .UninstallApplication (dpaCR .Client , snapshotClassPath )
124+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
125+ }
126+ }
127+
128+ if o .CreateDPA {
129+ log .Printf ("Deleting DPA" )
130+ err := dpaCR .Delete ()
131+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
132+ gomega .Eventually (dpaCR .IsDeleted (), time .Minute * 2 , time .Second * 5 ).Should (gomega .BeTrue ())
133+ }
134+
135+ if o .CreateBSL {
136+ log .Printf ("Deleting BSL" )
137+ err := dpaCR .DeleteBackupStorageLocation ()
138+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
139+ }
140+
141+ if o .CreateVSL {
142+ log .Printf ("Deleting VSL" )
143+ err := dpaCR .DeleteVolumeSnapshotLocation ()
144+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
145+ }
146+ }
147+
46148func todoListReady (preBackupState bool , twoVol bool , database string ) VerificationFunction {
47149 return VerificationFunction (func (ocClient client.Client , namespace string ) error {
48150 log .Printf ("checking for the NAMESPACE: %s" , namespace )
@@ -72,40 +174,10 @@ func parksAppReady(preBackupState bool, twoVol bool, DCReadyCheck bool) Verifica
72174 })
73175}
74176
75- func waitOADPReadiness (backupRestoreType lib.BackupRestoreType ) {
76- err := dpaCR .CreateOrUpdate (dpaCR .Build (backupRestoreType ))
77- gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
78-
79- log .Print ("Checking if DPA is reconciled" )
80- gomega .Eventually (dpaCR .IsReconciledTrue (), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
81-
82- log .Printf ("Waiting for Velero Pod to be running" )
83- gomega .Eventually (lib .VeleroPodIsRunning (kubernetesClientForSuiteRun , namespace ), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
84-
85- if backupRestoreType == lib .KOPIA || backupRestoreType == lib .CSIDataMover {
86- log .Printf ("Waiting for Node Agent pods to be running" )
87- gomega .Eventually (lib .AreNodeAgentPodsRunning (kubernetesClientForSuiteRun , namespace ), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
88- }
89-
90- // Velero does not change status of VSL objects. Users can only confirm if VSLs are correct configured when running a native snapshot backup/restore
91-
92- log .Print ("Checking if BSL is available" )
93- gomega .Eventually (dpaCR .BSLsAreAvailable (), time .Minute * 3 , time .Second * 5 ).Should (gomega .BeTrue ())
94- }
95-
96177func prepareBackupAndRestore (brCase BackupRestoreCase , updateLastInstallTime func ()) (string , string ) {
97178 updateLastInstallTime ()
98179
99- waitOADPReadiness (brCase .BackupRestoreType )
100-
101- if brCase .BackupRestoreType == lib .CSI || brCase .BackupRestoreType == lib .CSIDataMover {
102- if provider == "aws" || provider == "ibmcloud" || provider == "gcp" || provider == "azure" || provider == "openstack" {
103- log .Printf ("Creating VolumeSnapshotClass for CSI backuprestore of %s" , brCase .Name )
104- snapshotClassPath := fmt .Sprintf ("./sample-applications/snapclass-csi/%s.yaml" , provider )
105- err := lib .InstallApplication (dpaCR .Client , snapshotClassPath )
106- gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
107- }
108- }
180+ NewOADPDeploymentOperationDefault ().Deploy (brCase .BackupRestoreType )
109181
110182 // TODO: check registry deployments are deleted
111183 // TODO: check S3 for images
@@ -319,22 +391,10 @@ func getFailedTestLogs(oadpNamespace string, appNamespace string, installTime ti
319391func tearDownBackupAndRestore (brCase BackupRestoreCase , installTime time.Time , report ginkgo.SpecReport ) {
320392 log .Println ("Post backup and restore state: " , report .State .String ())
321393 gatherLogs (brCase , installTime , report )
322- tearDownDPAResources ( brCase )
394+ NewOADPDeploymentOperationDefault (). Undeploy ( brCase . BackupRestoreType )
323395 deleteNamespace (brCase .Namespace )
324396}
325397
326- func tearDownDPAResources (brCase BackupRestoreCase ) {
327- if brCase .BackupRestoreType == lib .CSI || brCase .BackupRestoreType == lib .CSIDataMover {
328- log .Printf ("Deleting VolumeSnapshot for CSI backuprestore of %s" , brCase .Name )
329- snapshotClassPath := fmt .Sprintf ("./sample-applications/snapclass-csi/%s.yaml" , provider )
330- err := lib .UninstallApplication (dpaCR .Client , snapshotClassPath )
331- gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
332- }
333-
334- err := dpaCR .Delete ()
335- gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
336- }
337-
338398func gatherLogs (brCase BackupRestoreCase , installTime time.Time , report ginkgo.SpecReport ) {
339399 if report .Failed () {
340400 knownFlake = lib .CheckIfFlakeOccurred (accumulatedTestLogs )
@@ -366,7 +426,7 @@ var _ = ginkgo.Describe("Backup and restore tests", ginkgo.Ordered, func() {
366426 var _ = ginkgo .AfterAll (func () {
367427 // DPA just needs to have BSL so gathering of backups/restores logs/describe work
368428 // using kopia to collect more info (DaemonSet)
369- waitOADPReadiness (lib .KOPIA )
429+ NewOADPDeploymentOperationDefault (). Deploy (lib .KOPIA )
370430
371431 //DPT Test and MustGather should be paired together
372432 log .Printf ("skipMustGather: %v" , skipMustGather )
0 commit comments