Skip to content

fix localnet port should not be static "patch-localnet."#6244

Merged
changluyi merged 2 commits intomasterfrom
feat/metallb-multi-underlay-e2e
Feb 2, 2026
Merged

fix localnet port should not be static "patch-localnet."#6244
changluyi merged 2 commits intomasterfrom
feat/metallb-multi-underlay-e2e

Conversation

@changluyi
Copy link
Copy Markdown
Collaborator

Pull Request

What type of this PR

Examples of user facing changes:

  • Features
  • Bug fixes
  • Docs
  • Tests

Which issue(s) this PR fixes

Fixes #(issue-number)

Signed-off-by: clyi <clyi@alauda.io>
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 1, 2026
@dosubot
Copy link
Copy Markdown

dosubot bot commented Feb 1, 2026

Related Documentation

No published documentation to review for changes on this repository.

Write your first living document

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the bug Something isn't working label Feb 1, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @changluyi, 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 introduces a crucial fix for handling local network service load balancing in environments with multiple subnets. By making the patch-localnet port naming dynamic based on the subnet, it ensures that Open vSwitch (OVS) flow rules are correctly applied, preventing potential conflicts and misconfigurations. The changes also include an enhancement to the LbServiceRules structure to incorporate subnet information and a more robust method for retrieving OVS port identifiers.

Highlights

  • Dynamic patch-localnet port naming: The patch-localnet port name is now dynamically generated using the subnet name, resolving issues with static naming and enabling correct flow rule application for services across different subnets.
  • LbServiceRules enhancement: The LbServiceRules struct has been extended to include SubnetName, ensuring that service load balancing rules are correctly associated with their respective subnets.
  • Refactored OVS port ID retrieval: The getPortID function has been refactored to directly query Open vSwitch (OVS) for port IDs, improving robustness and removing a dependency on the ovsClient.OpenFlow.DumpPort method.
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
Copy Markdown
Contributor

@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 fixes an issue by making the localnet port name dynamic based on the subnet name, propagating subnetName to the flow rule creation logic. No vulnerabilities were found during the SAST reconnaissance of pkg/daemon/controller_linux.go and pkg/daemon/flow_rules_linux.go. A suggestion is made to refactor the getPortID function to improve code clarity by removing an unused parameter.

Comment on lines 82 to 94
func (c *Controller) getPortID(bridgeName, portName string) (int, error) {
if c.ovsClient == nil {
return 0, errors.New("ovs client not initialized")
ofportStr, err := ovs.Get("Interface", portName, "ofport", "", true)
if err != nil {
return 0, fmt.Errorf("failed to get ofport for interface %s: %w", portName, err)
}

portInfo, err := c.ovsClient.OpenFlow.DumpPort(bridgeName, portName)
portID, err := strconv.Atoi(strings.TrimSpace(ofportStr))
if err != nil {
return 0, fmt.Errorf("failed to dump port %s on bridge %s: %w", portName, bridgeName, err)
return 0, fmt.Errorf("failed to parse ofport %q: %w", ofportStr, err)
}
return portInfo.PortID, nil

return portID, nil
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The bridgeName parameter is unused in this function after the refactoring. It should be removed from the function signature and its call sites in AddOrUpdateUnderlaySubnetSvcLocalFlowCache to improve code clarity.

Suggested change
func (c *Controller) getPortID(bridgeName, portName string) (int, error) {
if c.ovsClient == nil {
return 0, errors.New("ovs client not initialized")
ofportStr, err := ovs.Get("Interface", portName, "ofport", "", true)
if err != nil {
return 0, fmt.Errorf("failed to get ofport for interface %s: %w", portName, err)
}
portInfo, err := c.ovsClient.OpenFlow.DumpPort(bridgeName, portName)
portID, err := strconv.Atoi(strings.TrimSpace(ofportStr))
if err != nil {
return 0, fmt.Errorf("failed to dump port %s on bridge %s: %w", portName, bridgeName, err)
return 0, fmt.Errorf("failed to parse ofport %q: %w", ofportStr, err)
}
return portInfo.PortID, nil
return portID, nil
}
func (c *Controller) getPortID(portName string) (int, error) {
oftportStr, err := ovs.Get("Interface", portName, "ofport", "", true)
if err != nil {
return 0, fmt.Errorf("failed to get ofport for interface %s: %w", portName, err)
}
portID, err := strconv.Atoi(strings.TrimSpace(ofportStr))
if err != nil {
return 0, fmt.Errorf("failed to parse ofport %q: %w", ofportStr, err)
}
return portID, nil
}

@coveralls
Copy link
Copy Markdown

coveralls commented Feb 1, 2026

Pull Request Test Coverage Report for Build 21575060506

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 23 (0.0%) changed or added relevant lines in 2 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage decreased (-0.002%) to 22.931%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/daemon/controller_linux.go 0 11 0.0%
pkg/daemon/flow_rules_linux.go 0 12 0.0%
Files with Coverage Reduction New Missed Lines %
pkg/daemon/flow_rules_linux.go 1 0.0%
Totals Coverage Status
Change from base Build 21538844522: -0.002%
Covered Lines: 12330
Relevant Lines: 53770

💛 - Coveralls

Signed-off-by: clyi <clyi@alauda.io>
@changluyi changluyi requested a review from zhangzujian February 2, 2026 03:08
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 2, 2026
@changluyi changluyi merged commit 98a3b1e into master Feb 2, 2026
75 of 77 checks passed
@changluyi changluyi deleted the feat/metallb-multi-underlay-e2e branch February 2, 2026 03:56
changluyi added a commit that referenced this pull request Feb 2, 2026
* fix localnet port

Signed-off-by: clyi <clyi@alauda.io>
changluyi added a commit that referenced this pull request Feb 2, 2026
* fix localnet port

Signed-off-by: clyi <clyi@alauda.io>
zbb88888 pushed a commit to qiniu/kube-ovn that referenced this pull request Feb 2, 2026
* fix localnet port

Signed-off-by: clyi <clyi@alauda.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants