mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(ecs): complete the fargate launch surface (#4017)
Floci accepted a Fargate task definition and ran it, but most of the launch surface was dropped on the way through: members that AWS echoes back went missing from responses, launch type resolution never validated what it resolved, and the runtime ignored the sizing the task asked for. Task definitions. A definition round-trips whole. Members that change behaviour are typed (ephemeralStorage, dependsOn, environmentFiles, port mapping name / appProtocol / containerPortRange, pidMode, ipcMode and the container-level members the parser used to drop); members Floci does not act on go through EcsJsonPassthrough, so an unimplemented volume configuration comes back as it was sent rather than vanishing. compatibilities is derived from the definition rather than echoed from requiresCompatibilities, requiresAttributes names the capabilities the definition needs, and a revision carries its registeredAt, deregisteredAt and deleteRequestedAt through the ACTIVE / INACTIVE / DELETE_IN_PROGRESS lifecycle. Validation. Fargate task sizes are validated per CPU architecture and operating system family, ephemeral storage against its 21-200 GiB range, container dependencies for unknown names and cycles, and the parameters Fargate does not support are rejected at registration with the exception type AWS documents for them, ClientException; the message text is Floci's, since AWS does not document the wording. Enum-typed members are validated at parse time and raise InvalidParameterException instead of being treated as absent, and tag cardinality and character limits are enforced across the operations that take tags. Launch. capacityProviderStrategy is distributed across its providers the way ECS distributes it, base first and the remainder by weight, with the cluster's default strategy applying when a request carries neither it nor a launch type. The strategy is validated against the bounds the ECS model gives it: at most 20 providers, weight 0 to 1,000, base 0 to 100,000, one base per strategy, and at least one provider of non-zero weight when a strategy names more than one, since a provider of weight 0 places nothing beyond its base. A task's CPU and memory reach the container, an awsvpc task gets an ENI per task and releases it when it stops, container dependencies are ordered with cycle detection, and mock mode reports per-container detail so a client running without Docker sees the same shape. The ENI allocation reaches into EC2, whose InvalidSubnetID.NotFound and InvalidGroup.NotFound are not in RunTask's error list, so an unknown subnet or security group is reported as the InvalidParameterException AWS returns. Verified against the AWS SDK for Java v2 and the AWS ECS API reference. Adds EcsFargateTaskIntegrationTest, EcsFargateTaskDefinitionIntegrationTest and EcsFargateEdgeCaseIntegrationTest, plus an SDK-based EcsFargateTest in the compatibility suite.
This commit is contained in:
1 parent
4906b7deed
commit
bf1152e144
40 files changed
+4209
-267
No files matched your search
@@ -0,0 +1,221 @@
|
||||
package com.floci.test;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
import software.amazon.awssdk.services.ec2.Ec2Client;
|
||||
import software.amazon.awssdk.services.ec2.model.DescribeSubnetsRequest;
|
||||
import software.amazon.awssdk.services.ecs.EcsClient;
|
||||
import software.amazon.awssdk.services.ecs.model.AwsVpcConfiguration;
|
||||
import software.amazon.awssdk.services.ecs.model.CapacityProviderStrategyItem;
|
||||
import software.amazon.awssdk.services.ecs.model.Compatibility;
|
||||
import software.amazon.awssdk.services.ecs.model.ContainerDefinition;
|
||||
import software.amazon.awssdk.services.ecs.model.CreateClusterRequest;
|
||||
import software.amazon.awssdk.services.ecs.model.DeleteTaskDefinitionsRequest;
|
||||
import software.amazon.awssdk.services.ecs.model.DeregisterTaskDefinitionRequest;
|
||||
import software.amazon.awssdk.services.ecs.model.DescribeTaskDefinitionRequest;
|
||||
import software.amazon.awssdk.services.ecs.model.DescribeTasksRequest;
|
||||
import software.amazon.awssdk.services.ecs.model.DescribeTasksResponse;
|
||||
import software.amazon.awssdk.services.ecs.model.EcsException;
|
||||
import software.amazon.awssdk.services.ecs.model.EphemeralStorage;
|
||||
import software.amazon.awssdk.services.ecs.model.LaunchType;
|
||||
import software.amazon.awssdk.services.ecs.model.NetworkConfiguration;
|
||||
import software.amazon.awssdk.services.ecs.model.NetworkMode;
|
||||
import software.amazon.awssdk.services.ecs.model.RegisterTaskDefinitionRequest;
|
||||
import software.amazon.awssdk.services.ecs.model.RunTaskRequest;
|
||||
import software.amazon.awssdk.services.ecs.model.StopTaskRequest;
|
||||
import software.amazon.awssdk.services.ecs.model.Task;
|
||||
import software.amazon.awssdk.services.ecs.model.TaskDefinition;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* The Fargate launch type through a real SDK client: the members the generated model carries have
|
||||
* to come back populated, not just be accepted on the way in.
|
||||
*/
|
||||
@DisplayName("ECS Fargate launch type")
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class EcsFargateTest {
|
||||
|
||||
private static EcsClient ecs;
|
||||
private static Ec2Client ec2;
|
||||
private static String clusterName;
|
||||
private static String family;
|
||||
private static String subnetId;
|
||||
private static String taskArn;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
ecs = TestFixtures.ecsClient();
|
||||
ec2 = TestFixtures.ec2Client();
|
||||
String suffix = String.valueOf(System.currentTimeMillis() % 100000);
|
||||
clusterName = "sdk-fargate-cluster-" + suffix;
|
||||
family = "sdk-fargate-task-" + suffix;
|
||||
subnetId = ec2.describeSubnets(DescribeSubnetsRequest.builder().build())
|
||||
.subnets().get(0).subnetId();
|
||||
ecs.createCluster(CreateClusterRequest.builder().clusterName(clusterName).build());
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
if (ecs == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (taskArn != null) {
|
||||
ecs.stopTask(StopTaskRequest.builder().cluster(clusterName).task(taskArn).build());
|
||||
}
|
||||
} catch (EcsException ignored) {
|
||||
// The task may already have stopped; cleanup must not fail the run.
|
||||
}
|
||||
try {
|
||||
ecs.deregisterTaskDefinition(DeregisterTaskDefinitionRequest.builder()
|
||||
.taskDefinition(family + ":1").build());
|
||||
ecs.deleteTaskDefinitions(DeleteTaskDefinitionsRequest.builder()
|
||||
.taskDefinitions(family + ":1").build());
|
||||
} catch (EcsException ignored) {
|
||||
// Same: a failed registration leaves nothing to clean up.
|
||||
}
|
||||
ecs.close();
|
||||
ec2.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("RegisterTaskDefinition - a Fargate definition round-trips its members")
|
||||
void registerFargateTaskDefinition() {
|
||||
TaskDefinition registered = ecs.registerTaskDefinition(RegisterTaskDefinitionRequest.builder()
|
||||
.family(family)
|
||||
.requiresCompatibilities(Compatibility.FARGATE)
|
||||
.networkMode(NetworkMode.AWSVPC)
|
||||
.cpu("512")
|
||||
.memory("1024")
|
||||
.ephemeralStorage(EphemeralStorage.builder().sizeInGiB(40).build())
|
||||
.containerDefinitions(ContainerDefinition.builder()
|
||||
.name("app")
|
||||
.image("nginx:alpine")
|
||||
.essential(true)
|
||||
.user("1000:1000")
|
||||
.workingDirectory("/srv")
|
||||
.readonlyRootFilesystem(true)
|
||||
.stopTimeout(30)
|
||||
.build())
|
||||
.build()).taskDefinition();
|
||||
|
||||
assertThat(registered.compatibilitiesAsStrings()).contains("FARGATE");
|
||||
assertThat(registered.ephemeralStorage().sizeInGiB()).isEqualTo(40);
|
||||
assertThat(registered.registeredAt()).isNotNull();
|
||||
|
||||
TaskDefinition described = ecs.describeTaskDefinition(DescribeTaskDefinitionRequest.builder()
|
||||
.taskDefinition(family).build()).taskDefinition();
|
||||
ContainerDefinition container = described.containerDefinitions().get(0);
|
||||
assertThat(described.ephemeralStorage().sizeInGiB()).isEqualTo(40);
|
||||
assertThat(container.user()).isEqualTo("1000:1000");
|
||||
assertThat(container.workingDirectory()).isEqualTo("/srv");
|
||||
assertThat(container.readonlyRootFilesystem()).isTrue();
|
||||
assertThat(container.stopTimeout()).isEqualTo(30);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
@DisplayName("RegisterTaskDefinition - a size Fargate does not offer is rejected")
|
||||
void rejectsAnInvalidFargateSize() {
|
||||
assertThatThrownBy(() -> ecs.registerTaskDefinition(RegisterTaskDefinitionRequest.builder()
|
||||
.family(family + "-invalid")
|
||||
.requiresCompatibilities(Compatibility.FARGATE)
|
||||
.networkMode(NetworkMode.AWSVPC)
|
||||
.cpu("256")
|
||||
.memory("4096")
|
||||
.containerDefinitions(ContainerDefinition.builder()
|
||||
.name("app").image("nginx:alpine").build())
|
||||
.build()))
|
||||
.isInstanceOf(EcsException.class)
|
||||
.hasMessageContaining("No Fargate configuration exists");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
@DisplayName("RunTask - a Fargate task reports its platform, ENI and ephemeral storage")
|
||||
void runFargateTask() {
|
||||
List<Task> tasks = ecs.runTask(RunTaskRequest.builder()
|
||||
.cluster(clusterName)
|
||||
.taskDefinition(family)
|
||||
.launchType(LaunchType.FARGATE)
|
||||
.enableExecuteCommand(true)
|
||||
.networkConfiguration(NetworkConfiguration.builder()
|
||||
.awsvpcConfiguration(AwsVpcConfiguration.builder()
|
||||
.subnets(subnetId)
|
||||
.build())
|
||||
.build())
|
||||
.build()).tasks();
|
||||
|
||||
assertThat(tasks).hasSize(1);
|
||||
Task task = tasks.get(0);
|
||||
taskArn = task.taskArn();
|
||||
|
||||
assertThat(task.launchType()).isEqualTo(LaunchType.FARGATE);
|
||||
assertThat(task.platformVersion()).isNotBlank();
|
||||
assertThat(task.platformFamily()).isEqualTo("Linux");
|
||||
assertThat(task.ephemeralStorage().sizeInGiB()).isEqualTo(40);
|
||||
assertThat(task.enableExecuteCommand()).isTrue();
|
||||
assertThat(task.group()).isEqualTo("family:" + family);
|
||||
assertThat(task.attachments()).hasSize(1);
|
||||
assertThat(task.attachments().get(0).type()).isEqualTo("ElasticNetworkInterface");
|
||||
assertThat(task.attachments().get(0).details())
|
||||
.anySatisfy(detail -> assertThat(detail.name()).isEqualTo("privateIPv4Address"));
|
||||
|
||||
Task described = ecs.describeTasks(DescribeTasksRequest.builder()
|
||||
.cluster(clusterName)
|
||||
.tasks(taskArn)
|
||||
.build()).tasks().get(0);
|
||||
assertThat(described.connectivityAsString()).isEqualTo("CONNECTED");
|
||||
assertThat(described.healthStatusAsString()).isNotBlank();
|
||||
assertThat(described.version()).isPositive();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
@DisplayName("RunTask - FARGATE_SPOT places through the capacity provider")
|
||||
void runTaskOnFargateSpot() {
|
||||
Task task = ecs.runTask(RunTaskRequest.builder()
|
||||
.cluster(clusterName)
|
||||
.taskDefinition(family)
|
||||
.capacityProviderStrategy(CapacityProviderStrategyItem.builder()
|
||||
.capacityProvider("FARGATE_SPOT")
|
||||
.weight(1)
|
||||
.build())
|
||||
.networkConfiguration(NetworkConfiguration.builder()
|
||||
.awsvpcConfiguration(AwsVpcConfiguration.builder()
|
||||
.subnets(subnetId)
|
||||
.build())
|
||||
.build())
|
||||
.build()).tasks().get(0);
|
||||
|
||||
assertThat(task.capacityProviderName()).isEqualTo("FARGATE_SPOT");
|
||||
// A task reports the launch type its capacity provider resolves to, alongside the provider.
|
||||
assertThat(task.launchType()).isEqualTo(LaunchType.FARGATE);
|
||||
|
||||
ecs.stopTask(StopTaskRequest.builder()
|
||||
.cluster(clusterName).task(task.taskArn()).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
@DisplayName("DescribeTasks - an unknown reference comes back as MISSING")
|
||||
void describeReportsMissingRatherThanDroppingTheReference() {
|
||||
DescribeTasksResponse tasks = ecs.describeTasks(DescribeTasksRequest.builder()
|
||||
.cluster(clusterName)
|
||||
.tasks("00000000000000000000000000000000")
|
||||
.build());
|
||||
assertThat(tasks.tasks()).isEmpty();
|
||||
assertThat(tasks.failures()).singleElement()
|
||||
.satisfies(failure -> assertThat(failure.reason()).isEqualTo("MISSING"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user