From 92b9e59fd5acd40e7c49801934dfc841bb9f6c55 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Wed, 31 Jul 2024 22:15:15 -0400 Subject: [PATCH 1/3] Unused parameters Signed-off-by: Tiger Kaovilai --- pkg/controller/backup_repository_controller_test.go | 12 ++++++------ pkg/controller/backup_sync_controller_test.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/controller/backup_repository_controller_test.go b/pkg/controller/backup_repository_controller_test.go index 519f3cb02..92ef5e335 100644 --- a/pkg/controller/backup_repository_controller_test.go +++ b/pkg/controller/backup_repository_controller_test.go @@ -33,7 +33,7 @@ import ( const testMaintenanceFrequency = 10 * time.Minute -func mockBackupRepoReconciler(t *testing.T, rr *velerov1api.BackupRepository, mockOn string, arg interface{}, ret interface{}) *BackupRepoReconciler { +func mockBackupRepoReconciler(t *testing.T, mockOn string, arg interface{}, ret interface{}) *BackupRepoReconciler { mgr := &repomokes.Manager{} if mockOn != "" { mgr.On(mockOn, arg).Return(ret) @@ -61,7 +61,7 @@ func mockBackupRepositoryCR() *velerov1api.BackupRepository { func TestPatchBackupRepository(t *testing.T) { rr := mockBackupRepositoryCR() - reconciler := mockBackupRepoReconciler(t, rr, "", nil, nil) + reconciler := mockBackupRepoReconciler(t, "", nil, nil) err := reconciler.Client.Create(context.TODO(), rr) assert.NoError(t, err) err = reconciler.patchBackupRepository(context.Background(), rr, repoReady()) @@ -77,7 +77,7 @@ func TestCheckNotReadyRepo(t *testing.T) { rr.Spec.BackupStorageLocation = "default" rr.Spec.ResticIdentifier = "fake-identifier" rr.Spec.VolumeNamespace = "volume-ns-1" - reconciler := mockBackupRepoReconciler(t, rr, "PrepareRepo", rr, nil) + reconciler := mockBackupRepoReconciler(t, "PrepareRepo", rr, nil) err := reconciler.Client.Create(context.TODO(), rr) assert.NoError(t, err) locations := &velerov1api.BackupStorageLocation{ @@ -100,7 +100,7 @@ func TestCheckNotReadyRepo(t *testing.T) { func TestRunMaintenanceIfDue(t *testing.T) { rr := mockBackupRepositoryCR() - reconciler := mockBackupRepoReconciler(t, rr, "PruneRepo", rr, nil) + reconciler := mockBackupRepoReconciler(t, "PruneRepo", rr, nil) err := reconciler.Client.Create(context.TODO(), rr) assert.NoError(t, err) lastTm := rr.Status.LastMaintenanceTime @@ -118,7 +118,7 @@ func TestRunMaintenanceIfDue(t *testing.T) { func TestInitializeRepo(t *testing.T) { rr := mockBackupRepositoryCR() rr.Spec.BackupStorageLocation = "default" - reconciler := mockBackupRepoReconciler(t, rr, "PrepareRepo", rr, nil) + reconciler := mockBackupRepoReconciler(t, "PrepareRepo", rr, nil) err := reconciler.Client.Create(context.TODO(), rr) assert.NoError(t, err) locations := &velerov1api.BackupStorageLocation{ @@ -189,7 +189,7 @@ func TestBackupRepoReconcile(t *testing.T) { } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - reconciler := mockBackupRepoReconciler(t, test.repo, "", test.repo, nil) + reconciler := mockBackupRepoReconciler(t, "", test.repo, nil) err := reconciler.Client.Create(context.TODO(), test.repo) assert.NoError(t, err) _, err = reconciler.Reconcile(context.TODO(), ctrl.Request{NamespacedName: types.NamespacedName{Namespace: test.repo.Namespace, Name: test.repo.Name}}) diff --git a/pkg/controller/backup_sync_controller_test.go b/pkg/controller/backup_sync_controller_test.go index 536d0078b..1bba44134 100644 --- a/pkg/controller/backup_sync_controller_test.go +++ b/pkg/controller/backup_sync_controller_test.go @@ -144,7 +144,7 @@ func defaultLocationWithLongerLocationName(namespace string) *velerov1api.Backup } } -func numBackups(c ctrlClient.WithWatch, ns string) (int, error) { +func numBackups(c ctrlClient.WithWatch) (int, error) { var existingK8SBackups velerov1api.BackupList err := c.List(context.TODO(), &existingK8SBackups, &ctrlClient.ListOptions{}) if err != nil { @@ -692,7 +692,7 @@ var _ = Describe("Backup Sync Reconciler", func() { } r.deleteOrphanedBackups(ctx, bslName, test.cloudBackups, velerotest.NewLogger()) - numBackups, err := numBackups(client, r.namespace) + numBackups, err := numBackups(client) Expect(err).ShouldNot(HaveOccurred()) fmt.Println("") From ad6104b90a354fbd0ce2a7a95852621aba78165b Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Wed, 31 Jul 2024 22:16:11 -0400 Subject: [PATCH 2/3] unused write to field Spec Signed-off-by: Tiger Kaovilai --- pkg/controller/restore_controller_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/controller/restore_controller_test.go b/pkg/controller/restore_controller_test.go index fe86d4c09..09fd12d10 100644 --- a/pkg/controller/restore_controller_test.go +++ b/pkg/controller/restore_controller_test.go @@ -613,12 +613,6 @@ func TestRestoreReconcile(t *testing.T) { }, } - if test.restore.Spec.ScheduleName != "" && test.backup != nil { - expected.Spec = SpecPatch{ - BackupName: test.backup.Name, - } - } - if test.expectedStartTime != nil { expected.Status.StartTimestamp = test.expectedStartTime } From 6d0d1aaccc0dbf4fdf3cc7a3b86d08b787cf3ba2 Mon Sep 17 00:00:00 2001 From: Tiger Kaovilai Date: Wed, 31 Jul 2024 22:18:42 -0400 Subject: [PATCH 3/3] tautological condition: non-nil != nil https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/nilness#cond:~:text=p%20%3A%3D%20%26v%0A...%0Aif%20p%20!%3D%20nil%20%7B%20//%20tautological%20condition%0A%7D Signed-off-by: Tiger Kaovilai --- pkg/controller/restore_finalizer_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/controller/restore_finalizer_controller.go b/pkg/controller/restore_finalizer_controller.go index a75ea199a..433f197a9 100644 --- a/pkg/controller/restore_finalizer_controller.go +++ b/pkg/controller/restore_finalizer_controller.go @@ -311,7 +311,7 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result // We are handling a common but specific scenario where a PVC is in a pending state and uses a storage class with // VolumeBindingMode set to WaitForFirstConsumer. In this case, the PV patch step is skipped to avoid // failures due to the PVC not being bound, which could cause a timeout and result in a failed restore. - if pvc != nil && pvc.Status.Phase == v1.ClaimPending { + if pvc.Status.Phase == v1.ClaimPending { // check if storage class used has VolumeBindingMode as WaitForFirstConsumer scName := *pvc.Spec.StorageClassName sc := &storagev1api.StorageClass{}