Skip to content

fix(controller): prevent NPE in isOvnSubnet when subnet is nil#6312

Merged
oilbeater merged 1 commit intomasterfrom
fix/isOvnSubnet-nil-check
Feb 21, 2026
Merged

fix(controller): prevent NPE in isOvnSubnet when subnet is nil#6312
oilbeater merged 1 commit intomasterfrom
fix/isOvnSubnet-nil-check

Conversation

@oilbeater
Copy link
Copy Markdown
Collaborator

Summary

  • Fix nil pointer dereference in isOvnSubnet() when called with a nil subnet (regression from controller: fix stale ip cr after subnet deletion #6275)
  • When an IP CR references a deleted subnet, handleUpdateIP now safely skips OVN port cleanup instead of panicking
  • Add unit tests for isOvnSubnet (nil/empty/OVN/non-OVN provider) and integration test for handleUpdateIP with a deleted subnet

Fixes #6309

Test plan

  • make lint passes (0 issues)
  • Test_isOvnSubnet — nil subnet returns false without panic
  • Test_handleUpdateIP_deletedSubnet — IP referencing deleted subnet is handled gracefully
  • All existing controller unit tests pass

🤖 Generated with Claude Code

When an IP CR references a deleted subnet, handleUpdateIP calls
isOvnSubnet with a nil subnet pointer, causing a panic that puts
the controller into CrashLoopBackOff. Add a nil check so that
isOvnSubnet safely returns false for nil input.

Fixes #6309

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:L This PR changes 100-499 lines, ignoring generated files. label Feb 21, 2026
@dosubot
Copy link
Copy Markdown

dosubot bot commented Feb 21, 2026

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added bug Something isn't working test automation tests labels Feb 21, 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 bug that caused a nil pointer dereference in the controller when an IP resource was associated with a subnet that no longer existed. The changes ensure that the controller can robustly handle such edge cases, preventing crashes and maintaining stability by gracefully skipping operations on deleted resources. This significantly improves the controller's resilience and error handling.

Highlights

  • Nil Pointer Dereference Fix: Resolved a nil pointer dereference issue in the isOvnSubnet() function that occurred when it was called with a nil subnet, which was a regression introduced in controller: fix stale ip cr after subnet deletion #6275.
  • Graceful IP Update Handling: Ensured that handleUpdateIP now safely skips OVN port cleanup when an IP Custom Resource (CR) references a deleted subnet, preventing panics.
  • Enhanced Unit Tests: Added comprehensive unit tests for isOvnSubnet to cover cases with nil, empty, OVN, and non-OVN provider subnets.
  • Integration Test for IP Handling: Included an integration test for handleUpdateIP to verify its graceful behavior when processing an IP that refers to a non-existent subnet.
Changelog
  • pkg/controller/controller_test.go
    • Imported ovnipam package.
    • Added ipInformer to the fakeControllerInformers struct.
    • Included IPs slice in FakeControllerOptions for test setup.
    • Implemented logic to create IP resources from options within newFakeControllerWithOptions.
    • Initialized ipsLister, ipSynced, ipam, and updateSubnetStatusQueue in the test controller setup.
  • pkg/controller/ip_test.go
    • Added a new test file ip_test.go.
    • Introduced Test_handleUpdateIP_deletedSubnet to verify the controller's behavior when an IP references a non-existent subnet.
  • pkg/controller/subnet.go
    • Modified the isOvnSubnet function to include a nil check for the subnet parameter, preventing nil pointer dereferences.
  • pkg/controller/subnet_test.go
    • Added Test_isOvnSubnet with multiple test cases to validate the isOvnSubnet function's behavior for nil, empty, OVN, and non-OVN provider subnets.
Activity
  • The author has confirmed that make lint passes with no issues.
  • Unit tests for Test_isOvnSubnet have been added and verified to handle nil subnets without panicking.
  • An integration test Test_handleUpdateIP_deletedSubnet has been added and confirmed to handle IPs referencing deleted subnets gracefully.
  • All existing controller unit tests have passed successfully.
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 effectively addresses a nil pointer dereference in isOvnSubnet by adding a necessary nil check. This fix prevents the controller from panicking when handling IP resources that reference a deleted subnet. The changes are well-supported by the addition of a new unit test for isOvnSubnet and a valuable integration test for handleUpdateIP, ensuring the fix is robust and preventing future regressions. The test infrastructure has been appropriately updated to accommodate these new tests. The code quality is high, and the changes are clear and correct.

@oilbeater oilbeater merged commit 3a28ee1 into master Feb 21, 2026
75 of 77 checks passed
@oilbeater oilbeater deleted the fix/isOvnSubnet-nil-check branch February 21, 2026 12:17
oilbeater added a commit that referenced this pull request Feb 21, 2026
When an IP CR references a deleted subnet, handleUpdateIP calls
isOvnSubnet with a nil subnet pointer, causing a panic that puts
the controller into CrashLoopBackOff. Add a nil check so that
isOvnSubnet safely returns false for nil input.

Fixes #6309

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit 3a28ee1)
zbb88888 pushed a commit to qiniu/kube-ovn that referenced this pull request Apr 7, 2026
…vn#6312)

When an IP CR references a deleted subnet, handleUpdateIP calls
isOvnSubnet with a nil subnet pointer, causing a panic that puts
the controller into CrashLoopBackOff. Add a nil check so that
isOvnSubnet safely returns false for nil input.

Fixes kubeovn#6309

Signed-off-by: Mengxin Liu <liumengxinfly@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit 3a28ee1)
(cherry picked from commit be347ca)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working need backport size:L This PR changes 100-499 lines, ignoring generated files. test automation tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] v1.15.3 regression: IPs referencing non-exsitenct subnets causes KubeOVN controller to panic and CrashLoopBackOff

1 participant