mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 18:18:02 -05:00
fix(ec2): select the subnet VPC default security group (#7762)
Use the existing VPC-specific default-group lookup for instance launch, with service and SDK placement regressions and documentation. Source: AndreKurait/floci#524 (94f76eae34e46dc1e740b6349bbaed578a15e372). Remove the obsolete regional resolver and its dedicated test assertions now that instance launch uses the VPC-specific lookup. Keep legacy VPC resolution coverage and remove its unused security-group fixture. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
9f77c736e9
commit
068740794a
4 files changed
+80
-41
No files matched your search
@@ -270,6 +270,23 @@ class Ec2ServiceTest {
|
||||
eni.getGroups().stream().map(GroupIdentifier::getGroupId).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void runInstancesWithoutGroupsGetsItsSubnetVpcsDefaultGroup() {
|
||||
Ec2Service service = mockModeService();
|
||||
String region = "us-east-1";
|
||||
String vpcId = service.createVpc(region, "10.94.0.0/16", false).getVpcId();
|
||||
Subnet subnet = service.createSubnet(region, vpcId, "10.94.1.0/24", region + "a");
|
||||
|
||||
Instance instance = service.runInstances(region, "ami-test", "t3.micro", 1, 1, null,
|
||||
List.of(), subnet.getSubnetId(), null, List.of(), null, null).getInstances().getFirst();
|
||||
|
||||
List<String> expected = List.of(service.defaultSecurityGroupOf(region, vpcId).orElseThrow().getGroupId());
|
||||
assertEquals(vpcId, instance.getVpcId());
|
||||
assertEquals(expected, instance.getSecurityGroups().stream().map(GroupIdentifier::getGroupId).toList());
|
||||
assertEquals(expected, instance.getNetworkInterfaces().getFirst().getGroups().stream()
|
||||
.map(GroupIdentifier::getGroupId).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultSecurityGroupOfIsEmptyOnceTheDefaultGroupIsGone() {
|
||||
Ec2Service service = mockModeService();
|
||||
@@ -4126,12 +4143,8 @@ class Ec2ServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveDefaultVpcAndSecurityGroupIdFallBackToPreRegionScopingStorage() throws Exception {
|
||||
// #21 follow-up: persistent storage written before default ids were made region-scoped
|
||||
// still carries the old literal "vpc-default"/"sg-default", never the new scoped form, and
|
||||
// nothing re-seeds it (ensureDefaultResources skips a region that already has a VPC on
|
||||
// file). Any lookup that blindly computed the new scoped id instead of resolving against
|
||||
// what's actually stored would silently stop finding the region's real default VPC/SG.
|
||||
void resolveDefaultVpcIdFallsBackToPreRegionScopingStorage() throws Exception {
|
||||
// Existing regions are not re-seeded, so persisted VPCs can still have the old unscoped id.
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
mock(AmiImageResolver.class), mock(Ec2ImageCatalog.class), new Ec2InstanceTypeCatalog(),
|
||||
@@ -4146,29 +4159,16 @@ class Ec2ServiceTest {
|
||||
legacyVpc.setRegion("us-east-1");
|
||||
putViaReflection(service, "vpcs", "us-east-1::vpc-default", legacyVpc);
|
||||
|
||||
SecurityGroup legacySg = new SecurityGroup();
|
||||
legacySg.setGroupId("sg-default");
|
||||
legacySg.setGroupName("default");
|
||||
legacySg.setDescription("default VPC security group");
|
||||
legacySg.setVpcId("vpc-default");
|
||||
legacySg.setOwnerId("000000000000");
|
||||
legacySg.setRegion("us-east-1");
|
||||
putViaReflection(service, "securityGroups", "us-east-1::sg-default", legacySg);
|
||||
|
||||
assertEquals("vpc-default", service.resolveDefaultVpcId("us-east-1"),
|
||||
"must resolve the pre-existing unscoped default VPC, not compute a fresh scoped id");
|
||||
assertEquals("sg-default", service.resolveDefaultSecurityGroupId("us-east-1"),
|
||||
"must resolve the pre-existing unscoped default security group, not compute a fresh scoped id");
|
||||
|
||||
SecurityGroup created = service.createSecurityGroup("us-east-1", "app", "app sg", null);
|
||||
assertEquals("vpc-default", created.getVpcId(),
|
||||
"a new security group with no explicit VpcId must attach to the real default VPC on file");
|
||||
|
||||
// A genuinely fresh region has neither format on file, so both resolvers fall back to the
|
||||
// A genuinely fresh region has neither format on file, so the resolver falls back to the
|
||||
// scoped form ensureDefaultResources would seed.
|
||||
assertEquals(Ec2Service.defaultVpcId("eu-west-1"), service.resolveDefaultVpcId("eu-west-1"));
|
||||
assertEquals(Ec2Service.defaultSecurityGroupId("eu-west-1"),
|
||||
service.resolveDefaultSecurityGroupId("eu-west-1"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Reference in new issue
Block a user