Skip to content

Commit

Permalink
Merge pull request #8012 from sseago/plugin-leak
Browse files Browse the repository at this point in the history
Reuse existing plugin manager for get/put volume info
  • Loading branch information
blackpiglet authored Jul 15, 2024
2 parents 3bd8a7d + dc286a3 commit 7f9fbab
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 22 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/8012-sseago
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Reuse existing plugin manager for get/put volume info
27 changes: 7 additions & 20 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type Backupper interface {
outBackupFile io.Writer,
backupItemActionResolver framework.BackupItemActionResolverV2,
asyncBIAOperations []*itemoperation.BackupOperation,
backupStore persistence.BackupStore,
) error
}

Expand Down Expand Up @@ -610,6 +611,7 @@ func (kb *kubernetesBackupper) FinalizeBackup(
outBackupFile io.Writer,
backupItemActionResolver framework.BackupItemActionResolverV2,
asyncBIAOperations []*itemoperation.BackupOperation,
backupStore persistence.BackupStore,
) error {
gzw := gzip.NewWriter(outBackupFile)
defer gzw.Close()
Expand Down Expand Up @@ -726,7 +728,7 @@ func (kb *kubernetesBackupper) FinalizeBackup(
}).Infof("Updated %d items out of an estimated total of %d (estimate will change throughout the backup finalizer)", len(backupRequest.BackedUpItems), totalItems)
}

backupStore, volumeInfos, err := kb.getVolumeInfos(*backupRequest.Backup, log)
volumeInfos, err := kb.getVolumeInfos(*backupRequest.Backup, backupStore, log)
if err != nil {
log.WithError(err).Errorf("fail to get the backup VolumeInfos for backup %s", backupRequest.Name)
return err
Expand Down Expand Up @@ -812,30 +814,15 @@ type tarWriter interface {

func (kb *kubernetesBackupper) getVolumeInfos(
backup velerov1api.Backup,
backupStore persistence.BackupStore,
log logrus.FieldLogger,
) (persistence.BackupStore, []*volume.BackupVolumeInfo, error) {
location := &velerov1api.BackupStorageLocation{}
if err := kb.kbClient.Get(context.Background(), kbclient.ObjectKey{
Namespace: backup.Namespace,
Name: backup.Spec.StorageLocation,
}, location); err != nil {
return nil, nil, errors.WithStack(err)
}

pluginManager := kb.pluginManager(log)
defer pluginManager.CleanupClients()

backupStore, storeErr := kb.backupStoreGetter.Get(location, pluginManager, log)
if storeErr != nil {
return nil, nil, storeErr
}

) ([]*volume.BackupVolumeInfo, error) {
volumeInfos, err := backupStore.GetBackupVolumeInfos(backup.Name)
if err != nil {
return nil, nil, err
return nil, err
}

return backupStore, volumeInfos, nil
return volumeInfos, nil
}

// updateVolumeInfos update the VolumeInfos according to the AsyncOperations
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4532,7 +4532,7 @@ func TestGetVolumeInfos(t *testing.T) {
bsl := builder.ForBackupStorageLocation("velero", "default").Result()
require.NoError(t, h.backupper.kbClient.Create(context.Background(), bsl))

_, _, err := h.backupper.getVolumeInfos(*backup, h.log)
_, err := h.backupper.getVolumeInfos(*backup, backupStore, h.log)
require.NoError(t, err)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/controller/backup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (b *fakeBackupper) FinalizeBackup(
outBackupFile io.Writer,
backupItemActionResolver framework.BackupItemActionResolverV2,
asyncBIAOperations []*itemoperation.BackupOperation,
backupStore persistence.BackupStore,
) error {
args := b.Called(logger, backup, inBackupFile, outBackupFile, backupItemActionResolver, asyncBIAOperations)
return args.Error(0)
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/backup_finalizer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (r *backupFinalizerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
outBackupFile,
backupItemActionsResolver,
operations,
backupStore,
)
if err != nil {
log.WithError(err).Error("error finalizing Backup")
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/backup_finalizer_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestBackupFinalizerReconcile(t *testing.T) {
backupStore.On("GetBackupVolumeInfos", mock.Anything).Return(nil, nil)
backupStore.On("PutBackupVolumeInfos", mock.Anything, mock.Anything).Return(nil)
pluginManager.On("GetBackupItemActionsV2").Return(nil, nil)
backupper.On("FinalizeBackup", mock.Anything, mock.Anything, mock.Anything, mock.Anything, framework.BackupItemActionResolverV2{}, mock.Anything).Return(nil)
backupper.On("FinalizeBackup", mock.Anything, mock.Anything, mock.Anything, mock.Anything, framework.BackupItemActionResolverV2{}, mock.Anything, mock.Anything).Return(nil)
_, err := reconciler.Reconcile(context.TODO(), ctrl.Request{NamespacedName: types.NamespacedName{Namespace: test.backup.Namespace, Name: test.backup.Name}})
gotErr := err != nil
assert.Equal(t, test.expectError, gotErr)
Expand Down

0 comments on commit 7f9fbab

Please sign in to comment.