mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): return a catalog image under the alias DescribeImages was asked for (#9817)
DescribeImages --image-ids <alias> now returns the catalog image under the ID that was requested, instead of the entry's own ID, once per requested ID. A listing without ImageId.N is unchanged.
This commit is contained in:
1 parent
85a8cf0a96
commit
d655a7e2ca
2 files changed
+47
-1
No files matched your search
@@ -10140,7 +10140,7 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
// matching still runs on the materialized image so AWS aliases such as amazon/self
|
||||
// are resolved against the real owner account id consistently with registered images.
|
||||
.filter(img -> matchesImageFilters(img, filters))
|
||||
.map(Ec2ImageCatalog.CatalogImage::toImage)
|
||||
.flatMap(img -> catalogImagesUnderRequestedIds(img, imageIds))
|
||||
.filter(img -> matchesImageOwners(img, owners))
|
||||
.collect(Collectors.toList());
|
||||
List<Image> createdImages = registeredImages.scan(k -> true).stream()
|
||||
@@ -10159,6 +10159,25 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider, Resettab
|
||||
return images;
|
||||
}
|
||||
|
||||
// A caller that names an image looks for that id in the answer (the aws provider reports
|
||||
// "couldn't find resource" otherwise), so a catalog entry reached through an alias is returned
|
||||
// under the alias, once per requested id. An unfiltered listing keeps the entry's own id.
|
||||
private Stream<Image> catalogImagesUnderRequestedIds(Ec2ImageCatalog.CatalogImage catalogImage,
|
||||
List<String> imageIds) {
|
||||
if (imageIds == null || imageIds.isEmpty()) {
|
||||
return Stream.of(catalogImage.toImage());
|
||||
}
|
||||
List<String> idsAndAliases = catalogImage.idsAndAliases();
|
||||
return imageIds.stream()
|
||||
.distinct()
|
||||
.filter(idsAndAliases::contains)
|
||||
.map(requestedId -> {
|
||||
Image image = catalogImage.toImage();
|
||||
image.setImageId(requestedId);
|
||||
return image;
|
||||
});
|
||||
}
|
||||
|
||||
// RunInstances launches an unrecognised AMI id by falling back to the catalog default image (see
|
||||
// AmiImageResolver), so an explicitly requested but unknown id is still launchable. IaC providers read
|
||||
// the AMI's root device via DescribeImages before RunInstances, so an empty result there aborts the
|
||||
|
||||
@@ -4607,6 +4607,33 @@ class Ec2ServiceTest {
|
||||
assertEquals("ami-0abcdef1234567890", images.getFirst().getImageId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeImagesReturnsCatalogImageUnderRequestedAlias() {
|
||||
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
|
||||
Ec2Service service = new Ec2Service(mockConfig(true), mock(Ec2ContainerManager.class),
|
||||
mock(Ec2PortForwardManager.class),
|
||||
new AmiImageResolver(imageCatalog), imageCatalog, new Ec2InstanceTypeCatalog(),
|
||||
new InMemoryStorageFactory());
|
||||
|
||||
List<Image> byAlias = service.describeImages("us-east-1", List.of("ami-ubuntu2004"), List.of());
|
||||
assertEquals(1, byAlias.size());
|
||||
assertEquals("ami-ubuntu2004", byAlias.getFirst().getImageId());
|
||||
|
||||
List<Image> byId = service.describeImages("us-east-1", List.of("ami-0abcdef1234567892"), List.of());
|
||||
assertEquals(1, byId.size());
|
||||
assertEquals("ami-0abcdef1234567892", byId.getFirst().getImageId());
|
||||
assertEquals(byId.getFirst().getName(), byAlias.getFirst().getName());
|
||||
|
||||
List<String> both = service.describeImages(
|
||||
"us-east-1", List.of("ami-ubuntu2004", "ami-0abcdef1234567892"), List.of()).stream()
|
||||
.map(Image::getImageId)
|
||||
.toList();
|
||||
assertEquals(List.of("ami-ubuntu2004", "ami-0abcdef1234567892"), both);
|
||||
|
||||
assertTrue(service.describeImages("us-east-1", List.of(), List.of()).stream()
|
||||
.noneMatch(image -> "ami-ubuntu2004".equals(image.getImageId())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeImagesResolvesUnknownLaunchableAmiId() {
|
||||
Ec2ImageCatalog imageCatalog = new Ec2ImageCatalog();
|
||||
|
||||
Reference in new issue
Block a user