fix(ec2): plan a VPC's CIDR against another Region's network for the same VPC id (#5134)

When planning a VPC's CIDR, Floci skips its own surviving Docker network
for that VPC so a restart does not read it as a collision. The match was
on the VPC id and owner only, but two Regions can hold a VPC with the same
id (the legacy vpc-default). Planning that id in one Region then skipped
the other Region's network, accepted an overlapping CIDR, and the Docker
network create failed, leaving instances without VPC connectivity. The
skip now also requires the network's Region label to match; every VPC
network has carried one since VPC networks were introduced.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-05 19:37:51 -04:00
1 parent a3118eb42b
commit 22ff93365e
2 files changed
+41 -10

No files matched your search

@@ -521,6 +521,33 @@ class VpcNetworkManagerTest {
assertEquals("10.0.0.0/16", manager.effectiveVpcCidr(REGION, "vpc-1").orElseThrow());
}
// Catches: planning a VPC skipping another Region's surviving network for a VPC with the same id,
// which then accepts an overlapping CIDR and fails when its own network is created.
@Test
void anotherRegionsNetworkForTheSameVpcIdIsStillACollision() {
Map<String, String> otherRegion = new LinkedHashMap<>(newLabels("vpc-default", "4650"));
otherRegion.put("io.floci.region", "eu-west-1");
existingNetwork(manager.networkName("eu-west-1", "vpc-default"), "10.0.0.0/16", otherRegion);
manager.declareVpc(REGION, "vpc-default", "10.0.0.0/16");
assertTrue(manager.isSubstituted(REGION, "vpc-default"),
"eu-west-1's network for vpc-default holds 10.0.0.0/16; us-east-1's vpc-default cannot reuse it");
assertNotEquals("10.0.0.0/16", manager.effectiveVpcCidr(REGION, "vpc-default").orElseThrow());
}
// The same rule through the labels a network carried before the io.floci.* keys.
@Test
void anotherRegionsLegacyNetworkForTheSameVpcIdIsStillACollision() {
Map<String, String> otherRegion = new LinkedHashMap<>(ourLabels("vpc-default", "4650"));
otherRegion.put("floci_vpc_region", "eu-west-1");
existingNetwork("floci-aws-vpc-4650-eu-west-1-vpc-default", "10.0.0.0/16", otherRegion);
manager.declareVpc(REGION, "vpc-default", "10.0.0.0/16");
assertTrue(manager.isSubstituted(REGION, "vpc-default"));
}
@Test
void createdNetworkCarriesTheIdentityLabelsAndTheirLegacyAliases() {
manager.declareVpc(REGION, "vpc-1", "10.0.0.0/16");