fix: sgs need to sync when neccessary#6297
Conversation
Summary of ChangesHello @zbb88888, 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 optimizes resource utilization by implementing a lazy initialization strategy for the default Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
Pull Request Test Coverage Report for Build 21905303159Details
💛 - Coveralls |
65ce620 to
17020bc
Compare
There was a problem hiding this comment.
Code Review
This pull request optimizes the initialization of the deny_all security group, making it lazy to reduce unnecessary resource creation. However, a critical race condition exists during controller startup due to a missing informer cache synchronization. This could lead to a temporary security bypass where the default-deny policy is not applied to ports with security groups until the cache synchronizes, potentially causing incorrect behavior.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new flag init-default-deny-all-sg to make the initialization of the default deny-all security group optional. This is useful for users who do not use Kube-OVN's security group feature. The changes are consistently applied across Helm charts, the installation script, and the controller's configuration. Additionally, the security group cache is now properly synced before use.
However, I've identified a potential issue where the implementation is incomplete. Even when the new flag is set to false, other parts of the code may still try to operate on the deny_all security group, which would not exist, leading to errors. Please see my detailed comment for a fix.
7443f95 to
9208dd2
Compare
3ee78f8 to
fd67a3b
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new enable-security-group flag to make the security group feature optional, with well-implemented changes across the Helm charts, installation script, and controller logic. However, two critical security issues were identified: a medium-severity issue where disabling the feature flag leads to an insecure partial-enforcement state, and a high-severity DoS vulnerability where malformed Pod annotations can block the enforcement of the default-deny policy cluster-wide. Additionally, there's an area for improvement regarding test coverage for the new logic and a minor typo in the pull request title ('neccessary' should be 'necessary').
fd67a3b to
8fd8881
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new flag enable-security-group to make the security group feature optional, which is a valuable addition for users who may not need this functionality. The changes are consistently applied across Helm charts, installation scripts, and the controller logic. When the feature is disabled, initialization is skipped, related resources are garbage collected, and handlers exit early. The new tests for garbage collection are well-written and cover the new logic. I have a few minor suggestions to simplify the code by removing some redundant checks.
8fd8881 to
41a2bf0
Compare
fix: add sgSynced to cache sync wait list Signed-off-by: zbb88888 <jmdxjsjgcxy@gmail.com>
41a2bf0 to
f3bf830
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new enable-security-group flag to make the security group feature optional, which is a great enhancement for flexibility. The changes are consistently applied across Helm charts, the installation script, and the controller logic. The logic to conditionally initialize and garbage-collect security group resources based on this flag is well-implemented. Additionally, a fix is included to ensure security group caches are properly synced at startup. My only suggestion is to improve the robustness of a test mock to make it less dependent on argument order, enhancing test suite maintainability.
| fc.mockOvnClient.EXPECT(). | ||
| DeletePortGroup(denyAllPg, orphanedPg). | ||
| Return(nil) |
There was a problem hiding this comment.
The mock expectation for DeletePortGroup is order-sensitive because it lists the expected port group names as separate arguments. This makes the test fragile. The order of port groups to be deleted depends on the iteration order of the portGroups slice in gcSecurityGroup. While this is deterministic for a slice, it can easily break if the slice initialization is changed in the future.
Consider making the expectation order-insensitive. One way to do this with gomock is to use a custom matcher or DoAndReturn to verify the arguments without depending on their order.
Pull Request
What type of this PR
Examples of user facing changes:
fix: deny all sg may not need if user not use kube-ovn sg
fix: all sg need to sync just after controller sg synced
add enableSecurityGroup just as enableNetworkPolicy
Which issue(s) this PR fixes
Fixes #(issue-number)