mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(lambda): expose the executing version on cold launches (#5523)
* fix(lambda): expose the executing version on cold launches Signed-off-by: Andre Kurait <akurait@amazon.com> * fix(lambda): propagate executing version to Kubernetes pods Signed-off-by: Andre Kurait <akurait@amazon.com> --------- Signed-off-by: Andre Kurait <akurait@amazon.com>
This commit is contained in:
1 parent
431748f740
commit
8565ad837a
6 files changed
+82
-4
No files matched your search
+12
-2
@@ -151,7 +151,9 @@ class LambdaVersionIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.header("X-Amz-Function-Error", nullValue())
|
||||
.body("ok", equalTo(true));
|
||||
.body("ok", equalTo(true))
|
||||
.body("envVersion", equalTo("$LATEST"))
|
||||
.body("contextVersion", equalTo("$LATEST"));
|
||||
} finally {
|
||||
given().delete(BASE_PATH + "/functions/" + fnName);
|
||||
}
|
||||
@@ -192,6 +194,8 @@ class LambdaVersionIntegrationTest {
|
||||
// Body first: the header assertion below fails fast and would otherwise mask what
|
||||
// the version actually returned.
|
||||
.body("ok", equalTo(true))
|
||||
.body("envVersion", equalTo("1"))
|
||||
.body("contextVersion", equalTo("1"))
|
||||
.header("X-Amz-Function-Error", nullValue());
|
||||
} finally {
|
||||
given().delete(BASE_PATH + "/functions/" + fnName);
|
||||
@@ -300,7 +304,13 @@ class LambdaVersionIntegrationTest {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
zos.putNextEntry(new ZipEntry("index.js"));
|
||||
zos.write("exports.handler = async () => ({ ok: true });".getBytes());
|
||||
zos.write("""
|
||||
exports.handler = async (event, context) => ({
|
||||
ok: true,
|
||||
envVersion: process.env.AWS_LAMBDA_FUNCTION_VERSION,
|
||||
contextVersion: context.functionVersion
|
||||
});
|
||||
""".getBytes());
|
||||
zos.closeEntry();
|
||||
}
|
||||
String base64Zip = Base64.getEncoder().encodeToString(baos.toByteArray());
|
||||
|
||||
+35
@@ -37,6 +37,7 @@ 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.MethodSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
@@ -225,6 +226,40 @@ class ContainerLauncherTest {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"$LATEST", "1", "7"})
|
||||
void launchExposesTheExecutingVersion(String version) {
|
||||
LambdaFunction fn = new LambdaFunction();
|
||||
fn.setFunctionName("version-fn");
|
||||
fn.setHotReloadHostPath("/home/ci/code");
|
||||
fn.setRuntime("nodejs20.x");
|
||||
fn.setHandler("index.handler");
|
||||
fn.setVersion(version);
|
||||
|
||||
launcher.launch(fn);
|
||||
|
||||
assertEquals(List.of("AWS_LAMBDA_FUNCTION_VERSION=" + version),
|
||||
captureRealContainerSpec().env().stream()
|
||||
.filter(value -> value.startsWith("AWS_LAMBDA_FUNCTION_VERSION=")).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void launchPreventsAnEnvironmentOverrideOfTheExecutingVersion() {
|
||||
LambdaFunction fn = new LambdaFunction();
|
||||
fn.setFunctionName("version-fn");
|
||||
fn.setHotReloadHostPath("/home/ci/code");
|
||||
fn.setRuntime("nodejs20.x");
|
||||
fn.setHandler("index.handler");
|
||||
fn.setVersion("7");
|
||||
fn.setEnvironment(Map.of("AWS_LAMBDA_FUNCTION_VERSION", "user-override"));
|
||||
|
||||
launcher.launch(fn);
|
||||
|
||||
assertEquals(List.of("AWS_LAMBDA_FUNCTION_VERSION=7"),
|
||||
captureRealContainerSpec().env().stream()
|
||||
.filter(value -> value.startsWith("AWS_LAMBDA_FUNCTION_VERSION=")).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
void launchFunction_hotReloadMountsTheHostDirectoryReadOnlyAtVarTask() {
|
||||
LambdaFunction fn = new LambdaFunction();
|
||||
|
||||
+21
@@ -24,6 +24,8 @@ import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
@@ -184,6 +186,25 @@ class KubernetesPodLauncherTest {
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"$LATEST, $$LATEST", "1, 1", "7, 7"})
|
||||
void launchExposesTheExecutingVersionInThePodAndRuntimeApi(String version, String podValue) {
|
||||
markPodPhaseInBackground("floci-lambda-my-fn-", "Running");
|
||||
LambdaFunction fn = function();
|
||||
fn.setVersion(version);
|
||||
fn.setEnvironment(Map.of("AWS_LAMBDA_FUNCTION_VERSION", "user-override"));
|
||||
|
||||
ContainerHandle handle = launcher.launch(fn);
|
||||
|
||||
Pod pod = client.pods().inNamespace("default").withName(handle.getContainerId()).get();
|
||||
// The pod spec escapes dollars for kubelet expansion; the runtime receives literal $LATEST.
|
||||
assertThat(pod.getSpec().getContainers().getFirst().getEnv())
|
||||
.filteredOn(variable -> "AWS_LAMBDA_FUNCTION_VERSION".equals(variable.getName()))
|
||||
.extracting(EnvVar::getValue)
|
||||
.containsExactly(podValue);
|
||||
verify(runtimeApiServer).setFunctionMetadata("my-fn", version, "index.handler", "000000000000");
|
||||
}
|
||||
|
||||
@Test
|
||||
void launchPassesTheFunctionsOwningAccountIntoTheBaselineAwsEnv() {
|
||||
// A pod-launched Lambda is subject to the same placeholder-credential bug as a
|
||||
|
||||
Reference in new issue
Block a user