@@ -1318,7 +1318,12 @@ func createMantleBackupUsingDummyPVC(ctx context.Context, name, ns string) (*man
13181318 return target , nil
13191319}
13201320
1321- func createSnapshotForMantleBackupUsingDummyPVC (ctx context.Context , cephCmd ceph.CephCmd , backup * mantlev1.MantleBackup ) error {
1321+ func createSnapshotForMantleBackupUsingDummyPVC (
1322+ ctx context.Context ,
1323+ cephCmd ceph.CephCmd ,
1324+ backup * mantlev1.MantleBackup ,
1325+ transferPartSize resource.Quantity ,
1326+ ) error {
13221327 snapName := util .GetUniqueName ("snap" )
13231328 if err := cephCmd .RBDSnapCreate (dummyPoolName , dummyImageName , snapName ); err != nil {
13241329 return err
@@ -1334,21 +1339,17 @@ func createSnapshotForMantleBackupUsingDummyPVC(ctx context.Context, cephCmd cep
13341339 if err := updateStatus (ctx , k8sClient , backup , func () error {
13351340 backup .Status .SnapID = & snaps [index ].Id
13361341 backup .Status .SnapSize = & snaps [index ].Size
1342+ backup .Status .TransferPartSize = & transferPartSize
13371343 return nil
13381344 }); err != nil {
13391345 return err
13401346 }
13411347 return nil
13421348}
13431349
1344- func setStatusTransferPartSize (ctx context.Context , backup * mantlev1.MantleBackup ) error {
1345- transferPartSize := resource .MustParse ("1Gi" )
1346- backup .Status .TransferPartSize = & transferPartSize
1347- if err := k8sClient .Status ().Update (ctx , backup ); err != nil {
1348- return err
1349- }
1350- return nil
1351- }
1350+ var (
1351+ defaultTransferPartSize = resource .MustParse ("1Gi" )
1352+ )
13521353
13531354var _ = Describe ("export and upload" , func () {
13541355 var mockCtrl * gomock.Controller
@@ -1368,7 +1369,7 @@ var _ = Describe("export and upload", func() {
13681369 target , err := createMantleBackupUsingDummyPVC (ctx , name , ns )
13691370 Expect (err ).NotTo (HaveOccurred ())
13701371
1371- err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , target )
1372+ err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , target , mbr . backupTransferPartSize )
13721373 Expect (err ).NotTo (HaveOccurred ())
13731374
13741375 grpcClient .EXPECT ().SetSynchronizing (gomock .Any (), gomock .Any ()).
@@ -1571,25 +1572,50 @@ var _ = Describe("export and upload", func() {
15711572 )
15721573
15731574 It ("should use the original transfer part size if it's changed" , func (ctx SpecContext ) {
1575+ // drop all items in the expire queue to avoid getting stuck
1576+ go func () {
1577+ for {
1578+ select {
1579+ case <- mbr .expireQueueCh :
1580+ case <- ctx .Done ():
1581+ return
1582+ }
1583+ }
1584+ }()
1585+ mbr .managedCephClusterID = resMgr .ClusterID
1586+ _ , pvc , err := resMgr .CreateUniquePVAndPVC (ctx , ns )
1587+ Expect (err ).NotTo (HaveOccurred ())
1588+ backup , err := resMgr .CreateUniqueBackupFor (ctx , pvc )
1589+ Expect (err ).NotTo (HaveOccurred ())
1590+
15741591 origSize := * resource .NewQuantity (testutil .FakeRBDSnapshotSize - 1 , resource .BinarySI )
1575- newSize := * resource .NewQuantity (testutil .FakeRBDSnapshotSize + 1 , resource .BinarySI )
15761592 mbr .backupTransferPartSize = origSize
1577- backup := createAndExportMantleBackup (ctx , mbr , "backup" , ns , false , false , nil )
1578- mbr .backupTransferPartSize = newSize
15791593
1580- // mimic as if the reconciler is called at least once after setting the new transfer part size.
1581- runStartExportAndUpload (ctx , backup )
1594+ // We use reconcileAsStandalone to focus on the part size update logic.
1595+ Eventually (func (g Gomega ) {
1596+ result , err := mbr .reconcileAsStandalone (ctx , backup )
1597+ g .Expect (result .IsZero ()).To (BeTrue ())
1598+ g .Expect (err ).NotTo (HaveOccurred ())
15821599
1583- Eventually (ctx , func (g Gomega , ctx SpecContext ) {
1584- err := k8sClient .Get (ctx , types.NamespacedName {Name : backup .GetName (), Namespace : backup .GetNamespace ()}, backup )
1585- Expect (err ).NotTo (HaveOccurred ())
1600+ err = k8sClient .Get (ctx , types.NamespacedName {Name : backup .GetName (), Namespace : backup .GetNamespace ()}, backup )
1601+ g .Expect (err ).NotTo (HaveOccurred ())
1602+ g .Expect (backup .Status .TransferPartSize ).NotTo (BeNil ())
1603+ g .Expect (backup .Status .TransferPartSize .Equal (origSize )).To (BeTrue ())
15861604 }).Should (Succeed ())
1587- Expect (backup .Status .TransferPartSize .Equal (origSize )).To (BeTrue ())
15881605
1589- completeJob (ctx , MakeExportJobName (backup , 0 ))
1590- runStartExportAndUpload (ctx , backup )
1591- completeJob (ctx , MakeExportJobName (backup , 1 ))
1592- runStartExportAndUpload (ctx , backup )
1606+ newSize := * resource .NewQuantity (testutil .FakeRBDSnapshotSize + 1 , resource .BinarySI )
1607+ mbr .backupTransferPartSize = newSize
1608+
1609+ Eventually (func (g Gomega ) {
1610+ result , err := mbr .reconcileAsStandalone (ctx , backup )
1611+ g .Expect (result .IsZero ()).To (BeTrue ())
1612+ g .Expect (err ).NotTo (HaveOccurred ())
1613+ }, "10s" ).Should (Succeed ())
1614+
1615+ err = k8sClient .Get (ctx , types.NamespacedName {Name : backup .GetName (), Namespace : backup .GetNamespace ()}, backup )
1616+ Expect (err ).NotTo (HaveOccurred ())
1617+ Expect (backup .Status .TransferPartSize ).NotTo (BeNil ())
1618+ Expect (backup .Status .TransferPartSize .Equal (origSize )).To (BeTrue ())
15931619 })
15941620 })
15951621
@@ -1703,13 +1729,12 @@ var _ = Describe("import", func() {
17031729 It ("should work correctly" , func (ctx SpecContext ) {
17041730 backup , err := createMantleBackupUsingDummyPVC (ctx , "target" , ns )
17051731 Expect (err ).NotTo (HaveOccurred ())
1706- err = setStatusTransferPartSize (ctx , backup )
1707- Expect (err ).NotTo (HaveOccurred ())
17081732
1709- // set .status.snapSize
1733+ // set .status.snapSize and .status.transferPartSize
17101734 err = updateStatus (ctx , k8sClient , backup , func () error {
1711- var i int64 = testutil .FakeRBDSnapshotSize
1712- backup .Status .SnapSize = & i
1735+ backup .Status .SnapSize = ptr .To (int64 (testutil .FakeRBDSnapshotSize ))
1736+ transferPartSize := resource .MustParse ("1Gi" )
1737+ backup .Status .TransferPartSize = & transferPartSize
17131738 return nil
17141739 })
17151740 Expect (err ).NotTo (HaveOccurred ())
@@ -1793,9 +1818,7 @@ var _ = Describe("import", func() {
17931818 backup .SetAnnotations (m )
17941819 err = k8sClient .Update (ctx , backup )
17951820 Expect (err ).NotTo (HaveOccurred ())
1796- err = setStatusTransferPartSize (ctx , backup )
1797- Expect (err ).NotTo (HaveOccurred ())
1798- err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , backup )
1821+ err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , backup , defaultTransferPartSize )
17991822 Expect (err ).NotTo (HaveOccurred ())
18001823 return backup
18011824 }
@@ -1888,7 +1911,7 @@ var _ = Describe("import", func() {
18881911 })
18891912 err = k8sClient .Update (ctx , source )
18901913 Expect (err ).NotTo (HaveOccurred ())
1891- err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , source )
1914+ err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , source , defaultTransferPartSize )
18921915 Expect (err ).NotTo (HaveOccurred ())
18931916
18941917 // Create target MantleBackup
@@ -1932,9 +1955,7 @@ var _ = Describe("import", func() {
19321955 It ("should work correctly if deletionTimestamp is set" , func (ctx SpecContext ) {
19331956 backup , err := createMantleBackupUsingDummyPVC (ctx , "target" , ns )
19341957 Expect (err ).NotTo (HaveOccurred ())
1935- err = setStatusTransferPartSize (ctx , backup )
1936- Expect (err ).NotTo (HaveOccurred ())
1937- err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , backup )
1958+ err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , backup , defaultTransferPartSize )
19381959 Expect (err ).NotTo (HaveOccurred ())
19391960
19401961 err = k8sClient .Delete (ctx , backup )
@@ -2039,9 +2060,7 @@ var _ = Describe("import", func() {
20392060 })
20402061 err = k8sClient .Update (ctx , source )
20412062 Expect (err ).NotTo (HaveOccurred ())
2042- err = setStatusTransferPartSize (ctx , source )
2043- Expect (err ).NotTo (HaveOccurred ())
2044- err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , source )
2063+ err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , source , defaultTransferPartSize )
20452064 Expect (err ).NotTo (HaveOccurred ())
20462065
20472066 // Create target MantleBackup
@@ -2096,9 +2115,7 @@ var _ = Describe("import", func() {
20962115 })
20972116 err = k8sClient .Update (ctx , backup )
20982117 Expect (err ).NotTo (HaveOccurred ())
2099- err = setStatusTransferPartSize (ctx , backup )
2100- Expect (err ).NotTo (HaveOccurred ())
2101- err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , backup )
2118+ err = createSnapshotForMantleBackupUsingDummyPVC (ctx , mbr .ceph , backup , defaultTransferPartSize )
21022119 Expect (err ).NotTo (HaveOccurred ())
21032120
21042121 err = k8sClient .Delete (ctx , backup )
0 commit comments