@@ -297,8 +297,6 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
297297 return err
298298 }
299299
300- backupRequest .BackedUpItems = map [itemKey ]struct {}{}
301-
302300 podVolumeTimeout := kb .podVolumeTimeout
303301 if val := backupRequest .Annotations [velerov1api .PodVolumeOperationTimeoutAnnotation ]; val != "" {
304302 parsed , err := time .ParseDuration (val )
@@ -499,20 +497,21 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
499497
500498 // updated total is computed as "how many items we've backed up so far, plus
501499 // how many items we know of that are remaining"
502- totalItems := len (backupRequest .BackedUpItems ) + (len (items ) - (i + 1 ))
500+ backedUpItems := backupRequest .BackedUpItems .Len ()
501+ totalItems := backedUpItems + (len (items ) - (i + 1 ))
503502
504503 // send a progress update
505504 update <- progressUpdate {
506505 totalItems : totalItems ,
507- itemsBackedUp : len ( backupRequest . BackedUpItems ) ,
506+ itemsBackedUp : backedUpItems ,
508507 }
509508
510509 log .WithFields (map [string ]interface {}{
511510 "progress" : "" ,
512511 "resource" : items [i ].groupResource .String (),
513512 "namespace" : items [i ].namespace ,
514513 "name" : items [i ].name ,
515- }).Infof ("Backed up %d items out of an estimated total of %d (estimate will change throughout the backup)" , len ( backupRequest . BackedUpItems ) , totalItems )
514+ }).Infof ("Backed up %d items out of an estimated total of %d (estimate will change throughout the backup)" , backedUpItems , totalItems )
516515 }
517516
518517 // no more progress updates will be sent on the 'update' channel
@@ -538,8 +537,9 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
538537 if updated .Status .Progress == nil {
539538 updated .Status .Progress = & velerov1api.BackupProgress {}
540539 }
541- updated .Status .Progress .TotalItems = len (backupRequest .BackedUpItems )
542- updated .Status .Progress .ItemsBackedUp = len (backupRequest .BackedUpItems )
540+ backedUpItems := backupRequest .BackedUpItems .Len ()
541+ updated .Status .Progress .TotalItems = backedUpItems
542+ updated .Status .Progress .ItemsBackedUp = backedUpItems
543543
544544 // update the hooks execution status
545545 if updated .Status .HookStatus == nil {
@@ -558,8 +558,8 @@ func (kb *kubernetesBackupper) BackupWithResolvers(
558558 log .Infof ("Summary for skipped PVs: %s" , skippedPVSummary )
559559 }
560560
561- backupRequest .Status .Progress = & velerov1api.BackupProgress {TotalItems : len ( backupRequest . BackedUpItems ) , ItemsBackedUp : len ( backupRequest . BackedUpItems ) }
562- log .WithField ("progress" , "" ).Infof ("Backed up a total of %d items" , len ( backupRequest . BackedUpItems ) )
561+ backupRequest .Status .Progress = & velerov1api.BackupProgress {TotalItems : backedUpItems , ItemsBackedUp : backedUpItems }
562+ log .WithField ("progress" , "" ).Infof ("Backed up a total of %d items" , backedUpItems )
563563
564564 return nil
565565}
@@ -667,7 +667,7 @@ func (kb *kubernetesBackupper) backupItemBlock(itemBlock BackupItemBlock) []sche
667667 continue
668668 }
669669 // Don't run hooks if pod has already been backed up
670- if _ , exists := itemBlock .itemBackupper .backupRequest .BackedUpItems [ key ]; ! exists {
670+ if ! itemBlock .itemBackupper .backupRequest .BackedUpItems . Has ( key ) {
671671 preHookPods = append (preHookPods , item )
672672 }
673673 }
@@ -681,7 +681,7 @@ func (kb *kubernetesBackupper) backupItemBlock(itemBlock BackupItemBlock) []sche
681681 itemBlock .Log .WithError (errors .WithStack (err )).Error ("Error accessing pod metadata" )
682682 continue
683683 }
684- itemBlock .itemBackupper .backupRequest .BackedUpItems [ key ] = struct {}{}
684+ itemBlock .itemBackupper .backupRequest .BackedUpItems . AddItem ( key )
685685 }
686686
687687 itemBlock .Log .Debug ("Backing up items in BackupItemBlock" )
@@ -861,8 +861,6 @@ func (kb *kubernetesBackupper) FinalizeBackup(
861861 return err
862862 }
863863
864- backupRequest .BackedUpItems = map [itemKey ]struct {}{}
865-
866864 // set up a temp dir for the itemCollector to use to temporarily
867865 // store items as they're scraped from the API.
868866 tempDir , err := os .MkdirTemp ("" , "" )
@@ -947,14 +945,15 @@ func (kb *kubernetesBackupper) FinalizeBackup(
947945
948946 // updated total is computed as "how many items we've backed up so far, plus
949947 // how many items we know of that are remaining"
950- totalItems := len (backupRequest .BackedUpItems ) + (len (items ) - (i + 1 ))
948+ backedUpItems := backupRequest .BackedUpItems .Len ()
949+ totalItems := backedUpItems + (len (items ) - (i + 1 ))
951950
952951 log .WithFields (map [string ]interface {}{
953952 "progress" : "" ,
954953 "resource" : item .groupResource .String (),
955954 "namespace" : item .namespace ,
956955 "name" : item .name ,
957- }).Infof ("Updated %d items out of an estimated total of %d (estimate will change throughout the backup finalizer)" , len ( backupRequest . BackedUpItems ) , totalItems )
956+ }).Infof ("Updated %d items out of an estimated total of %d (estimate will change throughout the backup finalizer)" , backedUpItems , totalItems )
958957 }
959958
960959 volumeInfos , err := backupStore .GetBackupVolumeInfos (backupRequest .Backup .Name )
@@ -979,7 +978,7 @@ func (kb *kubernetesBackupper) FinalizeBackup(
979978 return err
980979 }
981980
982- log .WithField ("progress" , "" ).Infof ("Updated a total of %d items" , len ( backupRequest .BackedUpItems ))
981+ log .WithField ("progress" , "" ).Infof ("Updated a total of %d items" , backupRequest .BackedUpItems . Len ( ))
983982
984983 return nil
985984}
0 commit comments