Skip to content

Fluid pr pkg controllers deploy#5682

Open
hxrshxz wants to merge 1 commit intofluid-cloudnative:masterfrom
hxrshxz:fluid-pr-pkg-controllers-deploy
Open

Fluid pr pkg controllers deploy#5682
hxrshxz wants to merge 1 commit intofluid-cloudnative:masterfrom
hxrshxz:fluid-pr-pkg-controllers-deploy

Conversation

@hxrshxz
Copy link
Contributor

@hxrshxz hxrshxz commented Mar 8, 2026

I. Describe what this PR does

Migrate pkg/controllers/deploy tests 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 fmt
  • go test ./pkg/controllers/deploy/... -count=1
  • go test -race ./pkg/controllers/deploy/... -count=1
  • rg 'testify' pkg/controllers/deploy/*.go

V. Special notes for reviews

N/A

Copilot AI review requested due to automatic review settings March 8, 2026 01:54
@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Mar 8, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign ronggu for approval by writing /assign @ronggu in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Test Framework Migration: Migrated existing unit tests for pkg/controllers/deploy from the standard Go testing package to Ginkgo/Gomega, enhancing test readability and structure.
  • Deferred Precheck Discovery: Refactored the runtime controller precheck mechanism to defer the discovery and filtering of precheck functions until they are actually needed at runtime, rather than initializing them globally at startup.
  • Concurrency Safety: Introduced a sync.Mutex to protect access to the package-level precheck function map, ensuring thread-safe operations when setting or retrieving precheck functions.
  • Precheck Function Isolation: Implemented cloning mechanisms for precheck function maps to prevent external modifications from affecting the internal state and to ensure isolation between test runs.
  • Enhanced Test Coverage: Added comprehensive test cases covering various scenarios, including handling of missing deployments, replica annotation logic (defaulting to 1, respecting custom values, enforcing minimum 1 for 0), already-running controllers, no-match errors, and the isolation properties of precheck functions.
Changelog
  • pkg/controllers/deploy/runtime_controllers.go
    • Added sync package import for concurrency control.
    • Refactored precheck function management to use defaultPrecheckFuncs, resolveDefaultPrecheckFuncs, and a mutex-protected precheckFuncs.
    • Introduced getPrecheckFuncs and clonePrecheckFuncs to provide thread-safe and isolated access to precheck functions.
    • Updated ScaleoutRuntimeControllerOnDemand to utilize the new getPrecheckFuncs for retrieving runtime prechecks.
  • pkg/controllers/deploy/runtime_controllers_test.go
    • Rewrote all existing tests using the Ginkgo/Gomega testing framework.
    • Added new test cases to verify error handling for missing deployments, replica scaling logic based on annotations, and behavior for already-running controllers.
    • Included tests to confirm the isolation of package-global precheck functions and the non-pinning of discovery-filtered defaults.
    • Removed testing and logr imports, and added os, Ginkgo, Gomega, efc, thin, vineyard imports.
  • pkg/controllers/deploy/suite_test.go
    • Added a new file to set up the Ginkgo test suite for the deploy package.
Activity
  • The pull request was created to migrate tests and refactor precheck discovery logic.
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.

@fluid-e2e-bot
Copy link

fluid-e2e-bot bot commented Mar 8, 2026

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

Copy link
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 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.

Comment on lines +75 to +84
func getPrecheckFuncs() map[string]CheckFunc {
precheckFuncsMu.Lock()
defer precheckFuncsMu.Unlock()

if precheckFuncs != nil {
return clonePrecheckFuncs(precheckFuncs)
}

return clonePrecheckFuncs(resolveDefaultPrecheckFuncs())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.go to 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.

@hxrshxz hxrshxz force-pushed the fluid-pr-pkg-controllers-deploy branch from c2798ae to 4dc787f Compare March 8, 2026 01:57
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 8, 2026

@codecov
Copy link

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.21%. Comparing base (a69c888) to head (4dc787f).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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())
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return clonePrecheckFuncs(resolveDefaultPrecheckFuncs())
return resolveDefaultPrecheckFuncs()

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants