mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(ec2): list i386 alongside x86_64 for t2 instance types (#5815)
* fix(ec2): list i386 alongside x86_64 for t2 instance types * fix(ec2): map i386 AMIs to the linux/386 container platform t2 instance types now accept i386 images, but the resolver only mapped arm64 and x86_64, so an i386 catalog image started without a platform and ran as whatever the host defaults to. * fix(ec2): allow i386 images on t2.medium AWS lists t2.nano, t2.micro, t2.small and t2.medium as the t2 sizes that can run 32-bit AMIs; t2.medium was missing i386 so RunInstances refused an i386 image there. * test(ec2): share catalog image setup and drop duplicated t2 pin Extract serviceWithCatalogImage for the catalog image and resolver stubs used by the arm64 and i386 runInstances tests, and stop i386CatalogImageLaunchesOnTheLinux386Platform at the platform; the t2 sizes stay pinned in Ec2InstanceTypeCatalogTest.t2FamilySupportsI386AndX86_64.
This commit is contained in:
1 parent
050f93e600
commit
feafbfe083
5 files changed
+67
-12
No files matched your search
@@ -64,6 +64,7 @@ public class AmiImageResolver {
|
||||
return switch (architecture) {
|
||||
case "arm64" -> "linux/arm64";
|
||||
case "x86_64" -> "linux/amd64";
|
||||
case "i386" -> "linux/386";
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ instanceTypes:
|
||||
memoryMib: 512
|
||||
supportedArchitectures:
|
||||
- x86_64
|
||||
- i386
|
||||
currentGeneration: true
|
||||
encryptionInTransitSupported: false
|
||||
defaultNetworkCardIndex: 0
|
||||
@@ -17,6 +18,7 @@ instanceTypes:
|
||||
memoryMib: 1024
|
||||
supportedArchitectures:
|
||||
- x86_64
|
||||
- i386
|
||||
currentGeneration: true
|
||||
encryptionInTransitSupported: false
|
||||
defaultNetworkCardIndex: 0
|
||||
@@ -30,6 +32,7 @@ instanceTypes:
|
||||
memoryMib: 2048
|
||||
supportedArchitectures:
|
||||
- x86_64
|
||||
- i386
|
||||
currentGeneration: true
|
||||
encryptionInTransitSupported: false
|
||||
defaultNetworkCardIndex: 0
|
||||
@@ -43,6 +46,7 @@ instanceTypes:
|
||||
memoryMib: 4096
|
||||
supportedArchitectures:
|
||||
- x86_64
|
||||
- i386
|
||||
currentGeneration: true
|
||||
encryptionInTransitSupported: false
|
||||
defaultNetworkCardIndex: 0
|
||||
|
||||
+17
@@ -35,6 +35,23 @@ class Ec2ExternalImageCatalogTest {
|
||||
assertTrue(new Ec2ImageCatalog().findByIdOrAlias("ami-local-worker").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void i386CatalogImageLaunchesOnTheLinux386Platform() throws Exception {
|
||||
Path catalog = directory.resolve("i386.yaml");
|
||||
Files.writeString(catalog, """
|
||||
defaultDockerImage: example/base:1
|
||||
images:
|
||||
- imageId: ami-local-i386
|
||||
dockerImage: i386/alpine:3
|
||||
name: local-i386
|
||||
description: local i386
|
||||
architecture: i386
|
||||
creationDate: 2025-11-05T00:00:00.000Z
|
||||
""");
|
||||
AmiImageResolver resolver = new AmiImageResolver(new Ec2ImageCatalog(catalog));
|
||||
assertEquals("linux/386", resolver.resolveImage("ami-local-i386").dockerPlatform());
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingOrInvalidFileFailsInsteadOfSilentlyUsingBundledImages() throws Exception {
|
||||
assertThrows(IllegalStateException.class,
|
||||
|
||||
+14
-1
@@ -131,6 +131,20 @@ class Ec2InstanceTypeCatalogTest {
|
||||
assertTrue(error.getMessage().contains("maximumNetworkInterfaces"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void t2FamilySupportsI386AndX86_64() {
|
||||
for (String name : List.of("t2.nano", "t2.micro", "t2.small", "t2.medium")) {
|
||||
assertEquals(Set.of("i386", "x86_64"),
|
||||
Set.copyOf(instanceTypeCatalog.find(name).orElseThrow().supportedArchitectures), name);
|
||||
}
|
||||
// AWS's 32-bit-capable t2 list stops at medium
|
||||
for (String name : List.of("t2.large", "t2.xlarge", "t2.2xlarge")) {
|
||||
assertEquals(List.of("x86_64"), instanceTypeCatalog.find(name).orElseThrow().supportedArchitectures, name);
|
||||
}
|
||||
// launch-time default architecture must stay x86_64 (first entry)
|
||||
assertEquals("x86_64", instanceTypeCatalog.find("t2.micro").orElseThrow().supportedArchitectures.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void burstableFamiliesCarryTheirDocumentedDefaultCreditOption() {
|
||||
assertEquals(Optional.of("standard"), Ec2InstanceTypeCatalog.defaultCpuCredits("t2.micro"));
|
||||
@@ -162,7 +176,6 @@ class Ec2InstanceTypeCatalogTest {
|
||||
|
||||
assertEquals(vcpu, instanceType.vcpu, name);
|
||||
assertEquals(memoryMib, instanceType.memoryMib, name);
|
||||
assertEquals(List.of("x86_64"), instanceType.supportedArchitectures, name);
|
||||
assertEquals(ipv4PerInterface, instanceType.ipv4AddressesPerInterface, name);
|
||||
assertEquals(maxInterfaces, instanceType.networkCards.get(0).maximumNetworkInterfaces, name);
|
||||
assertTrue(instanceType.currentGeneration, name);
|
||||
|
||||
@@ -3378,18 +3378,9 @@ class Ec2ServiceTest {
|
||||
|
||||
@Test
|
||||
void runInstancesRejectsIncompatibleInstanceTypeForCreatedArmImage() {
|
||||
Ec2ImageCatalog catalog = mock(Ec2ImageCatalog.class);
|
||||
Ec2ImageCatalog.CatalogImage source = new Ec2ImageCatalog.CatalogImage();
|
||||
source.imageId = "ami-arm-source";
|
||||
source.architecture = "arm64";
|
||||
source.rootDeviceName = "/dev/xvda";
|
||||
when(catalog.findByIdOrAlias("ami-arm-source")).thenReturn(Optional.of(source));
|
||||
|
||||
AmiImageResolver resolver = mock(AmiImageResolver.class);
|
||||
when(resolver.resolveImage("ami-arm-source"))
|
||||
.thenReturn(new ResolvedAmiImage("arm-image", ResolvedAmiImage.DEFAULT_RUNTIME, false,
|
||||
"linux/arm64"));
|
||||
Ec2Service service = liveService(capturingContainerManager(), resolver, catalog);
|
||||
Ec2Service service = serviceWithCatalogImage(resolver, "ami-arm-source", "arm64", "arm-image",
|
||||
"linux/arm64");
|
||||
Reservation sourceReservation = service.runInstances("us-east-1", "ami-arm-source", "t4g.medium",
|
||||
1, 1, null, List.of(), null, null, List.of(), null, null);
|
||||
|
||||
@@ -3409,6 +3400,35 @@ class Ec2ServiceTest {
|
||||
assertEquals("arm64", compatible.getInstances().getFirst().getArchitecture());
|
||||
}
|
||||
|
||||
@Test
|
||||
void runInstancesAcceptsI386ImageOnT2MediumAndRefusesItOnT2Large() {
|
||||
Ec2Service service = serviceWithCatalogImage(mock(AmiImageResolver.class), "ami-i386", "i386",
|
||||
"i386/alpine:3", "linux/386");
|
||||
|
||||
Reservation medium = service.runInstances("us-east-1", "ami-i386", "t2.medium", 1, 1,
|
||||
null, List.of(), null, null, List.of(), null, null);
|
||||
assertEquals("i386", medium.getInstances().getFirst().getArchitecture());
|
||||
|
||||
AwsException error = assertThrows(AwsException.class,
|
||||
() -> service.runInstances("us-east-1", "ami-i386", "t2.large", 1, 1,
|
||||
null, List.of(), null, null, List.of(), null, null));
|
||||
assertEquals("InvalidParameterValue", error.getErrorCode());
|
||||
}
|
||||
|
||||
private Ec2Service serviceWithCatalogImage(AmiImageResolver resolver, String imageId, String architecture,
|
||||
String dockerImage, String dockerPlatform) {
|
||||
Ec2ImageCatalog catalog = mock(Ec2ImageCatalog.class);
|
||||
Ec2ImageCatalog.CatalogImage source = new Ec2ImageCatalog.CatalogImage();
|
||||
source.imageId = imageId;
|
||||
source.architecture = architecture;
|
||||
source.rootDeviceName = "/dev/xvda";
|
||||
when(catalog.findByIdOrAlias(imageId)).thenReturn(Optional.of(source));
|
||||
when(resolver.resolveImage(imageId))
|
||||
.thenReturn(new ResolvedAmiImage(dockerImage, ResolvedAmiImage.DEFAULT_RUNTIME, false,
|
||||
dockerPlatform));
|
||||
return liveService(capturingContainerManager(), resolver, catalog);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dryRunValidatesImagesBeforeReportingSuccess() {
|
||||
Ec2ContainerManager manager = mock(Ec2ContainerManager.class);
|
||||
|
||||
Reference in new issue
Block a user