Skip to content

fix(slr): address family and familypolicy isn't correct #5349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025

Conversation

SkalaNetworks
Copy link
Contributor

Pull Request

What type of this PR

Bug fix on the SwitchLBRules.

The ipFamilies and ipFamilyPolicy aren't honored for the VIP. Because the clusterIP isn't set, K8S determines the family using its defaults.

So if the cluster was installed with a ServiceCIDR that contains the IPv4 range first and the IPv6 second, the family will be set to IPv4 by default. This works in nearly every case.

But if the ServiceCIDR contains the IPv6 range first and the IPv4 range second, the Service is created with ipFamily IPv6, eventhough the VIP might be an IPv4. This breaks the SLR and no endpoint is generated for the service.

The VIP might contain IPv4/IPv6 or a mix of the two. Depending on the content of the VIP, we detect if the Service should be created with ipFamilies IPv4, IPv6 or both. We also compute the ipFamilyPolicy to SingleStack or Dual depending on the number of ipFamilies.

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 @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 fixes a bug in the SwitchLBRule controller where the generated Kubernetes Service was not correctly configured with the appropriate IP families and family policy based on the specified VIP. This could lead to the Service being created with the wrong address family in dual-stack clusters, preventing endpoints from being generated. The changes introduce logic to dynamically determine the correct IP families and policy by inspecting the VIP string and apply these settings to the Service, ensuring compatibility with the provided VIP addresses.

Highlights

  • Bug Fix: SwitchLBRule IP Families: I've addressed a bug where the ipFamilies and ipFamilyPolicy for the Service created by a SwitchLBRule were not being correctly determined based on the VIP, potentially causing issues in dual-stack environments depending on the ServiceCIDR order.
  • Dynamic IP Family Detection: Introduced a new helper function getIPFamilies that inspects the provided VIP string (which can contain comma-separated IPs) to determine if it includes IPv4, IPv6, or both, and sets the appropriate IPFamilies slice and IPFamilyPolicy (SingleStack or PreferDualStack).
  • Service Update Logic: Modified the generateHeadlessService function to call the new getIPFamilies helper and apply the determined families and policy to the Service spec, both when creating a new Service and updating an existing one.
  • IP Protocol Helper: Added a utility function GetIPAddressProtocol in pkg/util/address_family.go to reliably determine if a given IP string is IPv4 or IPv6 using the standard net package.
  • Unit Tests: Added unit tests for the new getIPFamilies function to cover single-stack (IPv4, IPv6) and dual-stack (IPv6 then IPv4, IPv4 then IPv6) scenarios.
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 configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 11, 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

The pull request fixes an issue where the IP family and family policy for SwitchLBRule services were not being set accurately. The core change involves a new utility function getIPFamilies to determine the appropriate settings based on the VIP's IP addresses, and applying these to the generated Kubernetes Service. A critical issue was identified in the new helper function util.GetIPAddressProtocol which could lead to a panic with invalid IP inputs, and a fix is suggested. Additionally, enhancing the test coverage for getIPFamilies with edge cases for VIP strings would improve robustness. A minor typo in a test error message was also noted.

@SkalaNetworks SkalaNetworks force-pushed the fix-slr-services branch 2 times, most recently from d1e72da to aed212a Compare June 12, 2025 07:50
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jun 12, 2025
@zhangzujian zhangzujian merged commit 1fceea2 into kubeovn:master Jun 12, 2025
74 checks passed
zhangzujian pushed a commit that referenced this pull request Jun 12, 2025
@coveralls
Copy link

coveralls commented Jun 12, 2025

Pull Request Test Coverage Report for Build 15605457341

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

  • 14 of 24 (58.33%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 21.755%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/controller/switch_lb_rule.go 14 24 58.33%
Totals Coverage Status
Change from base Build 15605224454: 0.02%
Covered Lines: 10441
Relevant Lines: 47993

💛 - Coveralls

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 need backport size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants