Skip to content

Conversation

@shivansh-gohem
Copy link

This PR resolves golint warnings in pkg/controller/encryption/ipsec/ipsec_controller.go to improve code quality and comply with Go best practices.

Changes:

  1. Removed Stuttering: Renamed IPSecController to Controller and NewIPsecController to NewController. Since this resides in the ipsec package, usage becomes ipsec.Controller instead of the repetitive ipsec.IPSecController.
  2. Standardization: Updated ClusterId -> ClusterID and PodIp -> PodIP to match Go naming conventions.
  3. Documentation: Added missing GoDoc comments for exported functions (NewController, Run, Stop, CleanAllIPsec).
  4. Refactoring: Updated ipsec_controller_test.go and pkg/controller/controller.go to reflect the renaming changes.

Verification:
Ran golangci-lint run --build-tags=linux pkg/controller/encryption/ipsec/... locally. Verified that all linting errors (typecheck and style) related to this controller are resolved.

Fixes #1475

@kmesh-bot
Copy link
Collaborator

Welcome @shivansh-gohem! It looks like this is your first PR to kmesh-net/kmesh 🎉

@gemini-code-assist
Copy link

Summary of Changes

Hello @shivansh-gohem, 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 significantly improves the code quality and adherence to Go best practices within the IPsec controller logic. The primary goal was to resolve golint warnings by addressing naming inconsistencies, such as name stuttering and improper acronym capitalization, and by adding comprehensive documentation. These changes result in a cleaner, more maintainable, and idiomatic Go codebase without altering the functional behavior of the IPsec controller.

Highlights

  • Code Renaming for Clarity: The IPSecController struct has been renamed to Controller and the NewIPsecController function to NewController within the ipsec package to eliminate name stuttering, making usage more idiomatic (e.g., ipsec.Controller).
  • Go Naming Convention Adherence: Variable and field names like ClusterId and PodIp have been updated to ClusterID and PodIP respectively, aligning with standard Go naming conventions for acronyms.
  • Improved Documentation: Missing GoDoc comments have been added for exported functions and types, including NewController, Run, Stop, CleanAllIPsec, and the Controller struct itself, enhancing code readability and maintainability.
  • Refactoring and Test Updates: Related files, specifically ipsec_controller_test.go and pkg/controller/controller.go, have been updated to reflect the renaming changes, ensuring consistency across the codebase.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.


Code now shines so bright, Stutter gone, names now clear, Linting makes it right.

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 effectively resolves golint warnings and improves code quality by removing name stuttering and adding documentation, which aligns with Go best practices. The changes are clear and well-executed. I've included a couple of suggestions to enhance error handling, making the controller more robust by preventing silent failures.

Comment on lines +376 to 382
func (c *Controller) deleteKNIMapCIDR(remoteCIDR string, mapfd *ebpf.Map) {
kniKey, err := c.generalKNIMapKey(remoteCIDR)
if err != nil {
return
}
_ = mapfd.Delete(kniKey)
}

Choose a reason for hiding this comment

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

high

The function deleteKNIMapCIDR silently fails by returning early if generalKNIMapKey returns an error, and it ignores the error from mapfd.Delete. This can lead to stale entries in the eBPF map if deletion fails, which could cause incorrect networking behavior. The function should return an error to allow the caller to handle failures appropriately. You will need to update the call site in handleKNIDelete to handle the returned error, for example by logging it.

Suggested change
func (c *Controller) deleteKNIMapCIDR(remoteCIDR string, mapfd *ebpf.Map) {
kniKey, err := c.generalKNIMapKey(remoteCIDR)
if err != nil {
return
}
_ = mapfd.Delete(kniKey)
}
func (c *Controller) deleteKNIMapCIDR(remoteCIDR string, mapfd *ebpf.Map) error {
kniKey, err := c.generalKNIMapKey(remoteCIDR)
if err != nil {
return err
}
return mapfd.Delete(kniKey)
}

@shivansh-gohem
Copy link
Author

Thanks for the review! You are right that the error handling here is missing.

However, since this PR focuses strictly on linting and renaming (to fix #1475), I prefer not to change the function signature or logic right now. This avoids "scope creep" and prevents breaking the reflection-based tests in ipsec_controller_test.go.

I can address the error handling in a separate, follow-up PR

@shivansh-gohem shivansh-gohem force-pushed the fix/1475-ipsec-lint branch 4 times, most recently from 7ec502e to ce55d1c Compare January 19, 2026 08:26
@codecov
Copy link

codecov bot commented Jan 19, 2026

Codecov Report

❌ Patch coverage is 65.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.53%. Comparing base (3018401) to head (cacd85a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...kg/controller/encryption/ipsec/ipsec_controller.go 68.42% 6 Missing ⚠️
pkg/controller/controller.go 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
pkg/controller/controller.go 0.00% <0.00%> (ø)
...kg/controller/encryption/ipsec/ipsec_controller.go 50.90% <68.42%> (+0.72%) ⬆️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c77714...cacd85a. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@LiZhenCheng9527 LiZhenCheng9527 left a comment

Choose a reason for hiding this comment

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

I'm not quite sure what the point is in you making these changes.

* current container based on the bpf_get_netns_cookie auxiliary function.
*/
#define MDA_LOOPBACK_ADDR 1
#define MDA_LOOPBACK_ADDR 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change this?

Copy link
Author

Choose a reason for hiding this comment

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

My apologies. These changes were automatically generated by the build script based on my local kernel environment and were included by mistake. I will revert the file so that PR will now only contain the intended linting fixes!

Signed-off-by: Shivansh Sahu <sahushivansh142@gmail.com>
@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Details 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


type IPSecController struct {
// Controller manages the IPsec configuration and synchronization for Kmesh.
type Controller struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I still have some confusion. Why is this change needed? Is there something wrong with the name IPSecController?

Copy link
Author

Choose a reason for hiding this comment

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

The renaming from IPSecController to Controller addresses a golint warning regarding "stuttering."

Since this struct resides within the ipsec package, Go naming conventions suggest avoiding the repetition of the package name in the type name.

  • Before: ipsec.IPSecController (Redundant repetition)
  • After: ipsec.Controller (Clean and idiomatic)

This change aligns the codebase with standard Go style guidelines without altering any logic.

@shivansh-gohem
Copy link
Author

/cc @LiZhenCheng9527

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

golint warnings in ipsec_controller.go

3 participants