Skip to content

feat(endpoint_slice): refactor and support arbitrary providers#5414

Merged
zhangzujian merged 3 commits intokubeovn:masterfrom
SkalaNetworks:improve-ep
Jul 17, 2025
Merged

feat(endpoint_slice): refactor and support arbitrary providers#5414
zhangzujian merged 3 commits intokubeovn:masterfrom
SkalaNetworks:improve-ep

Conversation

@SkalaNetworks
Copy link
Copy Markdown
Member

@SkalaNetworks SkalaNetworks commented Jul 1, 2025

Pull Request

What type of this PR

Examples of user facing changes:

  • Features

This PR refactors the way endpoint slices are handled. It makes the logic of detecting the VPC/subnet targetted by a service more straightforward and supports custom providers instead of just the "ovn" one.

Support for specifying "endpoints" instead of selectors is also improved, with custom providers added to them. The refactor will make the implementation of healthchecks for them easier.

Note that this PR doesn't fix the obvious issue where a service targets pods that are in different VPC/subnets. It also only handles the first network of every Pod. For this, we'd need more checks and to use EndpointSlice mirrors.

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.

Summary of Changes

Hello @SkalaNetworks, 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 significant refactoring of how EndpointSlices are processed, primarily focusing on the detection of the target VPC and subnet for services. The changes aim to make this detection logic more straightforward and extensible by supporting arbitrary network providers, moving beyond a hardcoded 'ovn' assumption. It also enhances the configuration capabilities for headless services by allowing SwitchLBRule to propagate network annotations.

Highlights

  • Refactored EndpointSlice VPC/Subnet Detection: The core logic for determining the target VPC and subnet for a service's EndpointSlices has been significantly refactored. The new approach prioritizes explicit LogicalRouterAnnotation and LogicalSwitchAnnotation on the service itself. If not present, it then infers the VPC/subnet by inspecting the network context of the associated pods via their EndpointSlice entries, rather than relying on a direct listing of service-selected pods.
  • Support for Arbitrary Network Providers: The system now dynamically identifies and supports different network providers beyond the default 'ovn'. New helper functions (getPodProviders, getEndpointProvider, getSubnetByProvider, getVpcByProvider, getEndpointVpcAndSubnet) have been introduced to abstract and centralize the process of extracting provider-specific VPC and subnet information from pod annotations, making the endpoint handling more extensible.
  • Enhanced Headless Service Configuration: Headless services generated by SwitchLBRule can now inherit explicit VPC and subnet annotations (LogicalRouterAnnotation and LogicalSwitchAnnotation) directly from the SwitchLBRule object. This provides more granular control over the network placement of these generated services.
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 is currently in preview and 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 to provide feedback.

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 refactors the endpoint slice handling to support arbitrary providers and simplifies the logic for determining the VPC and subnet for a service. There are a few areas for improvement, including a critical fix for a potential panic and some medium-severity issues related to error handling.

Comment thread pkg/controller/switch_lb_rule.go Outdated
Comment thread pkg/controller/endpoint_slice.go Outdated
Comment thread pkg/controller/endpoint_slice.go Outdated
Comment thread pkg/controller/endpoint_slice.go
@coveralls
Copy link
Copy Markdown

coveralls commented Jul 1, 2025

Pull Request Test Coverage Report for Build 16322093478

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

  • 17 of 152 (11.18%) changed or added relevant lines in 2 files are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.01%) to 21.433%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/controller/switch_lb_rule.go 13 15 86.67%
pkg/controller/endpoint_slice.go 4 137 2.92%
Files with Coverage Reduction New Missed Lines %
pkg/controller/switch_lb_rule.go 1 7.42%
pkg/controller/endpoint_slice.go 6 8.2%
Totals Coverage Status
Change from base Build 16287267322: -0.01%
Covered Lines: 10544
Relevant Lines: 49196

💛 - Coveralls

@SkalaNetworks SkalaNetworks force-pushed the improve-ep branch 5 times, most recently from 3add592 to 7abc4b7 Compare July 1, 2025 16:32
@SkalaNetworks
Copy link
Copy Markdown
Member Author

/gemini review

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 introduces significant refactoring to how endpoint slices are handled, making the detection of VPC/subnet for services more robust and supporting arbitrary providers. The changes are well-structured, introducing new helper functions to encapsulate the logic for retrieving provider-specific network information from pods. The addition of setUserDefinedNetwork and its corresponding tests is a good step towards allowing user-defined network configurations for services. The primary concern identified is a potential logical error in the default assignment of VPC and subnet names, which should be addressed for correctness.

Comment thread pkg/controller/endpoint_slice.go Outdated
@SkalaNetworks SkalaNetworks force-pushed the improve-ep branch 3 times, most recently from 0ef9f61 to 8f9cb75 Compare July 4, 2025 18:19
@SkalaNetworks
Copy link
Copy Markdown
Member Author

/gemini review

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 refactors the logic for handling endpoint slices to support arbitrary providers and improve clarity. The changes primarily affect pkg/controller/endpoint_slice.go, breaking down large functions into smaller, more focused ones. This improves modularity and makes the code easier to understand. The PR also propagates user-defined network settings from SwitchLBRule to the generated Service.

Comment thread pkg/controller/endpoint_slice.go Outdated
Comment thread pkg/controller/endpoint_slice.go Outdated
Comment thread pkg/controller/endpoint_slice.go Outdated
Comment thread pkg/controller/endpoint_slice.go Outdated
Comment thread pkg/controller/endpoint_slice.go
Comment thread pkg/controller/endpoint_slice_test.go
Comment thread pkg/controller/switch_lb_rule_test.go
Signed-off-by: SkalaNetworks <contact@skala.network>
@SkalaNetworks SkalaNetworks marked this pull request as ready for review July 4, 2025 19:21
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. feature New network feature refactor labels Jul 4, 2025
@SkalaNetworks
Copy link
Copy Markdown
Member Author

/cc @zhangzujian @oilbeater

This should help for people using custom providers. Especially useful on multi-attached VMs that have many network interfaces of type Kube-OVN.

I'm gonna add healthchecks on custom endpoints next (right now, only selectors are supported).

@SkalaNetworks
Copy link
Copy Markdown
Member Author

@zhangzujian @oilbeater I've prepared a PR to add healthchecks on static endpoints #5435

I'll wait on this one to be merged to get it out of draft as it depends on code present here.

Comment thread pkg/controller/switch_lb_rule_test.go Outdated
@zhangzujian
Copy link
Copy Markdown
Member

Could you please add an e2e test case for this feature?

@SkalaNetworks
Copy link
Copy Markdown
Member Author

Could you please add an e2e test case for this feature?

will do

Comment thread test/e2e/kube-ovn/switch_lb_rule/switch_lb_rule.go
Signed-off-by: SkalaNetworks <contact@skala.network>

if customProvider {
nad := framework.MakeOVNNetworkAttachmentDefinition(subnetName, f.Namespace.Namespace, provider, []request.Route{})
nadClient.Create(nad)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test case requires Multus-CNI. We can move it to test/e2e/multus/e2e_test.go.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@zhangzujian Considering it's gonna run pretty much exactly the same tests as the standard SLRs that don't use Multus, how do you envision it? I'd like to minimize code duplication.

Maybe we can force Multus installations for SLR tests?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can check whether the CRD exists and skip this test case if not found.

Also, we can add a ginkgo label such as multus-cni that indicates this case requires Multus-CNI.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I implemented an if to check if Multus is installed. I'll see for the label.

…stalled

Signed-off-by: SkalaNetworks <contact@skala.network>
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 16, 2025
@zhangzujian zhangzujian merged commit 9d39ee5 into kubeovn:master Jul 17, 2025
72 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New network feature refactor size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants