Skip to content

Conversation

@RainbowMango
Copy link
Member

What type of PR is this?

/kind cleanup

What this PR does / why we need it:
This PR bumps golangci-lint to v2.6+ so that we can use modernize to simplify the code.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:
This PR contains a workaround commit to ignore the false positive warning as tracked by golangci/golangci-lint#5979. We can wait for that to be resolved before moving forward.
/hold

Does this PR introduce a user-facing change?:

NONE

Copilot AI review requested due to automatic review settings December 2, 2025 12:38
@karmada-bot karmada-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Dec 2, 2025
@karmada-bot karmada-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Dec 2, 2025
@RainbowMango RainbowMango added this to the v1.17 milestone Dec 2, 2025
Copilot finished reviewing on behalf of RainbowMango December 2, 2025 12:39
@gemini-code-assist
Copy link

Summary of Changes

Hello @RainbowMango, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on enhancing code quality and maintainability by upgrading the project's linter infrastructure. It introduces a newer version of golangci-lint and activates the modernize linter, which helps identify opportunities to simplify Go code. The changes also include targeted refactorings to adopt more idiomatic and efficient Go patterns, alongside a temporary measure to manage a specific linter warning until an upstream fix is available.

Highlights

  • Linter Upgrade and Modernization: The golangci-lint tool has been updated to version v2.6.2, and the modernize linter has been enabled to encourage the use of modern Go language features.
  • Code Refactoring for Efficiency and Readability: Numerous code sections have been refactored to leverage modern Go constructs such as strings.Builder for efficient string concatenation, slices.Contains for simplified slice checks, maps.Copy for map operations, and the any type alias for interface{} to improve readability.
  • Workaround for Linter False Positives: A temporary workaround has been implemented to address a known false positive warning (SA5011) from the modernize linter, specifically related to possible nil pointer dereferences. This is being tracked in a golangci/golangci-lint issue.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request bumps golangci-lint and enables the modernize linter, which has resulted in a large number of small, mechanical changes across the codebase to adopt more modern Go features. These changes include using any instead of interface{}, leveraging the slices and maps packages, using strings.Builder for performance, and adopting Go 1.21+ features like min/max builtins and Go 1.22 features like for range on integers. The changes are generally positive and improve code quality and performance. The configuration changes in .golangci.yml to disable some checks are well-justified for a large, existing codebase. I've found one minor issue in a test file where a refactoring made the test logic less clear, but overall, this is a great modernization effort.

Comment on lines +435 to 439
for range rsl {
if reflect.TypeFor[corev1.ResourceName]().String() != "v1.ResourceName" {
t.Errorf("Got %v expected %v", reflect.TypeFor[corev1.ResourceName](), "v1.ResourceName")
}
}

Choose a reason for hiding this comment

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

medium

The loop variable name was removed, but it was used in the original code inside reflect.TypeOf(name). The new code for range rsl with reflect.TypeFor[corev1.ResourceName]() inside the loop makes the loop redundant as it checks the same static type information in every iteration. This change seems to be a result of a faulty linter suggestion and makes the test less clear. Please consider restoring the use of the loop variable or refactor the test to perform the check once outside the loop if that's the intent.

Copy link
Contributor

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 modernizes the codebase by bumping golangci-lint to v2.6+ and applying the modernize linter to simplify code using newer Go language features. The changes are primarily automated refactorings that leverage Go 1.21+ features including:

  • Replacing interface{} with any alias
  • Using slices.Contains() instead of manual loops
  • Using maps.Copy() for map copying
  • Using range-over-integer syntax (for range n)
  • Using strings.SplitSeq() iterator-based splitting
  • Using fmt.Appendf() instead of fmt.Sprintf() with byte slices
  • Using min() builtin function
  • Using reflect.TypeFor[T]() instead of reflect.TypeOf((*T)(nil))
  • Using t.Context() in tests instead of manual context creation
  • Using b.Loop() in benchmarks

Reviewed changes

Copilot reviewed 221 out of 221 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/helper/scheduler.go Replaced manual contains loops with slices.Contains
test/helper/resource.go Updated interface{} to any, for loop to range syntax
test/e2e/suites/operator/api_sidecar_test.go Replaced loop with slices.Contains
test/e2e/suites/base/*.go Updated map[string]interface{} to map[string]any throughout test files
test/e2e/framework/*.go Updated function signatures to use any instead of interface{}
pkg/webhook/**/*.go Updated interface{} to any, added slices usage
pkg/util/*.go Added maps/slices imports, modernized loops and map copying
pkg/scheduler/**/*.go Updated interface{} to any, modernized for loops
pkg/resourceinterpreter/**/*.go Comprehensive updates to test fixtures using any
pkg/search/**/*.go Updated handlers and context usage

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

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 64.15094% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.55%. Comparing base (8bebb5d) to head (806e1bd).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
pkg/karmadactl/interpret/edit.go 0.00% 7 Missing ⚠️
pkg/metricsadapter/provider/resourcemetrics.go 0.00% 7 Missing ⚠️
pkg/search/backendstore/opensearch.go 0.00% 7 Missing ⚠️
pkg/karmadactl/get/get.go 0.00% 5 Missing ⚠️
pkg/detector/detector.go 55.55% 4 Missing ⚠️
pkg/estimator/server/eventhandlers.go 42.85% 4 Missing ⚠️
pkg/karmadactl/addons/search/search.go 0.00% 4 Missing ⚠️
pkg/karmadactl/util/completion/completion.go 0.00% 4 Missing ⚠️
pkg/metricsadapter/controller.go 0.00% 4 Missing ⚠️
pkg/clusterdiscovery/clusterapi/clusterapi.go 0.00% 3 Missing ⚠️
... and 28 more
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6992      +/-   ##
==========================================
- Coverage   46.61%   46.55%   -0.06%     
==========================================
  Files         699      699              
  Lines       48156    48078      -78     
==========================================
- Hits        22447    22385      -62     
+ Misses      24014    24002      -12     
+ Partials     1695     1691       -4     
Flag Coverage Δ
unittests 46.55% <64.15%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Copy link
Member

@dongjiang1989 dongjiang1989 left a comment

Choose a reason for hiding this comment

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

LGTM

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dongjiang1989
Once this PR has been reviewed and has the lgtm label, please assign rainbowmango for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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

Labels

do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants