IFC-2555: Fix prefix pool duplication#9299
Conversation
There was a problem hiding this comment.
No issues found across 5 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. This PR modifies core IPAM allocation logic and database queries (changing comparison operators and adding uuid filters), which has a high blast radius on network prefix allocation correctness; despite comprehensive tests, such critical business logic changes require a human reviewer's judgment.
Re-trigger cubic
| self.obj = obj | ||
| self.target_prefixlen = target_prefixlen | ||
| self.namespace_id = _get_namespace_id(namespace) | ||
| self.parent_uuid = parent_uuid |
There was a problem hiding this comment.
is it possible to use obj instead of adding the parent_uuid parameter to do the same thing?
There was a problem hiding this comment.
I did this tests locally that passed and I think it would be worth adding, or maybe replacing the tests with it
- start with a resource pool that includes two /30 prefixes. provision a /31 (success), provision a /30 (success), provision another /30 (failure), provision another /31 (success)
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Shadow auto-approve: would require human review. This change modifies a core IPAM query condition (av.prefixlen > to >=) and adds an exclusion filter, which affects prefix pool allocation logic for both IPv4 and IPv6; while the fix is well-tested, it touches critical business logic where a subtle bug could cause data integrity issues, so...
Re-trigger cubic
| # obj is an IPNetworkType (Python network object); parent_uuid is the database UUID of | ||
| # the pool-resource node. They represent different things and cannot substitute each other. |
There was a problem hiding this comment.
I don't think this comment is necessary
| target_prefixlen: int, | ||
| namespace: Node | str | None = None, | ||
| # obj is an IPNetworkType (Python network object); parent_uuid is the database UUID of | ||
| # the pool-resource node. They represent different things and cannot substitute each other. |
Why
When a prefix pool's resource prefix has the same length as the requested allocation size (e.g., allocating
/30subnets from a/30parent), the pool returns the same prefix on every request instead of signalling exhaustion. This causes generators to silently produce duplicate IP allocations, resulting in routing failures.Root cause:
IPPrefixSubnetFetchFreeandIPv6PrefixSubnetFetchFreefilter occupied child ranges withav.prefixlen > $maxprefixlen(strict greater-than). When the allocated child hasprefixlen == parent.prefixlen, the condition30 > 30is false — the child is invisible to subsequent queries, which then return the samefree_startagain.Closes opsmill/infrahub-sdk-python#981
How to test
Checklist
changelog/+fix-prefix-pool-dup.fixed.md)Summary by cubic
Fixes duplicate allocations from prefix pools when the pool resource has the same prefix length as the requested size. Pools now allocate once and then correctly signal exhaustion (IPv4 and IPv6), addressing IFC-2555’s “no more resource available” expectation.
prefixlen >= maxprefixlen(was>), for IPv4 and IPv6 queries.pfx.uuid <> $exclude_uuid.parent_uuidthrough the allocator to the IPAM queries.Written for commit a27694a. Summary will update on new commits. Review in cubic