Fluid pr pkg controllers deploy#5682
Fluid pr pkg controllers deploy#5682hxrshxz wants to merge 1 commit intofluid-cloudnative:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello, 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 significantly refactors the runtime controller deployment logic by migrating its test suite to Ginkgo/Gomega, which improves the maintainability and expressiveness of tests. Concurrently, it enhances the robustness of the precheck function management by introducing deferred discovery, thread-safe access, and proper isolation, ensuring that runtime controller scaling behaves predictably and correctly under various conditions. 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
|
|
Hi @hxrshxz. Thanks for your PR. I'm waiting for a fluid-cloudnative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
There was a problem hiding this comment.
Code Review
This pull request is a nice refactoring of the runtime controller deployment logic. It migrates the tests to Ginkgo/Gomega, which greatly improves their readability and structure. The change to defer precheck function discovery until runtime is also a good improvement for startup performance.
I've found one potential concurrency issue in getPrecheckFuncs where a lock is held during a potentially slow I/O operation. I've left a comment with a suggestion to improve it.
Overall, this is a high-quality contribution.
| func getPrecheckFuncs() map[string]CheckFunc { | ||
| precheckFuncsMu.Lock() | ||
| defer precheckFuncsMu.Unlock() | ||
|
|
||
| if precheckFuncs != nil { | ||
| return clonePrecheckFuncs(precheckFuncs) | ||
| } | ||
|
|
||
| return clonePrecheckFuncs(resolveDefaultPrecheckFuncs()) | ||
| } |
There was a problem hiding this comment.
The current implementation of getPrecheckFuncs holds a mutex lock while calling resolveDefaultPrecheckFuncs(). On its first execution, resolveDefaultPrecheckFuncs() triggers API discovery which can be a slow I/O operation. Holding a lock during I/O can lead to performance bottlenecks, especially if multiple goroutines attempt to call this function concurrently at startup.
To improve this, you can use a double-checked locking pattern to avoid holding the lock during the potentially slow discovery process. This ensures that other goroutines are not blocked.
func getPrecheckFuncs() map[string]CheckFunc {
precheckFuncsMu.Lock()
if precheckFuncs != nil {
cloned := clonePrecheckFuncs(precheckFuncs)
precheckFuncsMu.Unlock()
return cloned
}
precheckFuncsMu.Unlock()
// resolveDefaultPrecheckFuncs may perform I/O and can be slow on the first call.
// It's better to not hold the lock during this operation.
defaultFuncs := resolveDefaultPrecheckFuncs()
// Re-lock and check again in case setPrecheckFunc was called concurrently.
precheckFuncsMu.Lock()
defer precheckFuncsMu.Unlock()
if precheckFuncs != nil {
return clonePrecheckFuncs(precheckFuncs)
}
return clonePrecheckFuncs(defaultFuncs)
}Signed-off-by: Harsh <harshmastic@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR modernizes pkg/controllers/deploy by migrating its unit tests from testing/testify-style patterns to Ginkgo/Gomega, and by deferring runtime-controller precheck discovery until it’s actually needed at runtime (instead of package init), improving testability and avoiding early cluster-discovery side effects.
Changes:
- Added a package-local Ginkgo suite entrypoint for
pkg/controllers/deploy. - Rewrote
runtime_controllers_test.goto Ginkgo/Gomega with expanded scenario coverage (scale-out rules, no-match errors, annotation handling, already-running controllers, and precheck isolation). - Refactored runtime controller precheck function handling to be lazily resolved and safely cloned to avoid cross-test/global mutation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/controllers/deploy/suite_test.go | Adds the Ginkgo suite runner for the deploy package. |
| pkg/controllers/deploy/runtime_controllers_test.go | Migrates deploy runtime controller tests to Ginkgo/Gomega and adds isolation-focused assertions. |
| pkg/controllers/deploy/runtime_controllers.go | Defers default precheck discovery to runtime and adds cloning/locking to prevent global-map mutation leaks. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
c2798ae to
4dc787f
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5682 +/- ##
=======================================
Coverage 61.21% 61.21%
=======================================
Files 444 444
Lines 30540 30540
=======================================
Hits 18694 18694
Misses 10306 10306
Partials 1540 1540 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return clonePrecheckFuncs(precheckFuncs) | ||
| } | ||
|
|
||
| return clonePrecheckFuncs(resolveDefaultPrecheckFuncs()) |
There was a problem hiding this comment.
getPrecheckFuncs() clones the result of resolveDefaultPrecheckFuncs(), but the default resolver already returns a newly allocated map (via filterOutDisabledRuntimes). This adds an extra allocation/copy on every call. Consider returning the resolved default map directly (and document that the resolver must return a new map), or otherwise restructure so the default path only allocates once while still preventing callers from mutating shared state.
| return clonePrecheckFuncs(resolveDefaultPrecheckFuncs()) | |
| return resolveDefaultPrecheckFuncs() |



I. Describe what this PR does
Migrate
pkg/controllers/deploytests to Ginkgo/Gomega and defer runtime controller precheck discovery until runtime use.II. Does this pull request fix one issue?
#5676
III. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.
Added package-local Ginkgo suite coverage for deploy runtime controller scale-out behavior, no-match errors, replica annotation handling, already-running controllers, precheck map isolation, and non-pinned default precheck resolution.
IV. Describe how to verify it
make fmtgo test ./pkg/controllers/deploy/... -count=1go test -race ./pkg/controllers/deploy/... -count=1rg 'testify' pkg/controllers/deploy/*.goV. Special notes for reviews
N/A