Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse existing plugin manager for get/put volume info #8012

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
outBackupFile io.Writer,
backupItemActionResolver framework.BackupItemActionResolverV2,
asyncBIAOperations []*itemoperation.BackupOperation,
backupStore persistence.BackupStore,
) error
}

Expand Down Expand Up @@ -610,6 +611,7 @@
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 @@
}).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)

Check warning on line 731 in pkg/backup/backup.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/backup.go#L731

Added line #L731 was not covered by tests
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 @@

func (kb *kubernetesBackupper) getVolumeInfos(
backup velerov1api.Backup,
backupStore persistence.BackupStore,
log logrus.FieldLogger,

Check failure on line 818 in pkg/backup/backup.go

View workflow job for this annotation

GitHub Actions / Run Linter Check

`(*kubernetesBackupper).getVolumeInfos` - `log` is unused (unparam)
) (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

Check warning on line 822 in pkg/backup/backup.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/backup.go#L822

Added line #L822 was not covered by tests
}

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
Loading