mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): honor platform-specific runtime image overrides (#6786)
Select runtime images with the effective Docker platform while preserving runtime-wide defaults, explicit platform precedence and code-volume helper platform. Signed-off-by: Andre Kurait <akurait@amazon.com> Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
80dbdbc0f8
commit
a46a2b32fd
10 files changed
+144
-30
No files matched your search
@@ -363,7 +363,7 @@ class LambdaImageConfigTest {
|
||||
// of starting an empty container. This test covers cmd construction, so any real
|
||||
// directory will do.
|
||||
fn.setCodeLocalPath(codeDir.toString());
|
||||
when(imageResolver.resolve("nodejs20.x")).thenReturn("public.ecr.aws/lambda/nodejs:20");
|
||||
when(imageResolver.resolve("nodejs20.x", null)).thenReturn("public.ecr.aws/lambda/nodejs:20");
|
||||
|
||||
launcher.launch(fn);
|
||||
|
||||
|
||||
+60
-12
@@ -40,6 +40,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -145,14 +146,7 @@ class ContainerLauncherTest {
|
||||
lenient().when(ecrRegistryManager.rewriteImageUri(any()))
|
||||
.thenAnswer(inv -> inv.getArgument(0));
|
||||
|
||||
ContainerBuilder containerBuilder = new ContainerBuilder(config, dockerHostResolver, embeddedDnsServer);
|
||||
ContainerReachableEndpoint reachableEndpoint =
|
||||
new ContainerReachableEndpoint(config, dockerHostResolver, embeddedDnsServer, 4566);
|
||||
LaunchedContainerAwsEnv awsEnv = new LaunchedContainerAwsEnv(reachableEndpoint);
|
||||
launcher = new ContainerLauncher(containerBuilder, lifecycleManager, logStreamer, imageResolver,
|
||||
runtimeApiServerFactory, dockerHostResolver, config, ecrRegistryManager,
|
||||
layerService, awsEnv,
|
||||
executionRoleCredentials);
|
||||
launcher = newLauncher(imageResolver);
|
||||
|
||||
when(runtimeApiServerFactory.create()).thenReturn(runtimeApiServer);
|
||||
when(runtimeApiServer.getPort()).thenReturn(9000);
|
||||
@@ -428,6 +422,57 @@ class ContainerLauncherTest {
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class), anyString());
|
||||
}
|
||||
|
||||
private ContainerLauncher newLauncher(ImageResolver selectedResolver) {
|
||||
ContainerBuilder builder = new ContainerBuilder(config, dockerHostResolver, embeddedDnsServer);
|
||||
ContainerReachableEndpoint endpoint =
|
||||
new ContainerReachableEndpoint(config, dockerHostResolver, embeddedDnsServer, 4566);
|
||||
return new ContainerLauncher(builder, lifecycleManager, logStreamer, selectedResolver,
|
||||
runtimeApiServerFactory, dockerHostResolver, config, ecrRegistryManager,
|
||||
layerService, new LaunchedContainerAwsEnv(endpoint),
|
||||
executionRoleCredentials);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"arm64, true, , linux/arm64, arm64",
|
||||
"x86_64, true, , linux/amd64, amd64",
|
||||
", true, , linux/amd64, amd64",
|
||||
"arm64, false, , , fallback",
|
||||
"arm64, true, --platform linux/amd64, linux/amd64, amd64",
|
||||
"x86_64, false, --platform linux/arm64, linux/arm64, arm64"
|
||||
})
|
||||
void launchFunction_selectsRuntimePinForEffectiveContainerPlatform(
|
||||
String architecture, boolean honourArchitecture, String flags,
|
||||
String expectedPlatform, String expectedImage) throws Exception {
|
||||
EmulatorConfig.LambdaServiceConfig lambda = config.services().lambda();
|
||||
lenient().when(lambda.honourArchitectures()).thenReturn(honourArchitecture);
|
||||
when(lambda.dockerFlags()).thenReturn(Optional.ofNullable(flags));
|
||||
when(lambda.runtimeImages()).thenReturn(Map.of(
|
||||
"nodejs20.x", "registry.example/node:fallback",
|
||||
"nodejs20.x.linux.amd64", "registry.example/node:amd64",
|
||||
"nodejs20.x.linux.arm64", "registry.example/node:arm64"));
|
||||
launcher = newLauncher(new ImageResolver(config));
|
||||
LambdaFunction fn = new LambdaFunction();
|
||||
fn.setFunctionName("runtime-pin-fn");
|
||||
fn.setRuntime("nodejs20.x");
|
||||
fn.setHandler("index.handler");
|
||||
fn.setCodeLocalPath(Files.createDirectory(tempDir.resolve("runtime-pin-code")).toString());
|
||||
if (architecture != null) {
|
||||
fn.setArchitectures(List.of(architecture));
|
||||
}
|
||||
|
||||
launcher.launch(fn);
|
||||
|
||||
ArgumentCaptor<ContainerSpec> spec = ArgumentCaptor.forClass(ContainerSpec.class);
|
||||
if (expectedPlatform == null) {
|
||||
verify(lifecycleManager).create(spec.capture());
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class), anyString());
|
||||
} else {
|
||||
verify(lifecycleManager).create(spec.capture(), eq(expectedPlatform));
|
||||
}
|
||||
assertEquals("registry.example/node:" + expectedImage, spec.getValue().image());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("invalidPersistedArchitectures")
|
||||
void launchFunction_rejectsInvalidPersistedArchitecturesBeforeCreatingContainer(
|
||||
@@ -460,10 +505,13 @@ class ContainerLauncherTest {
|
||||
List.of("arm64", "x86_64"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void launchFunction_usesArm64DockerPlatformForCodeVolumeHelper() throws Exception {
|
||||
@ParameterizedTest
|
||||
@CsvSource({"arm64, ", "x86_64, --platform linux/arm64"})
|
||||
void launchFunction_usesArm64DockerPlatformForCodeVolumeHelper(String architecture, String flags)
|
||||
throws Exception {
|
||||
EmulatorConfig.LambdaServiceConfig lambda = config.services().lambda();
|
||||
when(lambda.honourArchitectures()).thenReturn(true);
|
||||
lenient().when(lambda.honourArchitectures()).thenReturn(true);
|
||||
when(lambda.dockerFlags()).thenReturn(Optional.ofNullable(flags));
|
||||
Path codePath = Files.createDirectory(tempDir.resolve("large-arm64-code"));
|
||||
Files.write(codePath.resolve("bundle.bin"), new byte[8 * 1024]);
|
||||
|
||||
@@ -473,7 +521,7 @@ class ContainerLauncherTest {
|
||||
fn.setHandler("index.handler");
|
||||
fn.setCodeLocalPath(codePath.toString());
|
||||
fn.setCodeSha256("large-arm64-code-sha");
|
||||
fn.setArchitectures(List.of("arm64"));
|
||||
fn.setArchitectures(List.of(architecture));
|
||||
|
||||
withLoweredCodeVolumeThreshold(() -> {
|
||||
launcher.launch(fn);
|
||||
|
||||
+19
@@ -26,6 +26,25 @@ class ImageResolverEnvConfigTest {
|
||||
.services().lambda().runtimeImages().get("python3.12"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void platformRuntimeKeysBindFromEnvironment() {
|
||||
SmallRyeConfig config = new SmallRyeConfigBuilder()
|
||||
.withSources(new EnvConfigSource(Map.of(
|
||||
"FLOCI_SERVICES_LAMBDA_RUNTIME_IMAGES__PROVIDED_AL2023_LINUX_AMD64__",
|
||||
"registry.example/provided:amd64",
|
||||
"FLOCI_SERVICES_LAMBDA_RUNTIME_IMAGES__PROVIDED_AL2023_LINUX_ARM64__",
|
||||
"registry.example/provided:arm64",
|
||||
"FLOCI_SERVICES_LAMBDA_RUNTIME_IMAGES__PROVIDED_AL2023__",
|
||||
"registry.example/provided:fallback"), 300))
|
||||
.withMapping(EmulatorConfig.class)
|
||||
.build();
|
||||
ImageResolver resolver = new ImageResolver(config.getConfigMapping(EmulatorConfig.class));
|
||||
|
||||
assertEquals("registry.example/provided:amd64", resolver.resolve("provided.al2023", "linux/amd64"));
|
||||
assertEquals("registry.example/provided:arm64", resolver.resolve("provided.al2023", "linux/arm64"));
|
||||
assertEquals("registry.example/provided:fallback", resolver.resolve("provided.al2023"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unquotedRuntimeKeyDoesNotBind() {
|
||||
SmallRyeConfig config = new SmallRyeConfigBuilder()
|
||||
|
||||
+19
-1
@@ -154,12 +154,30 @@ class ImageResolverTest {
|
||||
assertEquals("public.ecr.aws/lambda/python:3.11", configuredResolver.resolve("python3.11"));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"linux/amd64, a", "linux/arm64, b", "linux/riscv64, c", ", c"})
|
||||
void selectsPlatformManifestBeforeRuntimeWideFallback(String platform, String digest) {
|
||||
String repository = "registry.example/lambda-python@sha256:";
|
||||
when(config.services().lambda().runtimeImages()).thenReturn(Map.of(
|
||||
"python3.12.linux.amd64", repository + "a".repeat(64),
|
||||
"python3.12.linux.arm64", repository + "b".repeat(64),
|
||||
"python3.12", repository + "c".repeat(64)));
|
||||
ImageResolver configuredResolver = new ImageResolver(config);
|
||||
|
||||
assertEquals(repository + digest.repeat(64), configuredResolver.resolve("python3.12", platform));
|
||||
assertEquals("public.ecr.aws/lambda/python:3.11", configuredResolver.resolve("python3.11", platform));
|
||||
assertEquals("custom/image:tag", configuredResolver.resolve("custom/image:tag", platform));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownRuntimeCannotBeOverridden() {
|
||||
when(config.services().lambda().runtimeImages()).thenReturn(Map.of("unknown", "example.com/unknown:1"));
|
||||
when(config.services().lambda().runtimeImages()).thenReturn(Map.of(
|
||||
"unknown", "example.com/unknown:1",
|
||||
"unknown.linux.arm64", "example.com/unknown:arm64"));
|
||||
ImageResolver configuredResolver = new ImageResolver(config);
|
||||
|
||||
assertThrows(AwsException.class, () -> configuredResolver.resolve("unknown"));
|
||||
assertThrows(AwsException.class, () -> configuredResolver.resolve("unknown", "linux/arm64"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user