EvictionController: Add bounds checks for instance slice operations#283
EvictionController: Add bounds checks for instance slice operations#283
Conversation
Extract slice operations into helper functions (peekInstance, popInstance, moveToBack) with proper empty slice handling to prevent potential panics when accessing OutstandingInstances. Add unit tests for the helpers.
📝 WalkthroughWalkthroughThe pull request introduces three helper functions ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Merging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
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. Changed unit test files
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/controller/eviction_controller.go (1)
56-84: Clarify thatOutstandingInstancesis processed from the tail.These helpers all treat the last element as “next”, and
moveToBackthen rotates that element to index 0. A short comment here—or on theOutstandingInstancesfield—would make that ordering contract much harder to misuse in future call sites.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/controller/eviction_controller.go` around lines 56 - 84, The helper functions popInstance, peekInstance, and moveToBack treat the slice's last element as the "next" instance (tail-first processing) and moveToBack rotates that tail element to index 0 to deprioritize it; add a concise comment on the OutstandingInstances field (and/or above these functions) stating this ordering contract (i.e., "OutstandingInstances is processed from the tail: last element is next; moveToBack moves that element to the front to deprioritize") so future callers won't misuse the slice ordering.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/controller/eviction_controller.go`:
- Around line 56-84: The helper functions popInstance, peekInstance, and
moveToBack treat the slice's last element as the "next" instance (tail-first
processing) and moveToBack rotates that tail element to index 0 to deprioritize
it; add a concise comment on the OutstandingInstances field (and/or above these
functions) stating this ordering contract (i.e., "OutstandingInstances is
processed from the tail: last element is next; moveToBack moves that element to
the front to deprioritize") so future callers won't misuse the slice ordering.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ff7b853e-b5eb-42c2-90ba-ef9e09aaf82d
📒 Files selected for processing (2)
internal/controller/eviction_controller.gointernal/controller/eviction_controller_test.go
Extract slice operations into helper functions (peekInstance, popInstance,
moveToBack) with proper empty slice handling to prevent potential panics
when accessing OutstandingInstances. Add unit tests for the helpers.
Summary by CodeRabbit
Refactor
Tests