Skip to content

release-1.15: Fix lint issues for golangci-lint v1.64.6#9648

Open
kaovilai wants to merge 1 commit intovelero-io:release-1.15from
kaovilai:with-lint-fix
Open

release-1.15: Fix lint issues for golangci-lint v1.64.6#9648
kaovilai wants to merge 1 commit intovelero-io:release-1.15from
kaovilai:with-lint-fix

Conversation

@kaovilai
Copy link
Copy Markdown
Collaborator

  • Bump golangci-lint to v1.64.6 and update .golangci.yaml config
  • Replace interface{} with any (Go 1.18+)
  • Drop zero-value initializers (= 0, = nil) from var declarations
  • Omit inferable types from var declarations
  • Replace n += 1 with n++
  • Replace single-case switch with if-then
  • Fix useless assert.True calls in data_download_controller_test
  • Fix assert.Equalf arg count in volumesnapshot_action_test
  • Remove redundant nil checks before len()
  • Fix go:generate directive spacing
  • Add //nolint:gosec for test code
  • Fix G115 integer overflow conversions
  • Remove unused functions
  • Fix unchecked error returns

Generated with Claude Code via Happy

Thank you for contributing to Velero!

Please add a summary of your change

Does your change fix a particular issue?

Fixes #(issue)

Please indicate you've done the following:

Replaces #8760

Copilot AI review requested due to automatic review settings March 25, 2026 22:20
@kaovilai kaovilai added the kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes label Mar 25, 2026
@kaovilai
Copy link
Copy Markdown
Collaborator Author

was just cleaning up my opened draft PRs from way back.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the repo to be clean under newer golangci-lint (v1.64.6) by applying broad, mostly-mechanical lint fixes across production and test code (e.g., interface{}any, removing redundant initializers, and tightening assertions).

Changes:

  • Update .golangci.yaml to align with golangci-lint v1.64.6 and enable/adjust several linters/rules.
  • Apply repo-wide Go lint refactors (any, inferred types, increment style, redundant checks) and targeted correctness fixes in tests.
  • Add overflow-safe int conversions (min(..., math.MaxInt32)), small perf cleanups (e.g., hex.EncodeToString), and assorted readability tweaks.

Reviewed changes

Copilot reviewed 173 out of 173 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/util/velero/velero_utils.go Ignore map.Set return values explicitly and adjust comments/param naming.
test/util/velero/install.go Mark unused parameter and ignore uninstall error explicitly.
test/util/report/report.go Use map[string]any for report data.
test/util/providers/azure_utils.go Remove redundant nil check before len().
test/types.go Use any in report inline map.
test/pkg/client/factory_test.go Replace map[string]interface{} with map[string]any in tests.
test/pkg/client/config.go Use any in VeleroConfig alias + doc update.
test/perf/metrics/monitor.go Replace interface{} maps with any.
test/perf/e2e_suite_test.go Replace interface{} map allocation with any.
test/e2e/basic/backup-volume-info/skipped_volumes.go Replace brittle length assertion with BeEmpty() matcher.
test/e2e/basic/backup-volume-info/native_snapshot.go Replace brittle length assertion with BeEmpty() matcher.
test/e2e/basic/backup-volume-info/filesystem_upload.go Replace brittle length assertion with BeEmpty() matcher.
test/e2e/basic/backup-volume-info/csi_snapshot.go Replace brittle length assertion with BeEmpty() matcher.
test/e2e/basic/backup-volume-info/csi_data_mover.go Replace brittle length assertion with BeEmpty() matcher.
test/e2e/basic/api-group/enable_api_group_versions.go Use any for JSON-unmarshaled structures.
pkg/util/third_party.go Remove redundant explicit type in slice var declaration.
pkg/util/logging/error_location_hook_test.go Replace interface{} maps with any in tests.
pkg/util/kube/pvc_pv.go Drop explicit = nil slice initializers.
pkg/util/kube/mocks.go Fix //go:generate directive formatting.
pkg/util/kube/event.go Remove redundant explicit type in duration var declaration.
pkg/util/encode/encode.go Change ToJSONGzip arg type to any.
pkg/util/csi/volume_snapshot_test.go Fix test case name duplication wording.
pkg/util/csi/volume_snapshot.go Replace n += 1 with n++.
pkg/uploader/provider/kopia.go Change password getter param type to any.
pkg/uploader/mocks/uploader.go Use []any in mock varargs handling.
pkg/uploader/kopia/snapshot_test.go Use []any in mock return tables.
pkg/uploader/kopia/shim.go Change manifest payload param types to any.
pkg/uploader/kopia/progress.go Clamp intint32 conversion and import math.
pkg/test/tar_writer.go Change Add payload type to any.
pkg/test/mock_pod_command_executor.go Change item map type to map[string]any.
pkg/test/helpers.go Change JSON map helper return type to map[string]any.
pkg/test/fake_discovery_helper.go Remove redundant nil checks before len().
pkg/test/comparisons.go Use any in test helpers (ValidatePatch, AssertDeepEqual).
pkg/restore/restore_test.go Replace interface{} maps with any and fix comment typo.
pkg/restore/restore.go Replace log fields map type with map[string]any; update map casting error msg.
pkg/restore/pv_restorer_test.go Use any for unstructured test helpers.
pkg/restore/pv_restorer.go Drop redundant = 0 initializer.
pkg/restore/merge_service_account.go Update metadata map cast to map[string]any.
pkg/restore/actions/service_action_test.go Update helper to use map[string]any.
pkg/restore/actions/service_action.go Switch unmarshal targets/casts to map[string]any.
pkg/restore/actions/pod_volume_restore_action_test.go Use map[string]any in unstructured conversions.
pkg/restore/actions/dataupload_retrieve_action_test.go Use map[string]any in unstructured conversions.
pkg/restore/actions/csi/volumesnapshotcontent_action.go Return type any for plugin initializer.
pkg/restore/actions/csi/volumesnapshotclass_action.go Return type any for plugin initializer.
pkg/restore/actions/csi/volumesnapshot_action_test.go Fix assert.Equalf message arg count.
pkg/restore/actions/csi/volumesnapshot_action.go Fix multiline log string; return initializer type any.
pkg/restore/actions/csi/pvc_action.go Return initializer type any.
pkg/restore/actions/crd_v1_preserve_unknown_fields_action.go Change unstructured input map type to map[string]any.
pkg/restore/actions/change_storageclass_action_test.go Use any for test table params/want.
pkg/restore/actions/change_storageclass_action.go Use map[string]any in logger fields.
pkg/restore/actions/change_pvc_node_selector.go Use map[string]any in logger fields.
pkg/restore/actions/change_image_name_action_test.go Use any for test table params/want.
pkg/restore/actions/change_image_name_action.go Switch container maps to map[string]any and update logger fields.
pkg/restore/actions/admissionwebhook_config_action_test.go Use map[string]any when unmarshaling JSON.
pkg/restore/actions/admissionwebhook_config_action.go Use []any for webhook slice.
pkg/repository/udmrepo/repo_options.go Update interfaces and option funcs to use any parameters.
pkg/repository/udmrepo/repo.go Change RepoManifest.Payload to any.
pkg/repository/udmrepo/kopialib/lib_repo.go Clamp length int conversion; add unused param underscore; import math.
pkg/repository/provider/unified_repo_test.go Use any in test tables/mocked return values.
pkg/repository/provider/unified_repo.go Change provider getters to accept any.
pkg/podvolume/restorer.go Use any in informer handler signatures.
pkg/podvolume/backupper.go Use any in informer handler signatures.
pkg/podexec/pod_command_executor_test.go Use map[string]any for item input in tests.
pkg/podexec/pod_command_executor.go Use map[string]any in interface + implementation.
pkg/plugin/framework/volume_snapshotter_client.go Change client init function return type to any.
pkg/plugin/framework/volume_snapshotter.go Change GRPCClient return type to any.
pkg/plugin/framework/restoreitemaction/v2/restore_item_action_client.go Change client init function return type to any.
pkg/plugin/framework/restoreitemaction/v2/restore_item_action.go Change GRPCClient return type to any.
pkg/plugin/framework/restore_item_action_client.go Change client init function return type to any.
pkg/plugin/framework/restore_item_action.go Change GRPCClient return type to any.
pkg/plugin/framework/plugin_types_test.go Use []any for plugin impl list in tests.
pkg/plugin/framework/plugin_lister.go Change GRPCClient return type to any.
pkg/plugin/framework/object_store_client.go Change client init function return type to any.
pkg/plugin/framework/object_store.go Change GRPCClient return type to any.
pkg/plugin/framework/itemblockaction/v1/item_block_action_test.go Use map[string]any for handlers map in tests.
pkg/plugin/framework/itemblockaction/v1/item_block_action_client.go Change client init function return type to any.
pkg/plugin/framework/itemblockaction/v1/item_block_action.go Change GRPCClient return type to any.
pkg/plugin/framework/examples_test.go Change example plugin constructors to return any.
pkg/plugin/framework/delete_item_action_client.go Change client init function return type to any.
pkg/plugin/framework/delete_item_action.go Change GRPCClient return type to any.
pkg/plugin/framework/common/server_mux.go Use any for handler initializer/handler maps and GetHandler return.
pkg/plugin/framework/common/server_errors.go Clamp line number int conversion; import math.
pkg/plugin/framework/common/handle_panic.go Change panic param type to any.
pkg/plugin/framework/common/client_errors.go Replace single-case type switch with if type assertion.
pkg/plugin/framework/common/client_dispenser_test.go Change init func type to return any.
pkg/plugin/framework/common/client_dispenser.go Change ClientFor/init func/client map to use any.
pkg/plugin/framework/backupitemaction/v2/backup_item_action_test.go Use map[string]any for handlers map in tests.
pkg/plugin/framework/backupitemaction/v2/backup_item_action_client.go Change client init function return type to any.
pkg/plugin/framework/backupitemaction/v2/backup_item_action.go Change GRPCClient return type to any.
pkg/plugin/framework/backup_item_action_test.go Use map[string]any for handlers map in tests.
pkg/plugin/framework/backup_item_action_client.go Change client init function return type to any.
pkg/plugin/framework/backup_item_action.go Change GRPCClient return type to any.
pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go Use any in tests for plugin values and inputs/outputs.
pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go Change reinitializer arg type to any.
pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go Use any in tests for plugin values and inputs/outputs.
pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go Use any in tests for plugin values and inputs/outputs.
pkg/plugin/clientmgmt/restartable_object_store_test.go Use any in tests for plugin values and inputs/outputs.
pkg/plugin/clientmgmt/restartable_object_store.go Change reinitializer arg type to any.
pkg/plugin/clientmgmt/restartable_delete_item_action_test.go Use any in tests for plugin values and inputs/outputs.
pkg/plugin/clientmgmt/process/restartable_process.go Switch plugin storage/getters/reinitializer types to any.
pkg/plugin/clientmgmt/process/process_test.go Switch mock dispense/client methods to any.
pkg/plugin/clientmgmt/process/process.go Change dispense return type to any.
pkg/plugin/clientmgmt/process/logrus_adapter_test.go Use []any and map[string]any in tests.
pkg/plugin/clientmgmt/process/logrus_adapter.go Switch varargs plumbing to ...any and map values to any.
pkg/plugin/clientmgmt/manager_test.go Use any in helper function signatures and expected action slices.
pkg/plugin/clientmgmt/itemblockaction/v1/restartable_item_block_action_test.go Use any in tests for plugin values and inputs/outputs.
pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go Use any in tests for plugin values and inputs/outputs.
pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go Use any in tests for plugin values and inputs/outputs.
pkg/persistence/object_store.go Use map[string]any in logging fields; decode target type any.
pkg/label/label.go Use hex.EncodeToString instead of fmt.Sprintf for sha output.
pkg/itemblock/actions/pvc_action.go Change initializer return type to any.
pkg/install/install.go Switch internal log helper varargs to ...any.
pkg/exposer/snapshot.go Update exposer interface param types to any.
pkg/exposer/generic_restore.go Drop redundant = 0 initializer.
pkg/exposer/csi_snapshot.go Update exposer impl method param types to any; drop redundant = 0.
pkg/datapath/types.go Update async datapath interface param types to any.
pkg/datapath/micro_service_watcher.go Update method/event handler param types to any; simplify timeout var decl.
pkg/datapath/file_system.go Update method param types to any.
pkg/datamover/restore_micro_service.go Update handler signatures to any.
pkg/datamover/backup_micro_service.go Update handler signatures to any.
pkg/controller/restore_controller.go Drop redundant = nil initializer.
pkg/controller/pod_volume_backup_controller_test.go Update fake datapath impl param types to any.
pkg/controller/pod_volume_backup_controller.go Use map[string]any in logger fields.
pkg/controller/data_upload_controller_test.go Simplify error slice init; update fake interfaces to any.
pkg/controller/data_upload_controller.go Change expose-param helper return types to any.
pkg/controller/data_download_controller_test.go Simplify error slice init; fix assert.True misuse; comment unused helper.
pkg/controller/backup_sync_controller_test.go Use sets.New(...) type inference; adjust loop variable capture.
pkg/controller/backup_sync_controller.go Use sets.New(...) type inference.
pkg/controller/backup_repository_controller_test.go Change mock helper arg/return types to any.
pkg/controller/backup_repository_controller.go Use map[string]any for JSON-unmarshaled config.
pkg/controller/backup_deletion_controller.go Remove redundant nil check before len().
pkg/cmd/util/output/restore_describer.go Adjust error handling around restore volume info download.
pkg/cmd/util/output/describe_test.go Use map[string]any in structured output tests.
pkg/cmd/util/output/describe.go Switch describer varargs to ...any; use map[string]any for structured output.
pkg/cmd/util/output/backup_structured_describer_test.go Replace interface{} maps/slices with any in expected structures.
pkg/cmd/util/output/backup_structured_describer.go Replace interface{} maps/slices with any in structured describers.
pkg/cmd/test/const.go Drop redundant explicit types in const-like vars.
pkg/cmd/server/plugin/plugin.go Change plugin constructors to return any.
pkg/cmd/errors.go Switch Exit varargs to ...any.
pkg/cmd/const.go Drop redundant explicit type in TRUE var.
pkg/cmd/cli/restore/create.go Clean up doc whitespace; drop redundant = nil; update informer handler arg types to any.
pkg/cmd/cli/datamover/data_mover_test.go Use []any in test cases.
pkg/cmd/cli/backup/create_test.go Use strconv.Itoa and import strconv.
pkg/cmd/cli/backup/create.go Update informer handler arg types to any.
pkg/client/factory_test.go Replace map[string]interface{} with map[string]any in tests.
pkg/client/config.go Use any in VeleroConfig alias + doc update.
pkg/backup/item_backupper.go Use map[string]any in logger fields.
pkg/backup/backup_test.go Replace interface{} with any in resource policy/test helpers.
pkg/backup/backup.go Drop redundant = nil; use map[string]any in logger fields.
pkg/backup/actions/remap_crd_version_action_test.go Update spec map cast to map[string]any.
pkg/backup/actions/csi/volumesnapshotcontent_action.go Change constructor return type to any.
pkg/backup/actions/csi/volumesnapshotclass_action.go Change constructor return type to any.
pkg/backup/actions/csi/volumesnapshot_action.go Change initializer return type to any.
pkg/backup/actions/csi/pvc_action.go Use strconv.Itoa; change initializer return type to any.
pkg/backup/actions/backup_pv_action_test.go Replace unstructured maps with map[string]any.
internal/volumehelper/volume_policy_helper_test.go Replace resource policy condition maps with map[string]any; drop redundant nil init.
internal/volumehelper/volume_policy_helper.go Replace interface{} with any for resource value.
internal/volume/volumes_information.go Drop redundant = 0 initializer.
internal/restartabletest/restartable_delegate.go Replace interface{} with any in delegate harness.
internal/resourcepolicies/volume_resources_validator_test.go Replace policy condition maps with map[string]any and any(...) casts.
internal/resourcepolicies/volume_resources_validator.go Change decode target type to any.
internal/resourcepolicies/volume_resources_test.go Replace input maps with map[string]any; remove redundant loop var copy.
internal/resourcepolicies/volume_resources.go Update types/docs for map[string]any conditions.
internal/resourcepolicies/resource_policies_test.go Replace policy condition maps with map[string]any and any(...) casts.
internal/resourcepolicies/resource_policies.go Replace interface{} with any in policy structures and APIs.
internal/resourcemodifiers/strategic_merge_patch.go Replace patch maps with map[string]any; simplify strict error handling.
internal/resourcemodifiers/resource_modifiers_test.go Replace unstructured objects with map[string]any throughout tests.
internal/hook/wait_exec_hook_handler.go Update informer handler arg types to any.
internal/delete/delete_item_action_handler_test.go Fix comment typo.
internal/delete/actions/csi/volumesnapshotcontent_action.go Change initializer return type to any.
internal/delete/actions/csi/volumesnapshot_action.go Change initializer return type to any.
.golangci.yaml Update linter configuration for golangci-lint v1.64.6 and adjust enabled linters/rules/exclusions.
Comments suppressed due to low confidence (1)

pkg/cmd/util/output/restore_describer.go:195

  • The else if !errors.Is(err, downloadrequest.ErrNotFound) branch will also execute when err is nil (since errors.Is(nil, ...) is false), causing an incorrect "<error getting restore volume info: >" message to be printed. Keep the err != nil guard (e.g., else if err != nil && !errors.Is(...)).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 165 to 172
ports, bool, err := unstructured.NestedSlice(*appliedServiceUnstructured, "spec", "ports")

if err != nil {
return errors.WithStack(err)
}

if bool {
for _, port := range ports {
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid naming this boolean return value bool. It shadows the predeclared bool identifier and makes the subsequent if bool { ... } hard to read/grep. Rename it to something like found/exists (and update the if accordingly).

Copilot uses AI. Check for mistakes.
@kaovilai kaovilai force-pushed the with-lint-fix branch 5 times, most recently from 6185ab2 to a2d5f60 Compare March 26, 2026 03:42
- Bump golangci-lint to v1.64.6 and update .golangci.yaml config
- Replace interface{} with any (Go 1.18+)
- Drop zero-value initializers (= 0, = nil) from var declarations
- Omit inferable types from var declarations
- Replace n += 1 with n++
- Replace single-case switch with if-then
- Fix useless assert.True calls in data_download_controller_test
- Fix assert.Equalf arg count in volumesnapshot_action_test
- Remove redundant nil checks before len()
- Fix go:generate directive spacing
- Add //nolint:gosec for test code
- Fix G115 integer overflow conversions
- Remove unused functions
- Fix unchecked error returns

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 26, 2026

Codecov Report

❌ Patch coverage is 55.14019% with 96 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.31%. Comparing base (765b22f) to head (6e91e72).

Files with missing lines Patch % Lines
pkg/cmd/server/plugin/plugin.go 0.00% 29 Missing ⚠️
pkg/plugin/clientmgmt/process/logrus_adapter.go 27.27% 8 Missing ⚠️
pkg/cmd/util/output/backup_structured_describer.go 84.84% 5 Missing ⚠️
pkg/datapath/micro_service_watcher.go 0.00% 5 Missing ⚠️
...g/plugin/clientmgmt/process/restartable_process.go 0.00% 4 Missing ⚠️
...nternal/resourcemodifiers/strategic_merge_patch.go 25.00% 3 Missing ⚠️
pkg/cmd/cli/backup/create.go 0.00% 3 Missing ⚠️
pkg/cmd/cli/restore/create.go 25.00% 3 Missing ⚠️
pkg/backup/backup.go 60.00% 2 Missing ⚠️
pkg/repository/udmrepo/kopialib/lib_repo.go 33.33% 2 Missing ⚠️
... and 32 more
Additional details and impacted files
@@               Coverage Diff                @@
##           release-1.15    #9648      +/-   ##
================================================
+ Coverage         59.10%   59.31%   +0.20%     
================================================
  Files               367      367              
  Lines             39188    31118    -8070     
================================================
- Hits              23162    18457    -4705     
+ Misses            14545    11180    -3365     
  Partials           1481     1481              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

has-e2e-2tests has-unit-tests kind/changelog-not-required PR does not require a user changelog. Often for docs, website, or build changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants