mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(cloudformation): register an ECS task definition's containers with their LinuxParameters (#6027)
* fix(cloudformation): register an ECS task definition's containers with their LinuxParameters An AWS::ECS::TaskDefinition dropped its containers' LinuxParameters, so a container CloudFormation registered ran without the init process, capabilities, devices, shared memory, swap or tmpfs mounts the template asked for, and the Fargate rules on them never applied. They are now read from the task definition as the ECS handler converts it and kept where RegisterTaskDefinition keeps them, among the container's unparsed members under linuxParameters, so DescribeTaskDefinition returns them in the API's shape and the same validation, normalisation and Fargate checks apply as for a definition registered through the API. As CloudFormation's handler does (measured), the devices and tmpfs lists are sent empty when the template has none. * test(compat): wait for the LinuxParameters stacks through TestFixtures Review of #6027: the test's private waitForTerminal and waitForDeleted repeated TestFixtures.awaitStackTerminal. It now waits through that, and deletes its two stacks with a plain DeleteStack after the class, as CloudFormationEcsTaskDefinitionModelTest does. * test(compat): give the ECS CloudFormation stacks Floci's and AWS's own timeouts Review of #6027: DEPLOY_TIMEOUT was 30 seconds against both targets. These stacks finish in milliseconds on Floci, so it is now 10 seconds there and 10 minutes on real AWS, as CloudFormationEventsRuleTargetTest splits it. CloudFormationEcsTaskDefinitionModelTest, from #6018, had the same single 60 seconds and splits the same way.
This commit is contained in:
1 parent
0517a7a936
commit
e38ec02d44
6 files changed
+471
-2
No files matched your search
+68
@@ -352,6 +352,12 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
def.setSecrets(parseSecrets(item.path("Secrets")));
|
||||
def.setLogConfiguration(parseLogConfiguration(item.path("LogConfiguration")));
|
||||
def.setFirelensConfiguration(parseFirelensConfiguration(item.path("FirelensConfiguration")));
|
||||
Map<String, Object> linuxParameters = parseLinuxParameters(item.path("LinuxParameters"));
|
||||
if (linuxParameters != null) {
|
||||
Map<String, Object> unparsed = new LinkedHashMap<>();
|
||||
unparsed.put("linuxParameters", linuxParameters);
|
||||
def.setUnparsed(unparsed);
|
||||
}
|
||||
if (item.path("Command").isArray()) {
|
||||
def.setCommand(toStringList(item.path("Command")));
|
||||
}
|
||||
@@ -372,6 +378,68 @@ public class EcsCfnProvisioner implements CfnResourceProvisioner {
|
||||
node.has("SecretOptions") ? parseSecrets(node.path("SecretOptions")) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A container's {@code LinuxParameters}, read as the ECS handler reads them, in the shape
|
||||
* RegisterTaskDefinition takes them, and kept where that path keeps them: among the
|
||||
* definition's unparsed members, under {@code linuxParameters}. So DescribeTaskDefinition shows
|
||||
* them and the Fargate rules on them apply, as for a definition registered through the API.
|
||||
* The devices and tmpfs lists are always sent, empty when the template has none, as
|
||||
* CloudFormation's handler sends them (measured).
|
||||
*/
|
||||
private static Map<String, Object> parseLinuxParameters(JsonNode node) {
|
||||
if (!node.isObject()) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
JsonNode capabilities = node.path("Capabilities");
|
||||
if (capabilities.isObject()) {
|
||||
Map<String, Object> kernelCapabilities = new LinkedHashMap<>();
|
||||
putStringList(kernelCapabilities, "add", capabilities.path("Add"));
|
||||
putStringList(kernelCapabilities, "drop", capabilities.path("Drop"));
|
||||
result.put("capabilities", kernelCapabilities);
|
||||
}
|
||||
List<Map<String, Object>> devices = new ArrayList<>();
|
||||
for (JsonNode item : node.path("Devices")) {
|
||||
Map<String, Object> device = new LinkedHashMap<>();
|
||||
putValue(device, "hostPath", item.path("HostPath"));
|
||||
putValue(device, "containerPath", item.path("ContainerPath"));
|
||||
putStringList(device, "permissions", item.path("Permissions"));
|
||||
devices.add(device);
|
||||
}
|
||||
result.put("devices", devices);
|
||||
putValue(result, "initProcessEnabled", node.path("InitProcessEnabled"));
|
||||
putValue(result, "maxSwap", node.path("MaxSwap"));
|
||||
putValue(result, "sharedMemorySize", node.path("SharedMemorySize"));
|
||||
putValue(result, "swappiness", node.path("Swappiness"));
|
||||
List<Map<String, Object>> mounts = new ArrayList<>();
|
||||
for (JsonNode item : node.path("Tmpfs")) {
|
||||
Map<String, Object> mount = new LinkedHashMap<>();
|
||||
putValue(mount, "containerPath", item.path("ContainerPath"));
|
||||
putStringList(mount, "mountOptions", item.path("MountOptions"));
|
||||
putValue(mount, "size", item.path("Size"));
|
||||
mounts.add(mount);
|
||||
}
|
||||
result.put("tmpfs", mounts);
|
||||
return result;
|
||||
}
|
||||
|
||||
/** A member the template sets, as the text, integer or boolean the handler converted it to. */
|
||||
private static void putValue(Map<String, Object> target, String key, JsonNode value) {
|
||||
if (value.isTextual()) {
|
||||
target.put(key, value.textValue());
|
||||
} else if (value.isInt()) {
|
||||
target.put(key, value.intValue());
|
||||
} else if (value.isBoolean()) {
|
||||
target.put(key, value.booleanValue());
|
||||
}
|
||||
}
|
||||
|
||||
private static void putStringList(Map<String, Object> target, String key, JsonNode value) {
|
||||
if (value.isArray()) {
|
||||
target.put(key, toStringList(value));
|
||||
}
|
||||
}
|
||||
|
||||
private static FirelensConfiguration parseFirelensConfiguration(JsonNode node) {
|
||||
if (node == null || !node.isObject() || !node.hasNonNull("Type")) {
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user