Repository navigation
network: scope routed network/VPC subnets to a zone - #14421
prashanthr2 wants to merge 2 commits into
Conversation
The ip4_guest_subnet_network_map table had no zone column, so the subnet bookkeeping for routed networks and VPCs was global. Creating a routed VPC or network with a CIDR already used in another zone failed with "The subnet is in use", even though the two zones are independent. Add a nullable data_center_id column to ip4_guest_subnet_network_map and scope the subnet lookup and the parentless overlap check by zone, so the same CIDR can be used once per zone. Existing rows are backfilled from their parent zone subnet, VPC or network. Fixes apache#14419 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017rnv8vT6LQSKfwkzp8tvg9
weizhouapache
left a comment
There was a problem hiding this comment.
lgtm
the SQL may be applied to 423to24.sql too
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.22 #14421 +/- ##
============================================
- Coverage 18.03% 18.02% -0.01%
+ Complexity 16286 16282 -4
============================================
Files 5937 5937
Lines 536771 536782 +11
Branches 65782 65782
============================================
- Hits 96787 96762 -25
- Misses 428932 428968 +36
Partials 11052 11052
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| private Long parentId; | ||
|
|
||
| @Column(name = "data_center_id") | ||
| private Long dataCenterId; |
There was a problem hiding this comment.
should listing subnets by zone use this column too? right now it only matches through the zone subnet, so ones made without a zone subnet dont show up when you filter by zone
There was a problem hiding this comment.
Good catch, thanks @Damans227 and it’s a bit worse than parentless rows. The zoneid filter resolves the zone through dc_ip4_guest_subnets:
List<DataCenterIpv4GuestSubnetVO> subnets = dataCenterIpv4GuestSubnetDao.listByDataCenterId(zoneId);
if (CollectionUtils.isEmpty(subnets)) {
return new ArrayList<>();
}
sc.addAnd("parentId", SearchCriteria.Op.IN, parentIds.toArray());
So if the zone has no zone-level subnet configured at all, the list returns empty even when routed VPCs exist there , which is exactly the setup in #14419. createIpv4SubnetForGuestNetworkResponse has the same gap: zoneId is only derived from the network, VPC or parent, so a parentless unassigned row reports no zone.
Now that the row carries the zone, I’ll replace the parent-id lookup with a direct data_center_id filter and add it as a fallback in the response (that needs getDataCenterId() on the Ipv4GuestSubnetNetworkMap interface). Rows that predate the upgrade and can’t be attributed to a zone keep data_center_id = NULL and still won’t show under a zone filter same as today, so no regression. Pushing shortly.
There was a problem hiding this comment.
Pushed in d98069c , filter now uses data_center_id, and the response falls back to it for parentless subnets.
|
@blueorangutan package |
|
@vladimirpetrov a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19588 |
@weizhouapache Agreed. schema-42300to2400.sql only exists on main, so I can’t add it here , do you want me to raise a separate PR against main for it or will it be picked up in the forward-merge? |
listIpv4SubnetsForGuestNetwork resolved the zoneid filter through dc_ip4_guest_subnets, so a subnet with no parent never matched, and a zone with no zone-level subnet returned an empty list. The response derived the zone the same way, leaving parentless subnets with no zone at all. Now that the record carries its zone, filter on data_center_id directly and fall back to it when building the response. Addresses review feedback on apache#14419. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017rnv8vT6LQSKfwkzp8tvg9
Damans227
left a comment
There was a problem hiding this comment.
thanks @prashanthr2, fix looks right. LGTM
Description
Fixes #14419.
ip4_guest_subnet_network_maphas no zone column, so the subnet bookkeeping for routed networks and VPCs is global. Creating a routed VPC or network with a CIDR that is already used in another zone fails withThe subnet is in use, even though the two zones are independent.This adds a nullable
data_center_idto the table and scopes both the subnet lookup (findBySubnetAndDataCenterId) and the parentless overlap check (listAllNoParentByDataCenterId) by zone, so the same CIDR can be used once per zone. Existing rows are backfilled from their parent zone subnet, their VPC'szone_id, or their network'sdata_center_id.Notes for reviewers:
ON DELETE CASCADEbecauseIDEMPOTENT_ADD_FOREIGN_KEYhardcodes it. That matchesnetworks,vpc,user_ip_addressand most of the schema, though the sibling tabledc_ip4_guest_subnetsuses a plain FK.data_center_id = NULL. Those are leftovers from failed network/VPC creates (state = Free, unreferenced) and no longer take part in any zone's overlap check, which is the intended direction.Types of changes
Feature/Enhancement Scale or Bug Severity
Bug Severity
How Has This Been Tested?
Unit tests in
RoutedIpv4ManagerImplTestupdated for the new DAO signatures, plus a newtestGetOrCreateIpv4SubnetForGuestNetworkOrVpcInternalByCidrInAnotherZonecovering the cross-zone case.Manual: create a routed VPC with
10.0.0.0/8in zone 1, then a second routed VPC with the same CIDR in zone 2. Before this change the second create fails with "The subnet is in use"; after it, both succeed and each row inip4_guest_subnet_network_mapcarries its owndata_center_id.🤖 Generated with Claude Code
https://claude.ai/code/session_017rnv8vT6LQSKfwkzp8tvg9