Enable linter revive and resolve found errors: part 2. (#6177)

Signed-off-by: Xun Jiang <blackpiglet@gmail.com>
Co-authored-by: Xun Jiang <blackpiglet@gmail.com>
This commit is contained in:
Xun Jiang/Bruce Jiang
2023-04-26 14:05:22 +08:00
committed by GitHub
co-authored by Xun Jiang
parent a0b0b7cd9b
commit e106bbf06b
34 changed files with 100 additions and 108 deletions
+1
View File
@@ -0,0 +1 @@
Enable linter revive and resolve found errors: part 2
@@ -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
@@ -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",
@@ -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
@@ -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",
+2 -2
View File
@@ -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{}
}
+1 -1
View File
@@ -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
@@ -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
@@ -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",
@@ -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
@@ -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)
@@ -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
@@ -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",
@@ -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
@@ -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",
@@ -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
@@ -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)
@@ -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)
}
@@ -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)
}
+1 -2
View File
@@ -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
+6 -6
View File
@@ -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)
}
+1 -2
View File
@@ -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")
}
+2 -4
View File
@@ -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",
},
@@ -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 {
+8 -9
View File
@@ -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,
+1 -1
View File
@@ -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{}},
+3 -4
View File
@@ -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.
+16 -16
View File
@@ -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{}),
+12 -12
View File
@@ -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)
}
+12 -12
View File
@@ -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,
},
+3 -3
View File
@@ -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) {
+3 -3
View File
@@ -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
+2 -2
View File
@@ -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 {
+4 -5
View File
@@ -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)
}