mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): preserve each MicroVM version build specification (#8600)
Each MicroVM image version now records the build inputs it was created with (code artifact URI, base image ARN and version, build role) as an immutable BuildSpec. GetMicrovmImageVersion and ListMicrovmImageVersions read that snapshot instead of the image's latest inputs, so an update no longer rewrites what older versions report. Versions stored before this change have no snapshot and fall back to their image's last known inputs; the docs note that their original inputs cannot be recovered. Closes #7312
This commit is contained in:
1 parent
975632df5c
commit
06a5ce4219
5 files changed
+151
-7
No files matched your search
+67
@@ -0,0 +1,67 @@
|
||||
package io.floci.aws.services.lambdamicrovms;
|
||||
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
@QuarkusTest
|
||||
class LambdaMicrovmImageVersionBuildSpecIntegrationTest {
|
||||
|
||||
private static final String IMAGES = "/2025-09-09/microvm-images";
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@Test
|
||||
void getKeepsEachVersionsBuildInputsAfterAnUpdate() {
|
||||
String name = createAndUpdate();
|
||||
assertBuildSpec(given().when().get(IMAGES + "/" + name + "/versions/1.0")
|
||||
.then().statusCode(200), "", "original", "1.0");
|
||||
assertBuildSpec(given().when().get(IMAGES + "/" + name + "/versions/2.0")
|
||||
.then().statusCode(200), "", "replacement", "2.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listKeepsEachVersionsBuildInputsAfterAnUpdate() {
|
||||
String name = createAndUpdate();
|
||||
ValidatableResponse listed = given().when().get(IMAGES + "/" + name + "/versions")
|
||||
.then().statusCode(200).body("items.size()", equalTo(2));
|
||||
assertBuildSpec(listed, "items[0].", "original", "1.0");
|
||||
assertBuildSpec(listed, "items[1].", "replacement", "2.0");
|
||||
}
|
||||
|
||||
private String createAndUpdate() {
|
||||
String name = "version-build-spec-" + UUID.randomUUID();
|
||||
given().contentType("application/json").body("{\"name\":\"" + name + "\"," + fields("original", "1.0") + "}")
|
||||
.when().post(IMAGES).then().statusCode(201);
|
||||
cleanup.register(() -> given().when().delete(IMAGES + "/" + name).then().statusCode(200));
|
||||
ValidatableResponse updated = given().contentType("application/json")
|
||||
.body("{" + fields("replacement", "2.0") + "}")
|
||||
.when().put(IMAGES + "/" + name).then().statusCode(200);
|
||||
assertBuildSpec(updated, "", "replacement", "2.0");
|
||||
given().when().get(IMAGES + "/" + name).then().statusCode(200)
|
||||
.body("latestActiveImageVersion", equalTo("2.0"));
|
||||
return name;
|
||||
}
|
||||
|
||||
private static String fields(String label, String version) {
|
||||
return "\"baseImageArn\":\"arn:aws:lambda:us-east-1:aws:microvm-image:" + label + "\","
|
||||
+ "\"baseImageVersion\":\"" + version + "\","
|
||||
+ "\"buildRoleArn\":\"arn:aws:iam::000000000000:role/" + label + "\","
|
||||
+ "\"codeArtifact\":{\"uri\":\"s3://artifacts/" + label + ".zip\"}";
|
||||
}
|
||||
|
||||
private static void assertBuildSpec(ValidatableResponse response, String prefix, String label, String version) {
|
||||
response.body(prefix + "baseImageArn", equalTo("arn:aws:lambda:us-east-1:aws:microvm-image:" + label))
|
||||
.body(prefix + "baseImageVersion", equalTo(version))
|
||||
.body(prefix + "buildRoleArn", equalTo("arn:aws:iam::000000000000:role/" + label))
|
||||
.body(prefix + "codeArtifact.uri", equalTo("s3://artifacts/" + label + ".zip"));
|
||||
}
|
||||
}
|
||||
+61
@@ -13,11 +13,13 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -95,6 +97,65 @@ class LambdaMicrovmsServicePersistenceTest {
|
||||
assertEquals(image.runtimeSettings, image.versions.get(1).runtimeSettings);
|
||||
}
|
||||
|
||||
@Test
|
||||
void buildInputsRemainVersionSpecificAfterReload() {
|
||||
createAndUpdateVersionedImage();
|
||||
LambdaMicrovmsService reloaded = process();
|
||||
|
||||
assertBuildInputs(versionResponse(reloaded, "1.0"), "original", "1.0");
|
||||
assertBuildInputs(versionResponse(reloaded, "2.0"), "replacement", "2.0");
|
||||
assertEquals("s3://artifacts/replacement.zip", reloaded.getImage(REGION, "versioned-image").codeArtifactUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyVersionsUseLastKnownInputsWithoutRewritingStorage() throws IOException {
|
||||
createAndUpdateVersionedImage();
|
||||
Path file = storageDir.resolve("lambda-microvm-images.json");
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode stored = mapper.readTree(file.toFile());
|
||||
for (JsonNode versions : stored.findValues("versions")) {
|
||||
for (JsonNode version : versions) {
|
||||
((ObjectNode) version).remove("buildSpec");
|
||||
}
|
||||
}
|
||||
mapper.writeValue(file.toFile(), stored);
|
||||
String beforeRead = Files.readString(file);
|
||||
|
||||
JsonNode response = versionResponse(process(), "1.0");
|
||||
assertEquals("1.0", response.path("imageVersion").asText());
|
||||
assertBuildInputs(response, "replacement", "2.0");
|
||||
assertEquals(beforeRead, Files.readString(file));
|
||||
}
|
||||
|
||||
private void createAndUpdateVersionedImage() {
|
||||
LambdaMicrovmsService service = process();
|
||||
service.createImage(REGION, ACCOUNT_ID, "versioned-image",
|
||||
"arn:aws:lambda:us-east-1:aws:microvm-image:original",
|
||||
"arn:aws:iam::000000000000:role/original", "s3://artifacts/original.zip", null,
|
||||
"1.0", LambdaMicrovmsService.RuntimeSettings.defaults(), Map.of());
|
||||
service.updateImage(REGION, "versioned-image",
|
||||
"arn:aws:lambda:us-east-1:aws:microvm-image:replacement",
|
||||
"arn:aws:iam::000000000000:role/replacement", "s3://artifacts/replacement.zip", null,
|
||||
"2.0", LambdaMicrovmsService.RuntimeSettings.defaults());
|
||||
}
|
||||
|
||||
private static JsonNode versionResponse(LambdaMicrovmsService service, String version) {
|
||||
RegionResolver resolver = mock(RegionResolver.class);
|
||||
when(resolver.resolveRegion(null)).thenReturn(REGION);
|
||||
LambdaMicrovmsController controller = new LambdaMicrovmsController(service, resolver, new ObjectMapper());
|
||||
return (JsonNode) controller.getVersion(null, "versioned-image", version).getEntity();
|
||||
}
|
||||
|
||||
private static void assertBuildInputs(JsonNode response, String label, String baseVersion) {
|
||||
assertAll(
|
||||
() -> assertEquals("arn:aws:lambda:us-east-1:aws:microvm-image:" + label,
|
||||
response.path("baseImageArn").asText()),
|
||||
() -> assertEquals(baseVersion, response.path("baseImageVersion").asText()),
|
||||
() -> assertEquals("arn:aws:iam::000000000000:role/" + label,
|
||||
response.path("buildRoleArn").asText()),
|
||||
() -> assertEquals("s3://artifacts/" + label + ".zip", response.path("codeArtifact").path("uri").asText()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anInPlaceUpdateReachesTheBackend() {
|
||||
// updateImage mutates the stored image rather than replacing it, so without an explicit
|
||||
|
||||
Reference in new issue
Block a user