mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(ec2): ignore NoDevice block device mappings at launch (#5739)
A RunInstances or CreateFleet BlockDeviceMapping with NoDevice set removes its device regardless of the other values it carries. The root volume type resolution and the VolumeType validation read Ebs on such entries, so a request that removed a template's gp3 root still got gp3, and a removed mapping naming an unknown VolumeType failed with InvalidParameterValue. Drop NoDevice entries before both, on the request-only and template-merged paths alike.
This commit is contained in:
1 parent
0eee5ee28d
commit
5544a119d3
3 files changed
+41
-7
No files matched your search
@@ -683,7 +683,8 @@ members it sets, and the rest keep the template's values; devices only one side
|
||||
given. An Auto Scaling group launching from a template gets the template's mappings the same
|
||||
way. The root volume's type comes from the mapping for the AMI's root device, else from the
|
||||
AMI's own root mapping, else `gp3`, and `CreateImage` records that type on the new AMI's root
|
||||
mapping. A mapping naming a `VolumeType` outside the service model's enum fails with
|
||||
mapping. A mapping with `NoDevice` set removes its device whatever else it names, so it sets no
|
||||
type and its `VolumeType` is not checked. A mapping naming a `VolumeType` outside the service model's enum fails with
|
||||
`InvalidParameterValue`, as `ModifyVolume` does. Template versions are not checked when they are
|
||||
stored, so a template naming an unknown `VolumeType` is accepted by `CreateLaunchTemplate` and
|
||||
fails at launch.
|
||||
|
||||
@@ -3359,12 +3359,13 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
validateArchitectureCompatibility(region, imageId, effectiveInstanceType);
|
||||
int count = Math.min(maxCount, Math.max(minCount, 1));
|
||||
String architecture = architectureFor(region, imageId, effectiveInstanceType);
|
||||
if (blockDeviceMappings != null) {
|
||||
blockDeviceMappings.stream()
|
||||
.filter(m -> m.getEbs() != null && m.getEbs().getVolumeType() != null)
|
||||
.forEach(m -> requireValidVolumeType(m.getEbs().getVolumeType()));
|
||||
}
|
||||
String rootVolumeType = rootVolumeTypeFor(findImageForCapture(region, imageId), blockDeviceMappings);
|
||||
// An entry with NoDevice set removes its device whatever else it names, as on AWS.
|
||||
List<LaunchTemplateData.BlockDeviceMapping> mappedDevices = blockDeviceMappings == null ? List.of()
|
||||
: blockDeviceMappings.stream().filter(m -> m.getNoDevice() == null).toList();
|
||||
mappedDevices.stream()
|
||||
.filter(m -> m.getEbs() != null && m.getEbs().getVolumeType() != null)
|
||||
.forEach(m -> requireValidVolumeType(m.getEbs().getVolumeType()));
|
||||
String rootVolumeType = rootVolumeTypeFor(findImageForCapture(region, imageId), mappedDevices);
|
||||
List<Instance> launched = new ArrayList<>();
|
||||
// Resolving the AMI, building the instances that depend on it and publishing them is one
|
||||
// step. A DeregisterImage releases the captured layer only when no live instance resolves
|
||||
|
||||
@@ -5778,6 +5778,38 @@ class Ec2IntegrationTest {
|
||||
.body(containsString("Value (gp9) for parameter volumeType is invalid. Unknown volume type."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(335)
|
||||
void runInstancesNoDeviceRootMappingFallsBackToAmiRootVolumeType() {
|
||||
String templateId = given()
|
||||
.formParam("Action", "CreateLaunchTemplate")
|
||||
.formParam("LaunchTemplateName", "gp3-root-nodevice-template")
|
||||
.formParam("LaunchTemplateData.BlockDeviceMapping.1.DeviceName", "/dev/xvda")
|
||||
.formParam("LaunchTemplateData.BlockDeviceMapping.1.Ebs.VolumeType", "gp3")
|
||||
.header("Authorization", AUTH_HEADER)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("CreateLaunchTemplateResponse.launchTemplate.launchTemplateId");
|
||||
|
||||
// NoDevice removes the template's root mapping, so the AMI's gp2 root applies.
|
||||
assertEquals("gp2", rootVolumeType(launch(Map.of(
|
||||
"LaunchTemplate.LaunchTemplateId", templateId,
|
||||
"BlockDeviceMapping.1.DeviceName", "/dev/xvda",
|
||||
"BlockDeviceMapping.1.NoDevice", ""))));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(336)
|
||||
void runInstancesIgnoresVolumeTypeOnANoDeviceMapping() {
|
||||
// The device is removed regardless of the assigned value, so gp9 is never validated.
|
||||
assertEquals("gp2", rootVolumeType(launch(Map.of(
|
||||
"BlockDeviceMapping.1.DeviceName", "/dev/xvda",
|
||||
"BlockDeviceMapping.1.NoDevice", "",
|
||||
"BlockDeviceMapping.1.Ebs.VolumeType", "gp9"))));
|
||||
}
|
||||
|
||||
private String launch(Map<String, String> params) {
|
||||
return given()
|
||||
.formParam("Action", "RunInstances")
|
||||
|
||||
Reference in new issue
Block a user