Skip to content

SPLAT-2238: Redesign logic to handle 4 pools with 3 max vcenters - #69

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift-eng:mainfrom
vr4manta:SPLAT-2238_fix3
Jul 13, 2026
Merged

SPLAT-2238: Redesign logic to handle 4 pools with 3 max vcenters#69
openshift-merge-bot[bot] merged 1 commit into
openshift-eng:mainfrom
vr4manta:SPLAT-2238_fix3

Conversation

@vr4manta

@vr4manta vr4manta commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

SPLAT-2238

Changes

  • Redesign logic to handle 4 pools with 3 max vcenters

Summary by CodeRabbit

  • New Features

    • Lease handling now uses smarter vCenter-aware filtering to better choose available pools as capacity gets tight.
  • Bug Fixes

    • Improved behavior when vCenter limits block progress: leases now reset unavailable pool assignments and report a clearer pending state instead of getting stuck.
    • Better distinguishes between true pool shortages and vCenter-capacity constraints for more reliable recovery.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 8, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 8, 2026

Copy link
Copy Markdown

@vr4manta: This pull request references SPLAT-2238 which is a valid jira issue.

Details

In response to this:

SPLAT-2238

Changes

  • Redesign logic to handle 4 pools with 3 max vcenters

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from mtulio and rvanderp3 July 8, 2026 19:41
@openshift-ci

openshift-ci Bot commented Jul 8, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vr4manta

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

The pull request process is described 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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.

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: Repository: openshift-eng/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: fafdd920-06ce-4970-8239-332ffba35401

📥 Commits

Reviewing files that changed from the base of the PR and between 75d7776 and c92fb9c.

📒 Files selected for processing (3)
  • pkg/controller/dynamic_filtering_test.go
  • pkg/controller/leases.go
  • pkg/controller/leases_vcenter_cap_stuck_test.go

Walkthrough

This PR adds vCenter-cap-aware dynamic filtering to lease pool assignment in the controller: it computes remaining vCenter slots and pools, excludes vCenters below a computed minimum-pools threshold via a fitting-pools calculation, and introduces recovery logic (releasing pool owner references, updating lease conditions, requeueing) when pool assignment stalls due to vCenter cap constraints. Two new test files validate the filtering and stuck scenarios.

Changes

Dynamic vCenter Filtering

Layer / File(s) Summary
Cap-aware filtering and stuck recovery
pkg/controller/leases.go
Adds remaining vCenter slot/pool bookkeeping, dynamic exclusion of vCenters below a computed minPoolsPerVCenter threshold using utils.GetFittingPools, and stuck-recovery handling that removes Pool owner references, sets a not-fulfilled condition, updates status/metrics, and requeues when vCenter cap constraints block pool selection.
Filtering and stuck-scenario tests
pkg/controller/dynamic_filtering_test.go, pkg/controller/leases_vcenter_cap_stuck_test.go
Adds TestDynamicVCenterFiltering with a createPool helper simulating cap-reached and dynamic exclusion scenarios, and TestVCenterCapStuckScenario simulating pool-fitting calculations and a stuck-lease scenario across subtests.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested reviewers: mtulio


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
No-Sensitive-Data-In-Logs ❌ Error New test logs print real vCenter hostnames, and controller logs pool/lease names that can expose internal infra details. Redact hostnames and object names from logs; log counts/IDs only or sanitize them before printing.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: redesigning vCenter pool assignment logic for 4 pools with a 3-vCenter cap.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
No-Weak-Crypto ✅ Passed Touched files add vCenter filtering/recovery tests and lease logic; no MD5/SHA1/DES/RC4/3DES/Blowfish/ECB, custom crypto, or secret comparisons found.
Container-Privileges ✅ Passed PR only changes three Go files; diff search found no privileged, hostPID/network/IPC, SYS_ADMIN, or allowPrivilegeEscalation settings.
No-Hardcoded-Secrets ✅ Passed No added hardcoded secrets, credentialed URLs, or suspicious secret literals were found in the changed files.
No-Injection-Vectors ✅ Passed Changed Go code only adds vCenter filtering/recovery logic and tests; no SQL concat, shell, eval/exec, pickle/yaml loads, os.system, or dangerous HTML sinks found.
Ai-Attribution ✅ Passed PR commit 75d7776 has no AI-tool mention or attribution trailer; no Assisted-by/Generated-by required.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
pkg/controller/leases_vcenter_cap_stuck_test.go (1)

1-352: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add meaningful assertions — the test is mostly logging with no verification.

The test sets up realistic production data and describes the stuck scenario well, but nearly all subtests only call t.Logf without asserting outcomes. The sole assertion (lines 194–196) just checks that vcenter-1 has ≥ 1 pool. The "simulates getting stuck scenario" subtest (lines 234–337) describes the deadlock but doesn't verify that the recovery actually releases pools, updates conditions, or requeues.

Consider asserting: which vCenters can/cannot fit the lease, that dynamic filtering produces the expected minPoolsPerVCenter, and that the stuck condition (cap reached + no fitting pools on in-use vCenters) is correctly detected.

♻️ Example: add assertions to the "approaching cap" subtest
 		t.Logf("Remaining slots: %d, Remaining pools: %d, Min pools per vCenter: %d",
 			remainingSlots, remainingPools, minPoolsPerVCenter)
 
-		// Dynamic filtering: must pick a vCenter with >= 2 pools available
-		// Based on our pool counts:
-		// - vcenter-120: can provide 4 pools → ALLOWED ✓
-		// - vcenter cicluster-1: can provide 2 pools → ALLOWED ✓
-		// - vcenter cicluster-2: can provide 2 pools → ALLOWED ✓
-		// - vcenter cicluster: can provide 6 pools → ALLOWED ✓
-
-		// All remaining vCenters can provide >= 2 pools, so none should be excluded
-		// This is good - the algorithm should work
+		// Verify minPoolsPerVCenter calculation
+		if minPoolsPerVCenter != 2 {
+			t.Errorf("Expected minPoolsPerVCenter=2, got %d", minPoolsPerVCenter)
+		}
+
+		// Verify all remaining vCenters have >= minPoolsPerVCenter fitting pools
+		fittingPools, _ := utils.GetFittingPools(lease, pools[2:], nil)
+		poolsPerVCenter := make(map[string]int)
+		for _, p := range fittingPools {
+			if !vcentersInUse[p.Spec.Server] {
+				poolsPerVCenter[p.Spec.Server]++
+			}
+		}
+		for server, count := range poolsPerVCenter {
+			if count < minPoolsPerVCenter {
+				t.Errorf("vCenter %s has %d pools, expected >= %d", server, count, minPoolsPerVCenter)
+			}
+		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/controller/leases_vcenter_cap_stuck_test.go` around lines 1 - 352, The
test is mostly logging and does not verify the stuck-lease behavior, so add real
assertions in TestVCenterCapStuckScenario and its subtests. Use the existing
pool/lease setup and helper logic around poolsPerVCenter, assignedPools, and
minPoolsPerVCenter to assert which vCenters can or cannot fit the lease, that
the computed minimum pools per vCenter is correct, and that the simulated
deadlock state is detected rather than only printed. In the "simulates getting
stuck scenario" path, assert the expected recovery outcome (release/retry or
equivalent condition change) instead of just logging the scenario.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/controller/leases.go`:
- Around line 954-955: The stuck-recovery path in leases.go only checks
`len(vcentersInUse) >= lease.Spec.VCenters`, so it misses the case where dynamic
filtering in `GetPoolWithStrategy` excludes all remaining vCenters before the
cap is reached. Update the recovery condition around the existing “cap reached
or approaching cap” check so it also triggers when filtering removed candidates
and no pool was found, using the relevant state from the filtering/selection
logic in `GetPoolWithStrategy` and the lease reconciliation path. This should
prevent falling through to the PARTIAL/break path and requeueing into the same
dead end.
- Around line 959-982: The lease release flow in the controller needs to persist
the OwnerReferences change separately from the status update. In the lease
handling logic where lease.OwnerReferences is filtered and conditions.Set is
used, first call a normal Update on the lease so the metadata change is saved,
then call Status().Update for the Fulfilled/ReasonLeaseNoPool condition, and
make sure any update error is returned rather than only logged.

---

Nitpick comments:
In `@pkg/controller/leases_vcenter_cap_stuck_test.go`:
- Around line 1-352: The test is mostly logging and does not verify the
stuck-lease behavior, so add real assertions in TestVCenterCapStuckScenario and
its subtests. Use the existing pool/lease setup and helper logic around
poolsPerVCenter, assignedPools, and minPoolsPerVCenter to assert which vCenters
can or cannot fit the lease, that the computed minimum pools per vCenter is
correct, and that the simulated deadlock state is detected rather than only
printed. In the "simulates getting stuck scenario" path, assert the expected
recovery outcome (release/retry or equivalent condition change) instead of just
logging the scenario.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: openshift-eng/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2b1ac0fa-a9de-45da-b3de-49e4c4a20873

📥 Commits

Reviewing files that changed from the base of the PR and between f8f02f2 and 75d7776.

📒 Files selected for processing (3)
  • pkg/controller/dynamic_filtering_test.go
  • pkg/controller/leases.go
  • pkg/controller/leases_vcenter_cap_stuck_test.go

Comment thread pkg/controller/leases.go Outdated
Comment thread pkg/controller/leases.go Outdated
Comment thread pkg/controller/leases.go
lease.OwnerReferences = newOwnerRefs

// Reset to PENDING
conditions.Set(lease, conditions.FalseConditionWithReason(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

how many times around will we go around before we reset the condition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the idea here is that we move lease back to pending and return. next reconcile loop will attempt again. this way if logic is still broke, we have a chance of the other pools getting resources to allow it to be fulfilled. If this is bad, i can change back.

@jcpowermac

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 13, 2026
@openshift-merge-bot
openshift-merge-bot Bot merged commit f0ae388 into openshift-eng:main Jul 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants