mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ecs): omit readOnly from mountPoints and volumesFrom that never sent it (#6933)
A mount point or volumes-from entry registered without readOnly described back with readOnly=false, and the Terraform AWS provider then diffed the shape and replaced aws_ecs_task_definition on every apply. readOnly is an optional boxed boolean in the ECS model: absence stays absent, explicit true and false echo as sent, and the container runtime still mounts absence as read-write. Closes #6909 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> Co-authored-by: Priamo Germosen <6233424+pgermosen@users.noreply.github.com>
This commit is contained in:
1 parent
5f327da1c8
commit
4d21ea66cf
7 files changed
+197
-10
No files matched your search
@@ -1347,4 +1347,108 @@ class EcsIntegrationTest {
|
||||
.body("__type", containsString("ClientException"))
|
||||
.body("message", containsString("HealthCheck command is required."));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(72)
|
||||
void registerAndDescribeTaskDefinitionKeepsReadOnlyAbsentWhenItWasNeverSent() {
|
||||
String arn = ecs("RegisterTaskDefinition")
|
||||
.body("""
|
||||
{
|
||||
"family": "readonly-absent-roundtrip",
|
||||
"volumes": [{"name": "v"}],
|
||||
"containerDefinitions": [
|
||||
{
|
||||
"name": "a",
|
||||
"image": "nginx:latest",
|
||||
"memory": 128,
|
||||
"essential": true,
|
||||
"mountPoints": [{"sourceVolume": "v", "containerPath": "/a"}]
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"image": "nginx:latest",
|
||||
"memory": 128,
|
||||
"essential": false,
|
||||
"volumesFrom": [{"sourceContainer": "a"}]
|
||||
}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("taskDefinition.containerDefinitions[0].mountPoints[0]"
|
||||
+ ".sourceVolume", equalTo("v"))
|
||||
.body("taskDefinition.containerDefinitions[0].mountPoints[0]"
|
||||
+ ".containerPath", equalTo("/a"))
|
||||
.body("taskDefinition.containerDefinitions[1].volumesFrom[0]"
|
||||
+ ".sourceContainer", equalTo("a"))
|
||||
.extract()
|
||||
.path("taskDefinition.taskDefinitionArn");
|
||||
|
||||
ecs("DescribeTaskDefinition")
|
||||
.body("""
|
||||
{"taskDefinition": "%s"}
|
||||
""".formatted(arn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("taskDefinition.containerDefinitions[0].mountPoints[0]", not(hasKey("readOnly")))
|
||||
.body("taskDefinition.containerDefinitions[1].volumesFrom[0]", not(hasKey("readOnly")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(73)
|
||||
void registerAndDescribeTaskDefinitionEchoesAnExplicitReadOnly() {
|
||||
String arn = ecs("RegisterTaskDefinition")
|
||||
.body("""
|
||||
{
|
||||
"family": "readonly-explicit-roundtrip",
|
||||
"volumes": [{"name": "v"}],
|
||||
"containerDefinitions": [
|
||||
{
|
||||
"name": "a",
|
||||
"image": "nginx:latest",
|
||||
"memory": 128,
|
||||
"essential": true,
|
||||
"mountPoints": [
|
||||
{"sourceVolume": "v", "containerPath": "/ro", "readOnly": true},
|
||||
{"sourceVolume": "v", "containerPath": "/rw", "readOnly": false}
|
||||
],
|
||||
"volumesFrom": [
|
||||
{"sourceContainer": "b", "readOnly": true},
|
||||
{"sourceContainer": "b", "readOnly": false}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"image": "nginx:latest",
|
||||
"memory": 128,
|
||||
"essential": false
|
||||
}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract()
|
||||
.path("taskDefinition.taskDefinitionArn");
|
||||
|
||||
ecs("DescribeTaskDefinition")
|
||||
.body("""
|
||||
{"taskDefinition": "%s"}
|
||||
""".formatted(arn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("taskDefinition.containerDefinitions[0].mountPoints[0].readOnly", equalTo(true))
|
||||
.body("taskDefinition.containerDefinitions[0].mountPoints[1].readOnly", equalTo(false))
|
||||
.body("taskDefinition.containerDefinitions[0].volumesFrom[0].readOnly", equalTo(true))
|
||||
.body("taskDefinition.containerDefinitions[0].volumesFrom[1].readOnly", equalTo(false));
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,87 @@ class EcsJsonHandlerVolumesTest {
|
||||
assertFalse(mps.get(1).path("readOnly").asBoolean(), "aws mount is read-write");
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerTaskDefinitionOmitsReadOnlyFromMountPointsAndVolumesFromThatNeverSentIt() throws Exception {
|
||||
String requestJson = """
|
||||
{
|
||||
"family": "td",
|
||||
"containerDefinitions": [
|
||||
{
|
||||
"name": "a",
|
||||
"image": "nginx",
|
||||
"memory": 128,
|
||||
"essential": true,
|
||||
"mountPoints": [
|
||||
{"sourceVolume": "v", "containerPath": "/a"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"image": "nginx",
|
||||
"memory": 128,
|
||||
"essential": false,
|
||||
"volumesFrom": [
|
||||
{"sourceContainer": "a"}
|
||||
]
|
||||
}
|
||||
],
|
||||
"volumes": [{"name": "v"}]
|
||||
}
|
||||
""";
|
||||
JsonNode request = objectMapper.readTree(requestJson);
|
||||
|
||||
Response response = handler.handle("RegisterTaskDefinition", request, "us-east-1");
|
||||
JsonNode td = objectMapper.valueToTree(response.getEntity()).path("taskDefinition");
|
||||
JsonNode containerA = td.path("containerDefinitions").get(0);
|
||||
JsonNode containerB = td.path("containerDefinitions").get(1);
|
||||
|
||||
assertTrue(containerA.path("mountPoints").get(0).path("readOnly").isMissingNode(),
|
||||
"a mountPoint registered without readOnly must not gain one");
|
||||
assertTrue(containerB.path("volumesFrom").get(0).path("readOnly").isMissingNode(),
|
||||
"a volumesFrom entry registered without readOnly must not gain one");
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerTaskDefinitionEchoesAnExplicitReadOnlyOnMountPointsAndVolumesFrom() throws Exception {
|
||||
String requestJson = """
|
||||
{
|
||||
"family": "td-explicit-readonly",
|
||||
"containerDefinitions": [
|
||||
{
|
||||
"name": "app",
|
||||
"image": "nginx",
|
||||
"memory": 128,
|
||||
"essential": true,
|
||||
"mountPoints": [
|
||||
{"sourceVolume": "v", "containerPath": "/ro", "readOnly": true},
|
||||
{"sourceVolume": "v", "containerPath": "/rw", "readOnly": false}
|
||||
],
|
||||
"volumesFrom": [
|
||||
{"sourceContainer": "other", "readOnly": true},
|
||||
{"sourceContainer": "other2", "readOnly": false}
|
||||
]
|
||||
}
|
||||
],
|
||||
"volumes": [{"name": "v"}]
|
||||
}
|
||||
""";
|
||||
JsonNode request = objectMapper.readTree(requestJson);
|
||||
|
||||
Response response = handler.handle("RegisterTaskDefinition", request, "us-east-1");
|
||||
JsonNode td = objectMapper.valueToTree(response.getEntity()).path("taskDefinition");
|
||||
JsonNode definition = td.path("containerDefinitions").get(0);
|
||||
JsonNode mps = definition.path("mountPoints");
|
||||
JsonNode volumesFrom = definition.path("volumesFrom");
|
||||
|
||||
assertTrue(mps.get(0).path("readOnly").asBoolean(), "explicit readOnly true must round-trip");
|
||||
assertFalse(mps.get(1).path("readOnly").asBoolean(), "explicit readOnly false must round-trip");
|
||||
assertTrue(volumesFrom.get(0).path("readOnly").asBoolean(),
|
||||
"explicit volumesFrom readOnly true must round-trip");
|
||||
assertFalse(volumesFrom.get(1).path("readOnly").asBoolean(),
|
||||
"explicit volumesFrom readOnly false must round-trip");
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerTaskDefinitionRoundTripsEfsVolumeConfiguration() throws Exception {
|
||||
String requestJson = """
|
||||
|
||||
Reference in new issue
Block a user