Skip to content

fix(e2e): poll for OVS bridge addresses in ovn-vpc-nat-gw test#6355

Merged
oilbeater merged 1 commit intomasterfrom
fix/e2e-ovn-nat-gw-bridge-addr-race
Feb 27, 2026
Merged

fix(e2e): poll for OVS bridge addresses in ovn-vpc-nat-gw test#6355
oilbeater merged 1 commit intomasterfrom
fix/e2e-ovn-nat-gw-bridge-addr-race

Conversation

@oilbeater
Copy link
Copy Markdown
Collaborator

Summary

  • Fix flaky e2e test [group:ovn-vpc-nat-gw] Test ovn eip fip snat dnat that intermittently fails at line 341 with bridge.NonLinkLocalAddresses() returning nil
  • Root cause: race between daemon's second initProviderNetwork call (triggered by controller's periodic status update every 30s) and the test's ip addr show check — the OVS bridge may briefly lose its addresses during the OVSDB transaction processing
  • Replace one-shot bridge address assertion with a polling loop (2s interval, 30s timeout) that waits for bridge addresses to stabilize before proceeding with validations

Test plan

  • Run the ovn-vpc-nat-gw e2e test suite multiple times to verify the flaky failure no longer occurs
  • Verify that both itFn calls (main provider network and extra provider network) benefit from the fix

🤖 Generated with Claude Code

The "Test ovn eip fip snat dnat" e2e test intermittently fails because
the OVS bridge has no IP addresses when checked. This race occurs when
the daemon re-processes the provider network event (triggered by the
controller's periodic status update) and briefly reconfigures the bridge
via OVS commands, right as the test queries `ip addr show`.

Replace the one-shot bridge address assertion with a polling loop that
waits up to 30s for the bridge addresses to stabilize before proceeding
with the remaining validations.

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 26, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 critical flakiness issue in an end-to-end test related to OVN VPC NAT Gateway. The core problem stemmed from timing discrepancies during network configuration, leading to unstable bridge address reporting. The solution introduces a more resilient validation approach, ensuring test stability and reliability without altering core functionality.

Highlights

  • Flaky Test Fix: Resolved an intermittent failure in the ovn-vpc-nat-gw e2e test caused by a race condition where OVS bridge addresses would temporarily disappear.
  • Polling Mechanism: Replaced a one-shot assertion for OVS bridge addresses with a robust polling loop, waiting for addresses to stabilize before validation.
  • Race Condition Mitigation: Mitigated a race between the daemon's initProviderNetwork call and the test's ip addr show check, which previously led to bridge.NonLinkLocalAddresses() returning nil.
Changelog
  • test/e2e/ovn-vpc-nat-gw/e2e_test.go
    • Introduced a framework.WaitUntil polling loop to ensure OVS bridge addresses are stable before proceeding with assertions.
    • Removed a redundant ExpectNotNil(bridge) check, as the polling mechanism implicitly handles bridge existence.
    • Updated the ExpectConsistOf assertion to compare against expectedAddrs captured before the polling loop, ensuring consistent validation.
Activity
  • The author provided a test plan outlining steps to verify the fix, including running the ovn-vpc-nat-gw e2e test suite multiple times.
  • The author confirmed the fix should benefit both main and extra provider network itFn calls.
  • The pull request description indicates it was generated with Claude 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 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.

@dosubot dosubot bot added the test automation tests label Feb 26, 2026
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 effectively addresses a flaky e2e test by introducing a polling mechanism to wait for OVS bridge addresses to stabilize. The implementation is sound and directly targets the described race condition. I have one minor suggestion to improve the clarity of the framework.WaitUntil call, as its current usage could be misleading for future maintenance.

ginkgo.By("get provider bridge v4 ip " + addr)
*bridgeIps = append(*bridgeIps, addr)
}
framework.WaitUntil(2*time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
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 framework.WaitUntil function appears to have a hardcoded polling interval of 2 seconds and ignores its first argument. While the value you've passed (2*time.Second) coincidentally matches the hardcoded interval, this is misleading and could cause confusion or bugs during future maintenance. The function signature in test/e2e/framework/wait.go is func WaitUntil(_, timeout time.Duration, ...) where the first argument is explicitly ignored.

To avoid confusion, it would be better to pass a zero value for the ignored interval. Ideally, framework.WaitUntil would be updated to accept and use the interval parameter, but since that's outside the scope of this PR, making the call less ambiguous is a good step.

Suggested change
framework.WaitUntil(2*time.Second, 30*time.Second, func(_ context.Context) (bool, error) {
framework.WaitUntil(0, 30*time.Second, func(_ context.Context) (bool, error) {

@oilbeater oilbeater merged commit 1c654cb into master Feb 27, 2026
76 checks passed
@oilbeater oilbeater deleted the fix/e2e-ovn-nat-gw-bridge-addr-race branch February 27, 2026 01:53
oilbeater added a commit that referenced this pull request Feb 27, 2026
…ling

Three E2E tests had flaky patterns identified during analysis of recent
fixes (#6343, #6345, #6347, #6349, #6355, #6358):

node/node.go:
- "should access overlay pods using node ip": RunHostCmdOrDie with no
  retry; OVN join subnet routes may not yet be installed on the host
  network stack when the pod turns Ready. Replace with WaitUntil (30s)
  and increase curl timeout from 2s to 5s.
- "should access overlay services using node ip": same issue plus no
  endpoint readiness wait before the curl. Add endpoint WaitUntil (1m)
  then wrap the connectivity check with WaitUntil (30s).

underlay/underlay.go:
- "should be able to detect conflict vlan subnet": two time.Sleep(10s)
  calls used fixed waits instead of condition-based polling. Replace
  the first sleep with WaitUntil waiting for conflictVlan1 to be
  processed (non-conflicting), and the second with WaitUntil waiting
  for conflictVlan2.Status.Conflict to become true.
- checkU2OFilterOpenFlowExist: manual "for range 3" retry loop with a
  hard 5s sleep. Replace with a deadline-based loop (30s, 2s interval)
  using time.Now().After for a clean timeout boundary.

subnet/subnet.go:
- "should detect MAC address conflict": time.Sleep(2s) before a
  one-shot event list is too short on a loaded cluster. Replace with
  WaitUntil (500ms interval, 15s timeout) polling for the
  AddressConflict Warning event.

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
oilbeater added a commit that referenced this pull request Feb 27, 2026
…ling (#6362)

* fix(e2e): replace hard sleeps and unretried checks with WaitUntil polling

Three E2E tests had flaky patterns identified during analysis of recent
fixes (#6343, #6345, #6347, #6349, #6355, #6358):

node/node.go:
- "should access overlay pods using node ip": RunHostCmdOrDie with no
  retry; OVN join subnet routes may not yet be installed on the host
  network stack when the pod turns Ready. Replace with WaitUntil (30s)
  and increase curl timeout from 2s to 5s.
- "should access overlay services using node ip": same issue plus no
  endpoint readiness wait before the curl. Add endpoint WaitUntil (1m)
  then wrap the connectivity check with WaitUntil (30s).

underlay/underlay.go:
- "should be able to detect conflict vlan subnet": two time.Sleep(10s)
  calls used fixed waits instead of condition-based polling. Replace
  the first sleep with WaitUntil waiting for conflictVlan1 to be
  processed (non-conflicting), and the second with WaitUntil waiting
  for conflictVlan2.Status.Conflict to become true.
- checkU2OFilterOpenFlowExist: manual "for range 3" retry loop with a
  hard 5s sleep. Replace with a deadline-based loop (30s, 2s interval)
  using time.Now().After for a clean timeout boundary.

subnet/subnet.go:
- "should detect MAC address conflict": time.Sleep(2s) before a
  one-shot event list is too short on a loaded cluster. Replace with
  WaitUntil (500ms interval, 15s timeout) polling for the
  AddressConflict Warning event.

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(e2e): replace per-node sleep with WaitUntil in vlan_subinterfaces test

After patching ProviderNetwork with AutoCreateVlanSubinterfaces=false,
the test verified existing subinterfaces were not deleted by sleeping
5 seconds inside the per-node loop (N nodes × 5s wasted time) and then
doing an immediate assertion.

This has two problems:
1. The sleep runs once per node, wasting N*5s even when the daemon
   reconciles quickly.
2. If the controller deletes a subinterface after the 5s sleep window,
   ExpectTrue produces a false-positive pass.

Replace with WaitUntil (2s interval, 30s timeout) per node: the check
passes on the first poll if subinterfaces are stable (common case), and
retries up to 30s if there is any transient disruption, eliminating
both issues.

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(e2e): eliminate race between VIP finalizer addition and WaitToBeReady

Root cause: handleAddVirtualIP called createOrUpdateVipCR to set
Status.V4ip (triggering WaitToBeReady), but the finalizer was only
added later in handleUpdateVirtualIP (triggered by a subsequent
update event). This created a race window where CreateSync could
return a VIP object with V4ip set but without the finalizer.

Fix 1 (controller): In createOrUpdateVipCR's else branch, add the
finalizer atomically in the same Update() call that sets spec/status,
so the VIP is fully initialized in one API operation.

Fix 2 (test framework): Update WaitToBeReady to require both an IP
address AND the controller finalizer before declaring a VIP ready,
ensuring tests only proceed with a fully-initialized VIP.

Fix 3 (test): Add ginkgo.DeferCleanup for testVipName inside the
It block so the VIP is deleted even on test failure, preventing
the AfterEach subnetClient.DeleteSync from timing out.

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>

---------

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files. test automation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant