Skip to content

Conversation

oilbeater
Copy link
Collaborator

@oilbeater oilbeater commented Aug 12, 2025

Pull Request

What type of this PR

Examples of user facing changes:

  • Bug fixes

The external gateway uses some very old code that contains many poorly considered aspects. For example, configuration errors can cause the entire feature to fail, and it cannot achieve operation idempotency etc.

Also I think it's not necessary to remove and then recreate ports when gw nodes change.

However, this is just a temporary quick fix to address user feedback problems.

Which issue(s) this PR fixes

Fixes #5262

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.

Summary of Changes

Hello @oilbeater, 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 addresses a bug in the external gateway functionality where logical switch ports (LSPs) were not correctly removed when gateway nodes changed. Previously, the code attempted to delete a logical router port, which was an incorrect operation for patch ports connecting a logical router to a logical switch. The fix now correctly identifies and removes the logical patch port, improving the robustness and idempotency of external gateway operations and resolving configuration error issues.

Highlights

  • External Gateway Bug Fix: Corrected the logic for removing network connections related to external gateways, specifically addressing issues when gateway nodes change.
  • Logical Port Handling: Changed the method from deleting a generic logical router port (DeleteLogicalRouterPort) to specifically removing a logical patch port (RemoveLogicalPatchPort), which is the correct approach for the inter-component connections.
  • Improved Idempotency: This change helps prevent configuration errors and improves the idempotency of external gateway operations, addressing long-standing issues with the older code.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Aug 12, 2025
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 correctly addresses a bug in the external gateway cleanup logic. By replacing DeleteLogicalRouterPort with RemoveLogicalPatchPort, it ensures that both the logical router port and its corresponding logical switch port are deleted, preventing dangling resources. This is a good improvement for the stability and correctness of the external gateway feature. I've added one suggestion to improve maintainability by refactoring the port naming logic.

klog.Infof("delete logical router port %s", lrpName)
if err := c.OVNNbClient.DeleteLogicalRouterPort(lrpName); err != nil {
klog.Errorf("failed to delete lrp %s, %v", lrpName, err)
lspName := fmt.Sprintf("%s-%s", c.config.ExternalGatewaySwitch, c.config.ClusterRouter)

Choose a reason for hiding this comment

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

medium

The logic for constructing lspName here, and lrpName on the previous line, is duplicated in other places like CreateGatewayLogicalSwitch. To improve maintainability and consistency, consider creating a helper function in the util package to centralize this naming convention.

For example, you could add a function like this to pkg/util/ovn.go:

func GetGatewayPortNames(lrName, lsName string) (lrpName, lspName string) {
    lrpName = fmt.Sprintf("%s-%s", lrName, lsName)
    lspName = fmt.Sprintf("%s-%s", lsName, lrName)
    return
}

And then use it here and in other places where these names are constructed.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 16904223583

Details

  • 0 of 4 (0.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.005%) to 21.407%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/controller/external_gw.go 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
pkg/ovs/ovn-nb-logical_router_route.go 2 74.6%
Totals Coverage Status
Change from base Build 16892022459: -0.005%
Covered Lines: 10579
Relevant Lines: 49418

💛 - Coveralls

@oilbeater oilbeater merged commit 9691549 into master Aug 12, 2025
136 of 138 checks passed
@oilbeater oilbeater deleted the fix/ex-gw branch August 12, 2025 10:15
oilbeater added a commit that referenced this pull request Aug 12, 2025
Signed-off-by: Mengxin Liu <[email protected]>
(cherry picked from commit 9691549)
oilbeater added a commit that referenced this pull request Aug 12, 2025
Signed-off-by: Mengxin Liu <[email protected]>
(cherry picked from commit 9691549)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Modify external-gw-nodes has error
2 participants