diff --git a/changelogs/unreleased/6177-blackpiglet b/changelogs/unreleased/6177-blackpiglet new file mode 100644 index 0000000000..11a9267cca --- /dev/null +++ b/changelogs/unreleased/6177-blackpiglet @@ -0,0 +1 @@ +Enable linter revive and resolve found errors: part 2 \ No newline at end of file diff --git a/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action.go b/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action.go index 6cbca3f525..4bc28e487d 100644 --- a/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action.go +++ b/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action.go @@ -74,7 +74,7 @@ func (r *RestartableBackupItemAction) getBackupItemAction() (biav1.BackupItemAct backupItemAction, ok := plugin.(biav1.BackupItemAction) if !ok { - return nil, errors.Errorf("%T is not a BackupItemAction!", plugin) + return nil, errors.Errorf("plugin %T is not a BackupItemAction", plugin) } return backupItemAction, nil diff --git a/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go b/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go index 53bf0e4de8..ce8d072614 100644 --- a/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go +++ b/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go @@ -48,7 +48,7 @@ func TestRestartableGetBackupItemAction(t *testing.T) { { name: "wrong type", plugin: 3, - expectedError: "int is not a BackupItemAction!", + expectedError: "plugin int is not a BackupItemAction", }, { name: "happy path", diff --git a/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action.go b/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action.go index c3121b1aac..84ddb54b2b 100644 --- a/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action.go +++ b/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action.go @@ -81,7 +81,7 @@ func (r *RestartableBackupItemAction) getBackupItemAction() (biav2.BackupItemAct backupItemAction, ok := plugin.(biav2.BackupItemAction) if !ok { - return nil, errors.Errorf("%T (returned for %v) is not a BackupItemActionV2!", plugin, r.Key) + return nil, errors.Errorf("plugin %T (returned for %v) is not a BackupItemActionV2", plugin, r.Key) } return backupItemAction, nil diff --git a/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go b/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go index 9d2f66c34b..efcb94927c 100644 --- a/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go +++ b/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go @@ -48,7 +48,7 @@ func TestRestartableGetBackupItemAction(t *testing.T) { { name: "wrong type", plugin: 3, - expectedError: "int (returned for {BackupItemActionV2 pod}) is not a BackupItemActionV2!", + expectedError: "plugin int (returned for {BackupItemActionV2 pod}) is not a BackupItemActionV2", }, { name: "happy path", diff --git a/pkg/plugin/clientmgmt/manager.go b/pkg/plugin/clientmgmt/manager.go index aafb398a0c..febc77276c 100644 --- a/pkg/plugin/clientmgmt/manager.go +++ b/pkg/plugin/clientmgmt/manager.go @@ -166,7 +166,7 @@ func (m *manager) GetObjectStore(name string) (velero.ObjectStore, error) { return nil, err } - r := NewRestartableObjectStore(name, restartableProcess) + r := newRestartableObjectStore(name, restartableProcess) return r, nil } @@ -370,7 +370,7 @@ func (m *manager) GetDeleteItemAction(name string) (velero.DeleteItemAction, err return nil, err } - r := NewRestartableDeleteItemAction(name, restartableProcess) + r := newRestartableDeleteItemAction(name, restartableProcess) return r, nil } diff --git a/pkg/plugin/clientmgmt/process/process.go b/pkg/plugin/clientmgmt/process/process.go index b6be276871..dea0195536 100644 --- a/pkg/plugin/clientmgmt/process/process.go +++ b/pkg/plugin/clientmgmt/process/process.go @@ -26,14 +26,14 @@ import ( "github.com/vmware-tanzu/velero/pkg/plugin/framework/common" ) -type ProcessFactory interface { +type Factory interface { newProcess(command string, logger logrus.FieldLogger, logLevel logrus.Level) (Process, error) } type processFactory struct { } -func newProcessFactory() ProcessFactory { +func newProcessFactory() Factory { return &processFactory{} } diff --git a/pkg/plugin/clientmgmt/process/registry.go b/pkg/plugin/clientmgmt/process/registry.go index 11a6bf43ed..6238c45fb0 100644 --- a/pkg/plugin/clientmgmt/process/registry.go +++ b/pkg/plugin/clientmgmt/process/registry.go @@ -52,7 +52,7 @@ type registry struct { logger logrus.FieldLogger logLevel logrus.Level - processFactory ProcessFactory + processFactory Factory fs filesystem.Interface pluginsByID map[KindAndName]framework.PluginIdentifier pluginsByKind map[common.PluginKind][]framework.PluginIdentifier diff --git a/pkg/plugin/clientmgmt/restartable_delete_item_action.go b/pkg/plugin/clientmgmt/restartable_delete_item_action.go index 3ae70dd2f7..75fabaf66f 100644 --- a/pkg/plugin/clientmgmt/restartable_delete_item_action.go +++ b/pkg/plugin/clientmgmt/restartable_delete_item_action.go @@ -33,8 +33,8 @@ type restartableDeleteItemAction struct { sharedPluginProcess process.RestartableProcess } -// NewRestartableDeleteItemAction returns a new restartableDeleteItemAction. -func NewRestartableDeleteItemAction(name string, sharedPluginProcess process.RestartableProcess) *restartableDeleteItemAction { +// newRestartableDeleteItemAction returns a new restartableDeleteItemAction. +func newRestartableDeleteItemAction(name string, sharedPluginProcess process.RestartableProcess) *restartableDeleteItemAction { r := &restartableDeleteItemAction{ key: process.KindAndName{Kind: common.PluginKindDeleteItemAction, Name: name}, sharedPluginProcess: sharedPluginProcess, @@ -52,7 +52,7 @@ func (r *restartableDeleteItemAction) getDeleteItemAction() (velero.DeleteItemAc deleteItemAction, ok := plugin.(velero.DeleteItemAction) if !ok { - return nil, errors.Errorf("%T is not a DeleteItemAction!", plugin) + return nil, errors.Errorf("plugin %T is not a DeleteItemAction", plugin) } return deleteItemAction, nil diff --git a/pkg/plugin/clientmgmt/restartable_delete_item_action_test.go b/pkg/plugin/clientmgmt/restartable_delete_item_action_test.go index fae5444aca..4c3bca035c 100644 --- a/pkg/plugin/clientmgmt/restartable_delete_item_action_test.go +++ b/pkg/plugin/clientmgmt/restartable_delete_item_action_test.go @@ -47,7 +47,7 @@ func TestRestartableGetDeleteItemAction(t *testing.T) { { name: "wrong type", plugin: 3, - expectedError: "int is not a DeleteItemAction!", + expectedError: "plugin int is not a DeleteItemAction", }, { name: "happy path", @@ -64,7 +64,7 @@ func TestRestartableGetDeleteItemAction(t *testing.T) { key := process.KindAndName{Kind: common.PluginKindDeleteItemAction, Name: name} p.On("GetByKindAndName", key).Return(tc.plugin, tc.getError) - r := NewRestartableDeleteItemAction(name, p) + r := newRestartableDeleteItemAction(name, p) a, err := r.getDeleteItemAction() if tc.expectedError != "" { assert.EqualError(t, err, tc.expectedError) @@ -84,7 +84,7 @@ func TestRestartableDeleteItemActionGetDelegate(t *testing.T) { // Reset error p.On("ResetIfNeeded").Return(errors.Errorf("reset error")).Once() name := "pod" - r := NewRestartableDeleteItemAction(name, p) + r := newRestartableDeleteItemAction(name, p) a, err := r.getDelegate() assert.Nil(t, a) assert.EqualError(t, err, "reset error") diff --git a/pkg/plugin/clientmgmt/restartable_object_store.go b/pkg/plugin/clientmgmt/restartable_object_store.go index a3552bd0ab..1ac8f301ee 100644 --- a/pkg/plugin/clientmgmt/restartable_object_store.go +++ b/pkg/plugin/clientmgmt/restartable_object_store.go @@ -39,8 +39,8 @@ type restartableObjectStore struct { config map[string]string } -// NewRestartableObjectStore returns a new restartableObjectStore. -func NewRestartableObjectStore(name string, sharedPluginProcess process.RestartableProcess) *restartableObjectStore { +// newRestartableObjectStore returns a new restartableObjectStore. +func newRestartableObjectStore(name string, sharedPluginProcess process.RestartableProcess) *restartableObjectStore { key := process.KindAndName{Kind: common.PluginKindObjectStore, Name: name} r := &restartableObjectStore{ key: key, @@ -57,7 +57,7 @@ func NewRestartableObjectStore(name string, sharedPluginProcess process.Restarta func (r *restartableObjectStore) Reinitialize(dispensed interface{}) error { objectStore, ok := dispensed.(velero.ObjectStore) if !ok { - return errors.Errorf("%T is not a ObjectStore!", dispensed) + return errors.Errorf("plugin %T is not a ObjectStore", dispensed) } return r.init(objectStore, r.config) @@ -73,7 +73,7 @@ func (r *restartableObjectStore) getObjectStore() (velero.ObjectStore, error) { objectStore, ok := plugin.(velero.ObjectStore) if !ok { - return nil, errors.Errorf("%T is not a ObjectStore!", plugin) + return nil, errors.Errorf("plugin %T is not a ObjectStore", plugin) } return objectStore, nil diff --git a/pkg/plugin/clientmgmt/restartable_object_store_test.go b/pkg/plugin/clientmgmt/restartable_object_store_test.go index fcdf121e2e..04cdedda0e 100644 --- a/pkg/plugin/clientmgmt/restartable_object_store_test.go +++ b/pkg/plugin/clientmgmt/restartable_object_store_test.go @@ -47,7 +47,7 @@ func TestRestartableGetObjectStore(t *testing.T) { { name: "wrong type", plugin: 3, - expectedError: "int is not a ObjectStore!", + expectedError: "plugin int is not a ObjectStore", }, { name: "happy path", @@ -97,7 +97,7 @@ func TestRestartableObjectStoreReinitialize(t *testing.T) { } err := r.Reinitialize(3) - assert.EqualError(t, err, "int is not a ObjectStore!") + assert.EqualError(t, err, "plugin int is not a ObjectStore") objectStore := new(providermocks.ObjectStore) objectStore.Test(t) diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go index adc61ed431..a03ccecd2a 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action.go @@ -72,7 +72,7 @@ func (r *RestartableRestoreItemAction) getRestoreItemAction() (riav1.RestoreItem restoreItemAction, ok := plugin.(riav1.RestoreItemAction) if !ok { - return nil, errors.Errorf("%T is not a RestoreItemAction!", plugin) + return nil, errors.Errorf("plugin %T is not a RestoreItemAction", plugin) } return restoreItemAction, nil diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go index d16e3bb1fe..e00a6fddae 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go @@ -47,7 +47,7 @@ func TestRestartableGetRestoreItemAction(t *testing.T) { { name: "wrong type", plugin: 3, - expectedError: "int is not a RestoreItemAction!", + expectedError: "plugin int is not a RestoreItemAction", }, { name: "happy path", diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action.go b/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action.go index c5326aa829..c23787cfb7 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action.go @@ -80,7 +80,7 @@ func (r *RestartableRestoreItemAction) getRestoreItemAction() (riav2.RestoreItem restoreItemAction, ok := plugin.(riav2.RestoreItemAction) if !ok { - return nil, errors.Errorf("%T is not a RestoreItemActionV2!", plugin) + return nil, errors.Errorf("plugin %T is not a RestoreItemActionV2", plugin) } return restoreItemAction, nil diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go b/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go index 3c3dc1cadf..73d4f81455 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go @@ -47,7 +47,7 @@ func TestRestartableGetRestoreItemAction(t *testing.T) { { name: "wrong type", plugin: 3, - expectedError: "int is not a RestoreItemActionV2!", + expectedError: "plugin int is not a RestoreItemActionV2", }, { name: "happy path", diff --git a/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go b/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go index 00a6742347..a7d2b4223e 100644 --- a/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go +++ b/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go @@ -72,7 +72,7 @@ func NewRestartableVolumeSnapshotter(name string, sharedPluginProcess process.Re func (r *RestartableVolumeSnapshotter) Reinitialize(dispensed interface{}) error { volumeSnapshotter, ok := dispensed.(vsv1.VolumeSnapshotter) if !ok { - return errors.Errorf("%T is not a VolumeSnapshotter!", dispensed) + return errors.Errorf("plugin %T is not a VolumeSnapshotter", dispensed) } return r.init(volumeSnapshotter, r.config) } @@ -87,7 +87,7 @@ func (r *RestartableVolumeSnapshotter) getVolumeSnapshotter() (vsv1.VolumeSnapsh volumeSnapshotter, ok := plugin.(vsv1.VolumeSnapshotter) if !ok { - return nil, errors.Errorf("%T is not a VolumeSnapshotter!", plugin) + return nil, errors.Errorf("plugin %T is not a VolumeSnapshotter", plugin) } return volumeSnapshotter, nil diff --git a/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go b/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go index 787191ec05..13d7852346 100644 --- a/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go +++ b/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go @@ -46,7 +46,7 @@ func TestRestartableGetVolumeSnapshotter(t *testing.T) { { name: "wrong type", plugin: 3, - expectedError: "int is not a VolumeSnapshotter!", + expectedError: "plugin int is not a VolumeSnapshotter", }, { name: "happy path", @@ -96,7 +96,7 @@ func TestRestartableVolumeSnapshotterReinitialize(t *testing.T) { } err := r.Reinitialize(3) - assert.EqualError(t, err, "int is not a VolumeSnapshotter!") + assert.EqualError(t, err, "plugin int is not a VolumeSnapshotter") volumeSnapshotter := new(providermocks.VolumeSnapshotter) volumeSnapshotter.Test(t) diff --git a/pkg/plugin/velero/backupitemaction/v2/backup_item_action.go b/pkg/plugin/velero/backupitemaction/v2/backup_item_action.go index 116cf71858..70c1429ee7 100644 --- a/pkg/plugin/velero/backupitemaction/v2/backup_item_action.go +++ b/pkg/plugin/velero/backupitemaction/v2/backup_item_action.go @@ -76,5 +76,5 @@ func AsyncOperationsNotSupportedError() error { } func InvalidOperationIDError(operationID string) error { - return errors.New(fmt.Sprintf("Operation ID %v is invalid.", operationID)) + return fmt.Errorf("operation ID %v is invalid", operationID) } diff --git a/pkg/plugin/velero/restoreitemaction/v2/restore_item_action.go b/pkg/plugin/velero/restoreitemaction/v2/restore_item_action.go index ed29343b8d..dfc35428f8 100644 --- a/pkg/plugin/velero/restoreitemaction/v2/restore_item_action.go +++ b/pkg/plugin/velero/restoreitemaction/v2/restore_item_action.go @@ -72,5 +72,5 @@ func AsyncOperationsNotSupportedError() error { } func InvalidOperationIDError(operationID string) error { - return errors.New(fmt.Sprintf("Operation ID %v is invalid.", operationID)) + return fmt.Errorf("operation ID %v is invalid", operationID) } diff --git a/pkg/podvolume/util.go b/pkg/podvolume/util.go index e8c1d202c4..bbdc1d6d5c 100644 --- a/pkg/podvolume/util.go +++ b/pkg/podvolume/util.go @@ -151,9 +151,8 @@ func GetSnapshotIdentifier(podVolumeBackups *velerov1api.PodVolumeBackupList) [] func getUploaderTypeOrDefault(uploaderType string) string { if uploaderType != "" { return uploaderType - } else { - return uploader.ResticType } + return uploader.ResticType } // getRepositoryType returns the hardcode repositoryType for different backup methods - Restic or Kopia,uploaderType diff --git a/pkg/repository/backup_repo_op.go b/pkg/repository/backup_repo_op.go index 3ae0f28121..e1c021fa8f 100644 --- a/pkg/repository/backup_repo_op.go +++ b/pkg/repository/backup_repo_op.go @@ -37,8 +37,8 @@ type BackupRepositoryKey struct { } var ( - backupRepoNotFoundError = errors.New("backup repository not found") - backupRepoNotProvisionedError = errors.New("backup repository not provisioned") + errBackupRepoNotFound = errors.New("backup repository not found") + errBackupRepoNotProvisioned = errors.New("backup repository not provisioned") ) func repoLabelsFromKey(key BackupRepositoryKey) labels.Set { @@ -69,7 +69,7 @@ func GetBackupRepository(ctx context.Context, cli client.Client, namespace strin } if len(backupRepoList.Items) == 0 { - return nil, backupRepoNotFoundError + return nil, errBackupRepoNotFound } if len(backupRepoList.Items) > 1 { @@ -84,7 +84,7 @@ func GetBackupRepository(ctx context.Context, cli client.Client, namespace strin } if repo.Status.Phase == "" || repo.Status.Phase == velerov1api.BackupRepositoryPhaseNew { - return nil, backupRepoNotProvisionedError + return nil, errBackupRepoNotProvisioned } } @@ -107,9 +107,9 @@ func newBackupRepository(namespace string, key BackupRepositoryKey) *velerov1api } func isBackupRepositoryNotFoundError(err error) bool { - return (err == backupRepoNotFoundError) + return (err == errBackupRepoNotFound) } func isBackupRepositoryNotProvisionedError(err error) bool { - return (err == backupRepoNotProvisionedError) + return (err == errBackupRepoNotProvisioned) } diff --git a/pkg/repository/config/gcp.go b/pkg/repository/config/gcp.go index 88b5d5ff35..5be4670ec6 100644 --- a/pkg/repository/config/gcp.go +++ b/pkg/repository/config/gcp.go @@ -41,7 +41,6 @@ func GetGCPResticEnvVars(config map[string]string) (map[string]string, error) { func GetGCPCredentials(config map[string]string) string { if credentialsFile, ok := config[CredentialsFileKey]; ok { return credentialsFile - } else { - return os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") } + return os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") } diff --git a/pkg/repository/provider/unified_repo_test.go b/pkg/repository/provider/unified_repo_test.go index e33059c2b7..0a0401aecf 100644 --- a/pkg/repository/provider/unified_repo_test.go +++ b/pkg/repository/provider/unified_repo_test.go @@ -660,9 +660,8 @@ func TestPrepareRepo(t *testing.T) { retFuncInit: func(ctx context.Context, repoOption udmrepo.RepoOptions, createNew bool) error { if !createNew { return nil - } else { - return errors.New("fake-error") } + return errors.New("fake-error") }, }, { @@ -681,9 +680,8 @@ func TestPrepareRepo(t *testing.T) { retFuncInit: func(ctx context.Context, repoOption udmrepo.RepoOptions, createNew bool) error { if !createNew { return errors.New("fake-error-1") - } else { - return errors.New("fake-error-2") } + return errors.New("fake-error-2") }, expectedErr: "error to init backup repo: fake-error-2", }, diff --git a/pkg/repository/udmrepo/kopialib/backend/utils.go b/pkg/repository/udmrepo/kopialib/backend/utils.go index eb673539fd..97fa2ab570 100644 --- a/pkg/repository/udmrepo/kopialib/backend/utils.go +++ b/pkg/repository/udmrepo/kopialib/backend/utils.go @@ -28,9 +28,8 @@ import ( func mustHaveString(key string, flags map[string]string) (string, error) { if value, exist := flags[key]; exist { return value, nil - } else { - return "", errors.New("key " + key + " not found") } + return "", errors.New("key " + key + " not found") } func optionalHaveString(key string, flags map[string]string) string { @@ -68,9 +67,8 @@ func optionalHaveFloat64(ctx context.Context, key string, flags map[string]strin func optionalHaveStringWithDefault(key string, flags map[string]string, defValue string) string { if value, exist := flags[key]; exist { return value - } else { - return defValue } + return defValue } func optionalHaveDuration(ctx context.Context, key string, flags map[string]string) time.Duration { diff --git a/pkg/repository/udmrepo/kopialib/lib_repo.go b/pkg/repository/udmrepo/kopialib/lib_repo.go index 0246620bcc..bb924c2f12 100644 --- a/pkg/repository/udmrepo/kopialib/lib_repo.go +++ b/pkg/repository/udmrepo/kopialib/lib_repo.go @@ -100,9 +100,8 @@ func (ks *kopiaRepoService) Init(ctx context.Context, repoOption udmrepo.RepoOpt } return writeInitParameters(repoCtx, repoOption, ks.logger) - } else { - return ConnectBackupRepo(repoCtx, repoOption) } + return ConnectBackupRepo(repoCtx, repoOption) } func (ks *kopiaRepoService) Open(ctx context.Context, repoOption udmrepo.RepoOptions) (udmrepo.BackupRepo, error) { @@ -480,19 +479,19 @@ func getCompressorForObject(opt udmrepo.ObjectWriteOptions) compression.Name { return "" } -func getManifestEntryFromKopia(kMani *manifest.EntryMetadata) *udmrepo.ManifestEntryMetadata { +func getManifestEntryFromKopia(mani *manifest.EntryMetadata) *udmrepo.ManifestEntryMetadata { return &udmrepo.ManifestEntryMetadata{ - ID: udmrepo.ID(kMani.ID), - Labels: kMani.Labels, - Length: int32(kMani.Length), - ModTime: kMani.ModTime, + ID: udmrepo.ID(mani.ID), + Labels: mani.Labels, + Length: int32(mani.Length), + ModTime: mani.ModTime, } } -func getManifestEntriesFromKopia(kMani []*manifest.EntryMetadata) []*udmrepo.ManifestEntryMetadata { +func getManifestEntriesFromKopia(mani []*manifest.EntryMetadata) []*udmrepo.ManifestEntryMetadata { var ret []*udmrepo.ManifestEntryMetadata - for _, entry := range kMani { + for _, entry := range mani { ret = append(ret, &udmrepo.ManifestEntryMetadata{ ID: udmrepo.ID(entry.ID), Labels: entry.Labels, diff --git a/pkg/repository/udmrepo/kopialib/repo_init.go b/pkg/repository/udmrepo/kopialib/repo_init.go index c6407bde47..b1a13e2e50 100644 --- a/pkg/repository/udmrepo/kopialib/repo_init.go +++ b/pkg/repository/udmrepo/kopialib/repo_init.go @@ -35,7 +35,7 @@ type kopiaBackendStore struct { } // backendStores lists the supported backend storages at present -var backendStores []kopiaBackendStore = []kopiaBackendStore{ +var backendStores = []kopiaBackendStore{ {udmrepo.StorageTypeAzure, "an Azure blob storage", &backend.AzureBackend{}}, {udmrepo.StorageTypeFs, "a filesystem", &backend.FsBackend{}}, {udmrepo.StorageTypeGcs, "a Google Cloud Storage bucket", &backend.GCSBackend{}}, diff --git a/pkg/restore/pod_volume_restore_action.go b/pkg/restore/pod_volume_restore_action.go index 3f419c0aca..9044ab7974 100644 --- a/pkg/restore/pod_volume_restore_action.go +++ b/pkg/restore/pod_volume_restore_action.go @@ -218,11 +218,10 @@ func getImage(log logrus.FieldLogger, config *corev1.ConfigMap) string { // tag-less image name: add default image tag for this version of Velero log.Infof("Plugin config contains image name without tag. Adding tag: %q", tag) return fmt.Sprintf("%s:%s", image, tag) - } else { - // tagged image name - log.Debugf("Plugin config contains image name with tag") - return image } + // tagged image name + log.Debugf("Plugin config contains image name with tag") + return image } // getResourceRequests extracts the CPU and memory requests from a ConfigMap. diff --git a/pkg/restore/pv_restorer_test.go b/pkg/restore/pv_restorer_test.go index 2cb76a57a0..db92f6e5cd 100644 --- a/pkg/restore/pv_restorer_test.go +++ b/pkg/restore/pv_restorer_test.go @@ -53,27 +53,27 @@ func TestExecutePVAction_NoSnapshotRestores(t *testing.T) { }{ { name: "no name should error", - obj: NewTestUnstructured().WithMetadata().Unstructured, + obj: newTestUnstructured().WithMetadata().Unstructured, restore: builder.ForRestore(api.DefaultNamespace, "").Result(), expectedErr: true, }, { name: "ensure spec.storageClassName is retained", - obj: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("storageClassName", "someOtherField").Unstructured, + obj: newTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("storageClassName", "someOtherField").Unstructured, restore: builder.ForRestore(api.DefaultNamespace, "").RestorePVs(false).Result(), backup: defaultBackup().Phase(api.BackupPhaseInProgress).Result(), - expectedRes: NewTestUnstructured().WithAnnotations("a", "b").WithName("pv-1").WithSpec("storageClassName", "someOtherField").Unstructured, + expectedRes: newTestUnstructured().WithAnnotations("a", "b").WithName("pv-1").WithSpec("storageClassName", "someOtherField").Unstructured, }, { name: "if backup.spec.snapshotVolumes is false, ignore restore.spec.restorePVs and return early", - obj: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("claimRef", "storageClassName", "someOtherField").Unstructured, + obj: newTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("claimRef", "storageClassName", "someOtherField").Unstructured, restore: builder.ForRestore(api.DefaultNamespace, "").RestorePVs(true).Result(), backup: defaultBackup().Phase(api.BackupPhaseInProgress).SnapshotVolumes(false).Result(), - expectedRes: NewTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("claimRef", "storageClassName", "someOtherField").Unstructured, + expectedRes: newTestUnstructured().WithName("pv-1").WithAnnotations("a", "b").WithSpec("claimRef", "storageClassName", "someOtherField").Unstructured, }, { name: "restore.spec.restorePVs=false, return early", - obj: NewTestUnstructured().WithName("pv-1").WithSpec().Unstructured, + obj: newTestUnstructured().WithName("pv-1").WithSpec().Unstructured, restore: builder.ForRestore(api.DefaultNamespace, "").RestorePVs(false).Result(), backup: defaultBackup().Phase(api.BackupPhaseInProgress).Result(), volumeSnapshots: []*volume.Snapshot{ @@ -83,11 +83,11 @@ func TestExecutePVAction_NoSnapshotRestores(t *testing.T) { builder.ForVolumeSnapshotLocation(api.DefaultNamespace, "loc-1").Result(), }, expectedErr: false, - expectedRes: NewTestUnstructured().WithName("pv-1").WithSpec().Unstructured, + expectedRes: newTestUnstructured().WithName("pv-1").WithSpec().Unstructured, }, { name: "volumeSnapshots is empty: return early", - obj: NewTestUnstructured().WithName("pv-1").WithSpec().Unstructured, + obj: newTestUnstructured().WithName("pv-1").WithSpec().Unstructured, restore: builder.ForRestore(api.DefaultNamespace, "").RestorePVs(true).Result(), backup: defaultBackup().Result(), locations: []*api.VolumeSnapshotLocation{ @@ -95,11 +95,11 @@ func TestExecutePVAction_NoSnapshotRestores(t *testing.T) { builder.ForVolumeSnapshotLocation(api.DefaultNamespace, "loc-2").Result(), }, volumeSnapshots: []*volume.Snapshot{}, - expectedRes: NewTestUnstructured().WithName("pv-1").WithSpec().Unstructured, + expectedRes: newTestUnstructured().WithName("pv-1").WithSpec().Unstructured, }, { name: "volumeSnapshots doesn't have a snapshot for PV: return early", - obj: NewTestUnstructured().WithName("pv-1").WithSpec().Unstructured, + obj: newTestUnstructured().WithName("pv-1").WithSpec().Unstructured, restore: builder.ForRestore(api.DefaultNamespace, "").RestorePVs(true).Result(), backup: defaultBackup().Result(), locations: []*api.VolumeSnapshotLocation{ @@ -110,7 +110,7 @@ func TestExecutePVAction_NoSnapshotRestores(t *testing.T) { newSnapshot("non-matching-pv-1", "loc-1", "type-1", "az-1", "snap-1", 1), newSnapshot("non-matching-pv-2", "loc-2", "type-2", "az-2", "snap-2", 2), }, - expectedRes: NewTestUnstructured().WithName("pv-1").WithSpec().Unstructured, + expectedRes: newTestUnstructured().WithName("pv-1").WithSpec().Unstructured, }, } @@ -165,7 +165,7 @@ func TestExecutePVAction_SnapshotRestores(t *testing.T) { }{ { name: "backup with a matching volume.Snapshot for PV executes restore", - obj: NewTestUnstructured().WithName("pv-1").WithSpec().Unstructured, + obj: newTestUnstructured().WithName("pv-1").WithSpec().Unstructured, restore: builder.ForRestore(api.DefaultNamespace, "").RestorePVs(true).Result(), backup: defaultBackup().Result(), locations: []*api.VolumeSnapshotLocation{ @@ -221,11 +221,11 @@ func TestExecutePVAction_SnapshotRestores(t *testing.T) { type providerToVolumeSnapshotterMap map[string]vsv1.VolumeSnapshotter func (g providerToVolumeSnapshotterMap) GetVolumeSnapshotter(provider string) (vsv1.VolumeSnapshotter, error) { - if bs, ok := g[provider]; !ok { + bs, ok := g[provider] + if !ok { return nil, errors.New("volume snapshotter not found for provider") - } else { - return bs, nil } + return bs, nil } func newSnapshot(pvName, location, volumeType, volumeAZ, snapshotID string, volumeIOPS int64) *volume.Snapshot { @@ -252,7 +252,7 @@ type testUnstructured struct { *unstructured.Unstructured } -func NewTestUnstructured() *testUnstructured { +func newTestUnstructured() *testUnstructured { obj := &testUnstructured{ Unstructured: &unstructured.Unstructured{ Object: make(map[string]interface{}), diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 59e73ee5d1..8783da19aa 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -977,19 +977,19 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso // namespace into which the resource is being restored into exists. // This is the *remapped* namespace that we are ensuring exists. nsToEnsure := getNamespace(ctx.log, archive.GetItemFilePath(ctx.restoreDir, "namespaces", "", obj.GetNamespace()), namespace) - if _, nsCreated, err := kube.EnsureNamespaceExistsAndIsReady(nsToEnsure, ctx.namespaceClient, ctx.resourceTerminatingTimeout); err != nil { + _, nsCreated, err := kube.EnsureNamespaceExistsAndIsReady(nsToEnsure, ctx.namespaceClient, ctx.resourceTerminatingTimeout) + if err != nil { errs.AddVeleroError(err) return warnings, errs, itemExists - } else { - // Add the newly created namespace to the list of restored items. - if nsCreated { - itemKey := itemKey{ - resource: resourceKey(nsToEnsure), - namespace: nsToEnsure.Namespace, - name: nsToEnsure.Name, - } - ctx.restoredItems[itemKey] = restoredItemStatus{action: itemRestoreResultCreated, itemExists: true} + } + // Add the newly created namespace to the list of restored items. + if nsCreated { + itemKey := itemKey{ + resource: resourceKey(nsToEnsure), + namespace: nsToEnsure.Namespace, + name: nsToEnsure.Name, } + ctx.restoredItems[itemKey] = restoredItemStatus{action: itemRestoreResultCreated, itemExists: true} } } else { if boolptr.IsSetToFalse(ctx.restore.Spec.IncludeClusterResources) { @@ -1429,7 +1429,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso // existingResourcePolicy is set as none, add warning if resourcePolicy == velerov1api.PolicyTypeNone { - e := errors.Errorf("could not restore, %s %q already exists. Warning: the in-cluster version is different than the backed-up version.", + e := errors.Errorf("could not restore, %s %q already exists. Warning: the in-cluster version is different than the backed-up version", obj.GetKind(), obj.GetName()) warnings.Add(namespace, e) // existingResourcePolicy is set as update, attempt patch on the resource and add warning if it fails @@ -1445,7 +1445,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso } } else { // Preserved Velero behavior when existingResourcePolicy is not specified by the user - e := errors.Errorf("could not restore, %s %q already exists. Warning: the in-cluster version is different than the backed-up version.", + e := errors.Errorf("could not restore, %s %q already exists. Warning: the in-cluster version is different than the backed-up version", obj.GetKind(), obj.GetName()) warnings.Add(namespace, e) } diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index f41ce759f0..20bdcc13f2 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -3088,21 +3088,21 @@ func TestResetMetadata(t *testing.T) { }, { name: "keep name, namespace, labels, annotations, managedFields, finalizers", - obj: NewTestUnstructured().WithMetadata("name", "namespace", "labels", "annotations", "managedFields", "finalizers").Unstructured, + obj: newTestUnstructured().WithMetadata("name", "namespace", "labels", "annotations", "managedFields", "finalizers").Unstructured, expectedErr: false, - expectedRes: NewTestUnstructured().WithMetadata("name", "namespace", "labels", "annotations", "managedFields", "finalizers").Unstructured, + expectedRes: newTestUnstructured().WithMetadata("name", "namespace", "labels", "annotations", "managedFields", "finalizers").Unstructured, }, { name: "remove uid, ownerReferences", - obj: NewTestUnstructured().WithMetadata("name", "namespace", "uid", "ownerReferences").Unstructured, + obj: newTestUnstructured().WithMetadata("name", "namespace", "uid", "ownerReferences").Unstructured, expectedErr: false, - expectedRes: NewTestUnstructured().WithMetadata("name", "namespace").Unstructured, + expectedRes: newTestUnstructured().WithMetadata("name", "namespace").Unstructured, }, { name: "keep status", - obj: NewTestUnstructured().WithMetadata().WithStatus().Unstructured, + obj: newTestUnstructured().WithMetadata().WithStatus().Unstructured, expectedErr: false, - expectedRes: NewTestUnstructured().WithMetadata().WithStatus().Unstructured, + expectedRes: newTestUnstructured().WithMetadata().WithStatus().Unstructured, }, } @@ -3130,8 +3130,8 @@ func TestResetStatus(t *testing.T) { }, { name: "remove status", - obj: NewTestUnstructured().WithMetadata().WithStatus().Unstructured, - expectedRes: NewTestUnstructured().WithMetadata().Unstructured, + obj: newTestUnstructured().WithMetadata().WithStatus().Unstructured, + expectedRes: newTestUnstructured().WithMetadata().Unstructured, }, } @@ -3447,7 +3447,7 @@ func Test_resetVolumeBindingInfo(t *testing.T) { }{ { name: "PVs that are bound have their binding and dynamic provisioning annotations removed", - obj: NewTestUnstructured().WithMetadataField("kind", "persistentVolume"). + obj: newTestUnstructured().WithMetadataField("kind", "persistentVolume"). WithName("pv-1").WithAnnotations( kubeutil.KubeAnnBindCompleted, kubeutil.KubeAnnBoundByController, @@ -3457,7 +3457,7 @@ func Test_resetVolumeBindingInfo(t *testing.T) { "name": "pvc-1", "uid": "abc", "resourceVersion": "1"}).Unstructured, - expected: NewTestUnstructured().WithMetadataField("kind", "persistentVolume"). + expected: newTestUnstructured().WithMetadataField("kind", "persistentVolume"). WithName("pv-1"). WithAnnotations(kubeutil.KubeAnnDynamicallyProvisioned). WithSpecField("claimRef", map[string]interface{}{ @@ -3465,12 +3465,12 @@ func Test_resetVolumeBindingInfo(t *testing.T) { }, { name: "PVCs that are bound have their binding annotations removed, but the volume name stays", - obj: NewTestUnstructured().WithMetadataField("kind", "persistentVolumeClaim"). + obj: newTestUnstructured().WithMetadataField("kind", "persistentVolumeClaim"). WithName("pvc-1").WithAnnotations( kubeutil.KubeAnnBindCompleted, kubeutil.KubeAnnBoundByController, ).WithSpecField("volumeName", "pv-1").Unstructured, - expected: NewTestUnstructured().WithMetadataField("kind", "persistentVolumeClaim"). + expected: newTestUnstructured().WithMetadataField("kind", "persistentVolumeClaim"). WithName("pvc-1").WithAnnotations(). WithSpecField("volumeName", "pv-1").Unstructured, }, diff --git a/pkg/test/fake_volume_snapshotter.go b/pkg/test/fake_volume_snapshotter.go index 1a91669434..c9e3fc067f 100644 --- a/pkg/test/fake_volume_snapshotter.go +++ b/pkg/test/fake_volume_snapshotter.go @@ -101,11 +101,11 @@ func (bs *FakeVolumeSnapshotter) GetVolumeInfo(volumeID, volumeAZ string) (strin return "", nil, bs.Error } - if volumeInfo, exists := bs.SnapshottableVolumes[volumeID]; !exists { + volumeInfo, exists := bs.SnapshottableVolumes[volumeID] + if !exists { return "", nil, errors.New("VolumeID not found") - } else { - return volumeInfo.Type, volumeInfo.Iops, nil } + return volumeInfo.Type, volumeInfo.Iops, nil } func (bs *FakeVolumeSnapshotter) GetVolumeID(pv runtime.Unstructured) (string, error) { diff --git a/pkg/uploader/kopia/shim.go b/pkg/uploader/kopia/shim.go index 68463c376d..1ae3c6de13 100644 --- a/pkg/uploader/kopia/shim.go +++ b/pkg/uploader/kopia/shim.go @@ -87,11 +87,11 @@ func (sr *shimRepository) GetManifest(ctx context.Context, id manifest.ID, paylo // Get one or more manifest data that match the given labels func (sr *shimRepository) FindManifests(ctx context.Context, labels map[string]string) ([]*manifest.EntryMetadata, error) { - if metadata, err := sr.udmRepo.FindManifests(ctx, udmrepo.ManifestFilter{Labels: labels}); err != nil { + metadata, err := sr.udmRepo.FindManifests(ctx, udmrepo.ManifestFilter{Labels: labels}) + if err != nil { return nil, errors.Wrapf(err, "failed to get manifests with labels %v", labels) - } else { - return GetKopiaManifestEntries(metadata), nil } + return GetKopiaManifestEntries(metadata), nil } // GetKopiaManifestEntries get metadata from specific ManifestEntryMetadata diff --git a/pkg/uploader/kopia/snapshot_test.go b/pkg/uploader/kopia/snapshot_test.go index a5b6d81fbe..1af69f139d 100644 --- a/pkg/uploader/kopia/snapshot_test.go +++ b/pkg/uploader/kopia/snapshot_test.go @@ -42,7 +42,7 @@ type mockArgs struct { returns []interface{} } -func InjectSnapshotFuncs() *snapshotMockes { +func injectSnapshotFuncs() *snapshotMockes { s := &snapshotMockes{ policyMock: &uploadermocks.Policy{}, snapshotMock: &uploadermocks.Snapshot{}, @@ -184,7 +184,7 @@ func TestSnapshotSource(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - s := InjectSnapshotFuncs() + s := injectSnapshotFuncs() MockFuncs(s, tc.args) _, _, err = SnapshotSource(ctx, s.repoWriterMock, s.uploderMock, sourceInfo, rootDir, "/", log, "TestSnapshotSource") if tc.notError { diff --git a/pkg/uploader/provider/provider.go b/pkg/uploader/provider/provider.go index 3d0c452dc9..df017ac1b6 100644 --- a/pkg/uploader/provider/provider.go +++ b/pkg/uploader/provider/provider.go @@ -81,10 +81,9 @@ func NewUploaderProvider( return nil, errors.Wrap(err, "failed to connect repository") } return NewKopiaUploaderProvider(ctx, credGetter, backupRepo, log) - } else { - if err := provider.NewResticRepositoryProvider(credGetter.FromFile, filesystem.NewFileSystem(), log).ConnectToRepo(ctx, provider.RepoParam{BackupLocation: bsl, BackupRepo: backupRepo}); err != nil { - return nil, errors.Wrap(err, "failed to connect repository") - } - return NewResticUploaderProvider(repoIdentifier, bsl, credGetter, repoKeySelector, log) } + if err := provider.NewResticRepositoryProvider(credGetter.FromFile, filesystem.NewFileSystem(), log).ConnectToRepo(ctx, provider.RepoParam{BackupLocation: bsl, BackupRepo: backupRepo}); err != nil { + return nil, errors.Wrap(err, "failed to connect repository") + } + return NewResticUploaderProvider(repoIdentifier, bsl, credGetter, repoKeySelector, log) }