mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-30 11:46:16 +00:00
Reduces ~140 indirect imports for plugin/framework importers (#8208)
* Avoid plugin framework importers from needing cloud provider imports Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
@@ -49,6 +49,8 @@ import (
|
||||
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/podvolume"
|
||||
"github.com/vmware-tanzu/velero/pkg/repository"
|
||||
repomanager "github.com/vmware-tanzu/velero/pkg/repository/manager"
|
||||
repotypes "github.com/vmware-tanzu/velero/pkg/repository/types"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/filesystem"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/kube"
|
||||
@@ -62,7 +64,7 @@ type backupDeletionReconciler struct {
|
||||
client.Client
|
||||
logger logrus.FieldLogger
|
||||
backupTracker BackupTracker
|
||||
repoMgr repository.Manager
|
||||
repoMgr repomanager.Manager
|
||||
metrics *metrics.ServerMetrics
|
||||
clock clock.Clock
|
||||
discoveryHelper discovery.Helper
|
||||
@@ -77,7 +79,7 @@ func NewBackupDeletionReconciler(
|
||||
logger logrus.FieldLogger,
|
||||
client client.Client,
|
||||
backupTracker BackupTracker,
|
||||
repoMgr repository.Manager,
|
||||
repoMgr repomanager.Manager,
|
||||
metrics *metrics.ServerMetrics,
|
||||
helper discovery.Helper,
|
||||
newPluginManager func(logrus.FieldLogger) clientmgmt.Manager,
|
||||
@@ -524,7 +526,7 @@ func (r *backupDeletionReconciler) deleteMovedSnapshots(ctx context.Context, bac
|
||||
return []error{errors.Wrapf(err, "failed to retrieve config for snapshot info")}
|
||||
}
|
||||
var errs []error
|
||||
directSnapshots := map[string][]repository.SnapshotIdentifier{}
|
||||
directSnapshots := map[string][]repotypes.SnapshotIdentifier{}
|
||||
for i := range list.Items {
|
||||
cm := list.Items[i]
|
||||
if cm.Data == nil || len(cm.Data) == 0 {
|
||||
@@ -538,7 +540,7 @@ func (r *backupDeletionReconciler) deleteMovedSnapshots(ctx context.Context, bac
|
||||
continue
|
||||
}
|
||||
|
||||
snapshot := repository.SnapshotIdentifier{}
|
||||
snapshot := repotypes.SnapshotIdentifier{}
|
||||
if err := json.Unmarshal(b, &snapshot); err != nil {
|
||||
errs = append(errs, errors.Wrapf(err, "failed to unmarshal snapshot info"))
|
||||
continue
|
||||
@@ -550,7 +552,7 @@ func (r *backupDeletionReconciler) deleteMovedSnapshots(ctx context.Context, bac
|
||||
}
|
||||
|
||||
if directSnapshots[snapshot.VolumeNamespace] == nil {
|
||||
directSnapshots[snapshot.VolumeNamespace] = []repository.SnapshotIdentifier{}
|
||||
directSnapshots[snapshot.VolumeNamespace] = []repotypes.SnapshotIdentifier{}
|
||||
}
|
||||
|
||||
directSnapshots[snapshot.VolumeNamespace] = append(directSnapshots[snapshot.VolumeNamespace], snapshot)
|
||||
@@ -618,7 +620,7 @@ func (r *backupDeletionReconciler) patchBackup(ctx context.Context, backup *vele
|
||||
|
||||
// getSnapshotsInBackup returns a list of all pod volume snapshot ids associated with
|
||||
// a given Velero backup.
|
||||
func getSnapshotsInBackup(ctx context.Context, backup *velerov1api.Backup, kbClient client.Client) (map[string][]repository.SnapshotIdentifier, error) {
|
||||
func getSnapshotsInBackup(ctx context.Context, backup *velerov1api.Backup, kbClient client.Client) (map[string][]repotypes.SnapshotIdentifier, error) {
|
||||
podVolumeBackups := &velerov1api.PodVolumeBackupList{}
|
||||
options := &client.ListOptions{
|
||||
LabelSelector: labels.Set(map[string]string{
|
||||
@@ -634,8 +636,8 @@ func getSnapshotsInBackup(ctx context.Context, backup *velerov1api.Backup, kbCli
|
||||
return podvolume.GetSnapshotIdentifier(podVolumeBackups), nil
|
||||
}
|
||||
|
||||
func batchDeleteSnapshots(ctx context.Context, repoEnsurer *repository.Ensurer, repoMgr repository.Manager,
|
||||
directSnapshots map[string][]repository.SnapshotIdentifier, backup *velerov1api.Backup, logger logrus.FieldLogger) []error {
|
||||
func batchDeleteSnapshots(ctx context.Context, repoEnsurer *repository.Ensurer, repoMgr repomanager.Manager,
|
||||
directSnapshots map[string][]repotypes.SnapshotIdentifier, backup *velerov1api.Backup, logger logrus.FieldLogger) []error {
|
||||
var errs []error
|
||||
for volumeNamespace, snapshots := range directSnapshots {
|
||||
batchForget := []string{}
|
||||
|
||||
@@ -55,7 +55,9 @@ import (
|
||||
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
|
||||
"github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks"
|
||||
"github.com/vmware-tanzu/velero/pkg/repository"
|
||||
repomanager "github.com/vmware-tanzu/velero/pkg/repository/manager"
|
||||
repomocks "github.com/vmware-tanzu/velero/pkg/repository/mocks"
|
||||
repotypes "github.com/vmware-tanzu/velero/pkg/repository/types"
|
||||
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||
)
|
||||
|
||||
@@ -698,13 +700,13 @@ func TestGetSnapshotsInBackup(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
podVolumeBackups []velerov1api.PodVolumeBackup
|
||||
expected map[string][]repository.SnapshotIdentifier
|
||||
expected map[string][]repotypes.SnapshotIdentifier
|
||||
longBackupNameEnabled bool
|
||||
}{
|
||||
{
|
||||
name: "no pod volume backups",
|
||||
podVolumeBackups: nil,
|
||||
expected: map[string][]repository.SnapshotIdentifier{},
|
||||
expected: map[string][]repotypes.SnapshotIdentifier{},
|
||||
},
|
||||
{
|
||||
name: "no pod volume backups with matching label",
|
||||
@@ -724,7 +726,7 @@ func TestGetSnapshotsInBackup(t *testing.T) {
|
||||
Status: velerov1api.PodVolumeBackupStatus{SnapshotID: "snap-2"},
|
||||
},
|
||||
},
|
||||
expected: map[string][]repository.SnapshotIdentifier{},
|
||||
expected: map[string][]repotypes.SnapshotIdentifier{},
|
||||
},
|
||||
{
|
||||
name: "some pod volume backups with matching label",
|
||||
@@ -765,7 +767,7 @@ func TestGetSnapshotsInBackup(t *testing.T) {
|
||||
Status: velerov1api.PodVolumeBackupStatus{SnapshotID: ""},
|
||||
},
|
||||
},
|
||||
expected: map[string][]repository.SnapshotIdentifier{
|
||||
expected: map[string][]repotypes.SnapshotIdentifier{
|
||||
"ns-1": {
|
||||
{
|
||||
VolumeNamespace: "ns-1",
|
||||
@@ -820,7 +822,7 @@ func TestGetSnapshotsInBackup(t *testing.T) {
|
||||
Status: velerov1api.PodVolumeBackupStatus{SnapshotID: ""},
|
||||
},
|
||||
},
|
||||
expected: map[string][]repository.SnapshotIdentifier{
|
||||
expected: map[string][]repotypes.SnapshotIdentifier{
|
||||
"ns-1": {
|
||||
{
|
||||
VolumeNamespace: "ns-1",
|
||||
@@ -856,18 +858,18 @@ func TestGetSnapshotsInBackup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func batchDeleteSucceed(ctx context.Context, repoEnsurer *repository.Ensurer, repoMgr repository.Manager, directSnapshots map[string][]repository.SnapshotIdentifier, backup *velerov1api.Backup, logger logrus.FieldLogger) []error {
|
||||
func batchDeleteSucceed(ctx context.Context, repoEnsurer *repository.Ensurer, repoMgr repomanager.Manager, directSnapshots map[string][]repotypes.SnapshotIdentifier, backup *velerov1api.Backup, logger logrus.FieldLogger) []error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func batchDeleteFail(ctx context.Context, repoEnsurer *repository.Ensurer, repoMgr repository.Manager, directSnapshots map[string][]repository.SnapshotIdentifier, backup *velerov1api.Backup, logger logrus.FieldLogger) []error {
|
||||
func batchDeleteFail(ctx context.Context, repoEnsurer *repository.Ensurer, repoMgr repomanager.Manager, directSnapshots map[string][]repotypes.SnapshotIdentifier, backup *velerov1api.Backup, logger logrus.FieldLogger) []error {
|
||||
return []error{
|
||||
errors.New("fake-delete-1"),
|
||||
errors.New("fake-delete-2"),
|
||||
}
|
||||
}
|
||||
|
||||
func generateSnapshotData(snapshot *repository.SnapshotIdentifier) (map[string]string, error) {
|
||||
func generateSnapshotData(snapshot *repotypes.SnapshotIdentifier) (map[string]string, error) {
|
||||
if snapshot == nil {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -888,10 +890,10 @@ func generateSnapshotData(snapshot *repository.SnapshotIdentifier) (map[string]s
|
||||
func TestDeleteMovedSnapshots(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repoMgr repository.Manager
|
||||
repoMgr repomanager.Manager
|
||||
batchDeleteSucceed bool
|
||||
backupName string
|
||||
snapshots []*repository.SnapshotIdentifier
|
||||
snapshots []*repotypes.SnapshotIdentifier
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
@@ -905,14 +907,14 @@ func TestDeleteMovedSnapshots(t *testing.T) {
|
||||
name: "bad cm info",
|
||||
repoMgr: repomocks.NewManager(t),
|
||||
backupName: "backup-01",
|
||||
snapshots: []*repository.SnapshotIdentifier{nil},
|
||||
snapshots: []*repotypes.SnapshotIdentifier{nil},
|
||||
expected: []string{"no snapshot info in config"},
|
||||
},
|
||||
{
|
||||
name: "invalid snapshots",
|
||||
repoMgr: repomocks.NewManager(t),
|
||||
backupName: "backup-01",
|
||||
snapshots: []*repository.SnapshotIdentifier{
|
||||
snapshots: []*repotypes.SnapshotIdentifier{
|
||||
{
|
||||
RepositoryType: "repo-1",
|
||||
VolumeNamespace: "ns-1",
|
||||
@@ -937,7 +939,7 @@ func TestDeleteMovedSnapshots(t *testing.T) {
|
||||
name: "batch delete succeed",
|
||||
repoMgr: repomocks.NewManager(t),
|
||||
backupName: "backup-01",
|
||||
snapshots: []*repository.SnapshotIdentifier{
|
||||
snapshots: []*repotypes.SnapshotIdentifier{
|
||||
|
||||
{
|
||||
SnapshotID: "snapshot-1",
|
||||
@@ -952,7 +954,7 @@ func TestDeleteMovedSnapshots(t *testing.T) {
|
||||
name: "batch delete fail",
|
||||
repoMgr: repomocks.NewManager(t),
|
||||
backupName: "backup-01",
|
||||
snapshots: []*repository.SnapshotIdentifier{
|
||||
snapshots: []*repotypes.SnapshotIdentifier{
|
||||
{
|
||||
RepositoryType: "repo-1",
|
||||
VolumeNamespace: "ns-1",
|
||||
|
||||
@@ -35,14 +35,14 @@ import (
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/constant"
|
||||
"github.com/vmware-tanzu/velero/pkg/label"
|
||||
"github.com/vmware-tanzu/velero/pkg/repository"
|
||||
repoconfig "github.com/vmware-tanzu/velero/pkg/repository/config"
|
||||
repomanager "github.com/vmware-tanzu/velero/pkg/repository/manager"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/kube"
|
||||
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -57,11 +57,11 @@ type BackupRepoReconciler struct {
|
||||
clock clocks.WithTickerAndDelayedExecution
|
||||
maintenanceFrequency time.Duration
|
||||
backupRepoConfig string
|
||||
repositoryManager repository.Manager
|
||||
repositoryManager repomanager.Manager
|
||||
}
|
||||
|
||||
func NewBackupRepoReconciler(namespace string, logger logrus.FieldLogger, client client.Client,
|
||||
maintenanceFrequency time.Duration, backupRepoConfig string, repositoryManager repository.Manager) *BackupRepoReconciler {
|
||||
maintenanceFrequency time.Duration, backupRepoConfig string, repositoryManager repomanager.Manager) *BackupRepoReconciler {
|
||||
c := &BackupRepoReconciler{
|
||||
client,
|
||||
namespace,
|
||||
@@ -294,7 +294,7 @@ func (r *BackupRepoReconciler) getRepositoryMaintenanceFrequency(req *velerov1ap
|
||||
|
||||
// ensureRepo calls repo manager's PrepareRepo to ensure the repo is ready for use.
|
||||
// An error is returned if the repository can't be connected to or initialized.
|
||||
func ensureRepo(repo *velerov1api.BackupRepository, repoManager repository.Manager) error {
|
||||
func ensureRepo(repo *velerov1api.BackupRepository, repoManager repomanager.Manager) error {
|
||||
return repoManager.PrepareRepo(repo)
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import (
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/repository"
|
||||
repomokes "github.com/vmware-tanzu/velero/pkg/repository/mocks"
|
||||
repotypes "github.com/vmware-tanzu/velero/pkg/repository/types"
|
||||
velerotest "github.com/vmware-tanzu/velero/pkg/test"
|
||||
|
||||
clientFake "sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
@@ -210,7 +210,7 @@ func TestBackupRepoReconcile(t *testing.T) {
|
||||
func TestGetRepositoryMaintenanceFrequency(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
mgr repository.Manager
|
||||
mgr repotypes.SnapshotIdentifier
|
||||
repo *velerov1api.BackupRepository
|
||||
freqReturn time.Duration
|
||||
freqError error
|
||||
|
||||
Reference in New Issue
Block a user