Skip to content

Extract registerWithManager for testability#331

Merged
fwiesel merged 2 commits into
mainfrom
testable-controllers
Jul 9, 2026
Merged

Extract registerWithManager for testability#331
fwiesel merged 2 commits into
mainfrom
testable-controllers

Conversation

@fwiesel

@fwiesel fwiesel commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Split SetupWithManager into two methods for controllers with OpenStack dependencies:

  • registerWithManager handles only the controller-runtime registration
  • SetupWithManager acquires OpenStack clients, then delegates to registerWithManager

This allows integration tests to inject fake OpenStack clients and call registerWithManager directly, without needing real OpenStack credentials or cloud config.

Also adds a configurable requeueInterval to OnboardingController (defaults to 1m), so integration tests can use a shorter polling interval.

No behaviour change — purely structural refactoring for testability.

Summary by CodeRabbit

  • New Features

    • Added more flexible retry timing for onboarding and related reconciliation flows.
    • Improved flavor selection during onboarding so the system can pick a suitable test flavor more reliably.
  • Bug Fixes

    • Improved status updates for hypervisor onboarding to better reflect current progress.
    • Refined controller setup behavior to make reconciliation more reliable in different runtime scenarios.

Split SetupWithManager into two methods for controllers with OpenStack
dependencies: registerWithManager handles only the controller-runtime
registration, while SetupWithManager acquires OpenStack clients first
then delegates to registerWithManager. This allows integration tests
to inject fake OpenStack clients and call registerWithManager directly.

onboarding_controller is handled in a separate commit because it has
more moving parts (additional helpers, requeueInterval).
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@fwiesel, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3307dbc-7786-4475-93ad-4d4e5a3ad1f7

📥 Commits

Reviewing files that changed from the base of the PR and between 8569ee9 and e43ceab.

📒 Files selected for processing (1)
  • internal/controller/onboarding_controller.go
📝 Walkthrough

Walkthrough

Five controllers (Aggregates, Eviction, HypervisorMaintenance, Offboarding, Traits) had their manager registration logic extracted into new registerWithManager helper methods, called from SetupWithManager. The Onboarding controller also gained a configurable requeue interval, a test flavor discovery helper, and a status patch helper.

Changes

Controller registration helper extraction

Layer / File(s) Summary
Aggregates registration
internal/controller/aggregates_controller.go
registerWithManager registers the controller for Hypervisor with LifecycleEnabledPredicate; SetupWithManager delegates to it.
Eviction registration
internal/controller/eviction_controller.go
registerWithManager completes Eviction wiring; SetupWithManager initializes computeClient and microversion, then delegates.
Maintenance registration
internal/controller/hypervisor_maintenance_controller.go
registerWithManager reconciles Hypervisor and owns Eviction; SetupWithManager delegates to it.
Offboarding registration
internal/controller/offboarding_controller.go
registerWithManager reconciles Hypervisor; SetupWithManager initializes compute/placement clients, then delegates.
Traits registration
internal/controller/traits_controller.go
registerWithManager reconciles Hypervisor; SetupWithManager initializes the placement client, then delegates.

Onboarding controller updates

Layer / File(s) Summary
Configurable requeue interval
internal/controller/onboarding_controller.go
Adds requeueInterval field and getRequeueInterval() fallback to defaultWaitTime; updates Reconcile, smokeTest, and completeOnboarding requeue paths to use it.
Flavor discovery, status patch, and registration
internal/controller/onboarding_controller.go
Adds flavors client import, findTestFlavor for flavor selection, patchStatus for status patching, and registerWithManager used by SetupWithManager.

Estimated code review effort: 2 (Simple) | ~15 minutes

Suggested reviewers: mchristianl, soofff

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title clearly captures the main refactor: extracting registerWithManager to improve testability.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch testable-controllers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…e interval

Extract registerWithManager from SetupWithManager and add a configurable
requeueInterval field (defaults to 1m via getRequeueInterval). Integration
tests set requeueInterval to 1s, reducing test runtime from minutes to
seconds.
@fwiesel fwiesel force-pushed the testable-controllers branch from 8569ee9 to e43ceab Compare July 9, 2026 08:03
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller 68.91% (-0.43%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/aggregates_controller.go 84.62% (-1.32%) 65 (+1) 55 10 (+1) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/eviction_controller.go 61.21% (-0.37%) 165 (+1) 101 64 (+1) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/hypervisor_maintenance_controller.go 78.41% (-0.90%) 88 (+1) 69 19 (+1) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/offboarding_controller.go 72.86% (-1.06%) 70 (+1) 51 19 (+1) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/onboarding_controller.go 55.06% (-0.08%) 247 (+4) 136 (+2) 111 (+2) 👎
github.com/cobaltcore-dev/openstack-hypervisor-operator/internal/controller/traits_controller.go 73.44% (-1.17%) 64 (+1) 47 17 (+1) 👎

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

@fwiesel fwiesel merged commit 14a4933 into main Jul 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants