-
-
Notifications
You must be signed in to change notification settings - Fork 254
fix: use port range on free allocation lookup #1882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use port range on free allocation lookup #1882
Conversation
- Implemented `range_start` and `range_end` configuration to filter allocation ports. - Updated allocation creation logic to respect port range configuration.
📝 WalkthroughWalkthroughService reads allocation Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as FindAssignableAllocationService
participant DB as Allocations DB
participant Creator as createNewAllocation
Caller->>Caller: read config allocation.range_start / range_end\nAssert::integerish(start,end)
Caller->>DB: query allocations where server_id = X\nand whereBetween(port, [start,end])
alt allocation found
DB-->>Caller: return Allocation
else none found
Caller->>Creator: createNewAllocation(server, start, end)
Creator-->>DB: insert allocation with port in [start,end]
DB-->>Creator: return new Allocation
Creator-->>Caller: return Allocation
end
Possibly related PRs
Pre-merge checks✅ Passed checks (3 passed)
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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
This comment was marked as duplicate.
This comment was marked as duplicate.
✅ Actions performedReview triggered.
|
Simplify allocation saving and add $start and $end as parameters since they are now needed for the function to run Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/Services/Allocations/FindAssignableAllocationService.php(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-12T17:33:57.388Z
Learnt from: lancepioch
Repo: pelican-dev/panel PR: 1595
File: app/Services/Servers/ServerCreationService.php:182-184
Timestamp: 2025-08-12T17:33:57.388Z
Learning: In the Pelican Panel codebase, when updating allocations to assign them to servers, the preferred pattern is to use whereNull('server_id'), lockForUpdate(), and direct property assignment with save() rather than mass update methods, to prevent race conditions and mass-assignment issues while ensuring model events fire properly.
Applied to files:
app/Services/Allocations/FindAssignableAllocationService.php
🧬 Code graph analysis (1)
app/Services/Allocations/FindAssignableAllocationService.php (2)
app/Models/Server.php (4)
allocation(277-280)node(343-346)allocations(287-290)Server(132-516)app/Models/Allocation.php (3)
server(129-132)node(137-140)Allocation(48-141)
🔇 Additional comments (2)
app/Services/Allocations/FindAssignableAllocationService.php (2)
59-59: LGTM: Proper null coalescing assignment.The null coalescing assignment operator correctly falls back to creating a new allocation only when no existing allocation is found.
77-81: Good refactoring: Parameters moved to method signature.The refactoring to accept
$startand$endas parameters instead of reading config internally is cleaner and makes the method more testable. The null check at line 79 properly validates that the range is configured before attempting to create a new allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
tests/Integration/Services/Allocations/FindAssignableAllocationServiceTest.php (1)
32-38: LGTM! Changes correctly align test with range-based allocation logic.The updates ensure the test works with the new port range filtering:
- Configures a valid range (5000-5005)
- Creates an allocation with port 5005 (within range)
- Tests inclusive upper bound behavior
Optional refinement for consistency:
Consider adding an explicit port assertion for consistency with other tests (lines 64, 86):
$this->assertSame($created->id, $response->id); +$this->assertSame(5005, $response->port); $this->assertSame($server->allocation->ip, $response->ip);While the port is implicitly verified by the id match, an explicit assertion would make the test more self-documenting and consistent with the pattern used in
test_new_allocation_is_created_if_one_is_not_foundandtest_only_port_not_in_use_is_created.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/Integration/Services/Allocations/FindAssignableAllocationServiceTest.php(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-12T17:33:57.388Z
Learnt from: lancepioch
Repo: pelican-dev/panel PR: 1595
File: app/Services/Servers/ServerCreationService.php:182-184
Timestamp: 2025-08-12T17:33:57.388Z
Learning: In the Pelican Panel codebase, when updating allocations to assign them to servers, the preferred pattern is to use whereNull('server_id'), lockForUpdate(), and direct property assignment with save() rather than mass update methods, to prevent race conditions and mass-assignment issues while ensuring model events fire properly.
Applied to files:
tests/Integration/Services/Allocations/FindAssignableAllocationServiceTest.php
🧬 Code graph analysis (1)
tests/Integration/Services/Allocations/FindAssignableAllocationServiceTest.php (2)
app/Models/Allocation.php (1)
Allocation(48-141)app/Models/Server.php (1)
allocation(277-280)
Updated free allocation search logic to respect port range.
Supersedes #1852