fix(ecs): round-trip runtimePlatform and logConfiguration on task definitions (#2443)

RegisterTaskDefinition parsed a fixed field list and dropped everything
else, so a task definition registered with a runtimePlatform or a
container logConfiguration came back from DescribeTaskDefinition without
them. A client that verifies its own write — Terraform, or a deploy tool
comparing the registered revision against desired state — saw drift that
was not there.

Both are now parsed, stored on the task definition, and serialized back
with the AWS wire shape. A request that omits them still produces a
response without the keys, so nothing changes for existing callers.

The two fields are set on the task definition returned by
EcsService.registerTaskDefinition, following the pattern already used for
task-level volumes. That mutation happens after the value was stored, so
a backend that serializes on put (persistent, hybrid, WAL) had captured
the pre-mutation value; the definition is now written back, which also
makes the existing volumes round-trip survive a restart.
This commit is contained in:
Davor Santic authored and GitHub committed 2026-08-22 00:22:32 -04:00
1 parent 30f965d056
commit a2389e7733
10 files changed
+480 -2

No files matched your search

@@ -17,12 +17,14 @@ import io.github.hectorvent.floci.services.ecs.model.EcsServiceModel;
import io.github.hectorvent.floci.services.ecs.model.EcsTask;
import io.github.hectorvent.floci.services.ecs.model.KeyValuePair;
import io.github.hectorvent.floci.services.ecs.model.LaunchType;
import io.github.hectorvent.floci.services.ecs.model.LogConfiguration;
import io.github.hectorvent.floci.services.ecs.model.MountPoint;
import io.github.hectorvent.floci.services.ecs.model.NetworkBinding;
import io.github.hectorvent.floci.services.ecs.model.NetworkConfiguration;
import io.github.hectorvent.floci.services.ecs.model.NetworkMode;
import io.github.hectorvent.floci.services.ecs.model.PortMapping;
import io.github.hectorvent.floci.services.ecs.model.ProtectedTask;
import io.github.hectorvent.floci.services.ecs.model.RuntimePlatform;
import io.github.hectorvent.floci.services.ecs.model.ServiceDeployment;
import io.github.hectorvent.floci.services.ecs.model.ServiceRevision;
import io.github.hectorvent.floci.services.ecs.model.Secret;
@@ -40,6 +42,7 @@ import jakarta.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -216,9 +219,12 @@ public class EcsJsonHandler {
TaskDefinition td = service.registerTaskDefinition(family, containerDefs, networkMode, cpu, memory,
taskRoleArn, executionRoleArn, requiresCompatibilities, tags, region);
// Task-level volumes are not part of registerTaskDefinition's signature; set them on the
// returned (and stored) task definition so they round-trip and reach RunTask launches.
// Task-level volumes and runtimePlatform are not part of registerTaskDefinition's signature;
// set them on the returned (and stored) task definition so they round-trip and reach RunTask
// launches, then write the mutated definition back so it also survives a restart.
td.setVolumes(parseVolumes(req.path("volumes")));
td.setRuntimePlatform(parseRuntimePlatform(req.path("runtimePlatform")));
service.persistTaskDefinition(td);
ObjectNode resp = objectMapper.createObjectNode();
resp.set("taskDefinition", taskDefinitionNode(td));
@@ -935,6 +941,17 @@ public class EcsJsonHandler {
if (td.getMemory() != null) { n.put("memory", td.getMemory()); }
if (td.getTaskRoleArn() != null) { n.put("taskRoleArn", td.getTaskRoleArn()); }
if (td.getExecutionRoleArn() != null) { n.put("executionRoleArn", td.getExecutionRoleArn()); }
if (td.getRuntimePlatform() != null) {
RuntimePlatform platform = td.getRuntimePlatform();
ObjectNode platformNode = objectMapper.createObjectNode();
if (platform.cpuArchitecture() != null) {
platformNode.put("cpuArchitecture", platform.cpuArchitecture());
}
if (platform.operatingSystemFamily() != null) {
platformNode.put("operatingSystemFamily", platform.operatingSystemFamily());
}
n.set("runtimePlatform", platformNode);
}
if (td.getRequiresCompatibilities() != null && !td.getRequiresCompatibilities().isEmpty()) {
ArrayNode arr = objectMapper.createArrayNode();
td.getRequiresCompatibilities().forEach(arr::add);
@@ -1052,6 +1069,30 @@ public class EcsJsonHandler {
n.set("mountPoints", mps);
}
if (def.getLogConfiguration() != null) {
LogConfiguration logConfig = def.getLogConfiguration();
ObjectNode logNode = objectMapper.createObjectNode();
if (logConfig.logDriver() != null) {
logNode.put("logDriver", logConfig.logDriver());
}
if (logConfig.options() != null) {
ObjectNode options = objectMapper.createObjectNode();
logConfig.options().forEach(options::put);
logNode.set("options", options);
}
if (logConfig.secretOptions() != null) {
ArrayNode secretOptions = objectMapper.createArrayNode();
for (Secret secret : logConfig.secretOptions()) {
ObjectNode secretNode = objectMapper.createObjectNode();
secretNode.put("name", secret.name());
secretNode.put("valueFrom", secret.valueFrom());
secretOptions.add(secretNode);
}
logNode.set("secretOptions", secretOptions);
}
n.set("logConfiguration", logNode);
}
return n;
}
@@ -1324,6 +1365,7 @@ public class EcsJsonHandler {
def.setSecrets(parseSecrets(item.path("secrets")));
}
def.setMountPoints(parseMountPoints(item.path("mountPoints")));
def.setLogConfiguration(parseLogConfiguration(item.path("logConfiguration")));
if (item.has("command") && item.path("command").isArray()) {
List<String> cmd = new ArrayList<>();
@@ -1377,6 +1419,37 @@ public class EcsJsonHandler {
return result;
}
private RuntimePlatform parseRuntimePlatform(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
String cpuArchitecture = node.path("cpuArchitecture").asText(null);
String operatingSystemFamily = node.path("operatingSystemFamily").asText(null);
if (cpuArchitecture == null && operatingSystemFamily == null) {
return null;
}
return new RuntimePlatform(cpuArchitecture, operatingSystemFamily);
}
private LogConfiguration parseLogConfiguration(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
String logDriver = node.path("logDriver").asText(null);
if (logDriver == null) {
return null;
}
Map<String, String> options = null;
if (node.path("options").isObject()) {
Map<String, String> parsed = new LinkedHashMap<>();
node.path("options").fields()
.forEachRemaining(entry -> parsed.put(entry.getKey(), entry.getValue().asText()));
options = parsed;
}
List<Secret> secretOptions = node.has("secretOptions") ? parseSecrets(node.path("secretOptions")) : null;
return new LogConfiguration(logDriver, options, secretOptions);
}
private List<Volume> parseVolumes(JsonNode node) {
List<Volume> result = new ArrayList<>();
if (!node.isArray()) {
@@ -402,6 +402,15 @@ public class EcsService implements ContainerTeardown {
}
}
/**
* Writes back a task definition mutated after {@link #registerTaskDefinition} returned it.
* A backend that serializes on {@code put} (persistent, hybrid, WAL) stored the value as it was
* at registration, so fields set on the returned instance need this to survive a restart.
*/
public void persistTaskDefinition(TaskDefinition td) {
taskDefinitions.put(td.getFamily() + ":" + td.getRevision(), td);
}
public TaskDefinition describeTaskDefinition(String taskDefinitionRef, String region) {
return resolveTaskDefinitionOrThrow(taskDefinitionRef, region);
}
@@ -19,6 +19,7 @@ public class ContainerDefinition {
private List<String> command;
private List<String> entryPoint;
private List<MountPoint> mountPoints;
private LogConfiguration logConfiguration;
public String getName() { return name; }
public void setName(String name) { this.name = name; }
@@ -55,4 +56,7 @@ public class ContainerDefinition {
public List<MountPoint> getMountPoints() { return mountPoints; }
public void setMountPoints(List<MountPoint> mountPoints) { this.mountPoints = mountPoints; }
public LogConfiguration getLogConfiguration() { return logConfiguration; }
public void setLogConfiguration(LogConfiguration logConfiguration) { this.logConfiguration = logConfiguration; }
}
@@ -0,0 +1,18 @@
package io.github.hectorvent.floci.services.ecs.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.List;
import java.util.Map;
/**
* The {@code logConfiguration} of an ECS container definition:
* {@code {"logDriver": "awslogs", "options": {...}, "secretOptions": [{"name": ..., "valueFrom": ...}]}}.
*
* <p>Modelled for RegisterTaskDefinition/DescribeTaskDefinition round-trip fidelity. Floci does not
* route container output to the configured driver — a local task's logs stay with its Docker
* container — so the {@code awslogs} options are stored and returned rather than acted upon.
*/
@RegisterForReflection
public record LogConfiguration(String logDriver, Map<String, String> options, List<Secret> secretOptions) {
}
@@ -0,0 +1,16 @@
package io.github.hectorvent.floci.services.ecs.model;
import io.quarkus.runtime.annotations.RegisterForReflection;
/**
* The {@code runtimePlatform} of an ECS task definition:
* {@code {"cpuArchitecture": "X86_64"|"ARM64", "operatingSystemFamily": "LINUX"|"WINDOWS_SERVER_*"}}.
*
* <p>Modelled for RegisterTaskDefinition/DescribeTaskDefinition round-trip fidelity — a client that
* reads back what it registered (Terraform, or a deploy tool verifying its own write) must see the
* platform it asked for. Floci runs every task on the host's own architecture, so the value has no
* effect on where a local task is placed.
*/
@RegisterForReflection
public record RuntimePlatform(String cpuArchitecture, String operatingSystemFamily) {
}
@@ -20,6 +20,7 @@ public class TaskDefinition {
private String executionRoleArn;
private List<ContainerDefinition> containerDefinitions;
private List<Volume> volumes;
private RuntimePlatform runtimePlatform;
private List<String> requiresCompatibilities;
private List<String> compatibilities;
private Map<String, String> tags = new HashMap<>();
@@ -59,6 +60,9 @@ public class TaskDefinition {
public List<Volume> getVolumes() { return volumes; }
public void setVolumes(List<Volume> volumes) { this.volumes = volumes; }
public RuntimePlatform getRuntimePlatform() { return runtimePlatform; }
public void setRuntimePlatform(RuntimePlatform runtimePlatform) { this.runtimePlatform = runtimePlatform; }
public List<String> getRequiresCompatibilities() { return requiresCompatibilities; }
public void setRequiresCompatibilities(List<String> requiresCompatibilities) { this.requiresCompatibilities = requiresCompatibilities; }