mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fix(ecs): apply cluster settings given on CreateCluster (#2845)
handleCreateCluster read clusterName and tags and nothing else, and EcsService.createCluster had no settings parameter, so settings sent at creation were dropped. Real AWS accepts them on CreateCluster itself, not only through UpdateClusterSettings, and handleUpdateClusterSettings two methods away already parses them the right way. The effect was permanent drift for any client that configures a cluster at creation. terraform-provider-aws sends its setting block on create, then reads DescribeClusters back without it and proposes the same change on every plan after apply, forever. Parse settings in the handler the way the update handlers do, and pass them through a new createCluster overload. The existing overloads delegate, so the CloudFormation caller is untouched. Closes #2806
This commit is contained in:
1 parent
90d1a19310
commit
19013b8b63
3 files changed
+106
-1
No files matched your search
@@ -143,7 +143,8 @@ public class EcsJsonHandler {
|
||||
private Response handleCreateCluster(JsonNode req, String region) {
|
||||
String name = req.path("clusterName").asText(null);
|
||||
Map<String, String> tags = parseTagMap(req.path("tags"));
|
||||
EcsCluster cluster = service.createCluster(name, tags, region);
|
||||
List<ClusterSetting> settings = parseClusterSettings(req.path("settings"));
|
||||
EcsCluster cluster = service.createCluster(name, tags, settings, region);
|
||||
ObjectNode resp = objectMapper.createObjectNode();
|
||||
resp.set("cluster", clusterNode(cluster));
|
||||
return Response.ok(resp).build();
|
||||
|
||||
@@ -221,6 +221,20 @@ public class EcsService implements ContainerTeardown, ResourceProvider {
|
||||
}
|
||||
|
||||
public EcsCluster createCluster(String clusterName, Map<String, String> tags, String region) {
|
||||
return createCluster(clusterName, tags, null, region);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a cluster, applying any {@code settings} the request carried.
|
||||
*
|
||||
* <p>Real AWS accepts {@code settings} (containerInsights and friends) on CreateCluster itself,
|
||||
* not only through UpdateClusterSettings. Dropping them here meant a client that configured the
|
||||
* cluster at creation, such as terraform-provider-aws's {@code setting} block, saw
|
||||
* DescribeClusters come back without them and proposed the same change on every subsequent
|
||||
* plan, forever (issue #2806).
|
||||
*/
|
||||
public EcsCluster createCluster(String clusterName, Map<String, String> tags,
|
||||
List<ClusterSetting> settings, String region) {
|
||||
String name = (clusterName == null || clusterName.isBlank()) ? DEFAULT_CLUSTER : clusterName;
|
||||
String key = clusterKey(region, name);
|
||||
if (clusters.containsKey(key)) {
|
||||
@@ -233,6 +247,9 @@ public class EcsService implements ContainerTeardown, ResourceProvider {
|
||||
if (tags != null && !tags.isEmpty()) {
|
||||
cluster.setTags(new LinkedHashMap<>(tags));
|
||||
}
|
||||
if (settings != null && !settings.isEmpty()) {
|
||||
cluster.setSettings(new ArrayList<>(settings));
|
||||
}
|
||||
clusters.put(key, cluster);
|
||||
LOG.infov("Created ECS cluster: {0} in {1}", name, region);
|
||||
return cluster;
|
||||
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package io.github.hectorvent.floci.services.ecs;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
|
||||
/**
|
||||
* Issue #2806: CreateCluster dropped the request's {@code settings}, so a cluster configured at
|
||||
* creation came back from DescribeClusters without them. Clients that set settings on create, such
|
||||
* as terraform-provider-aws's {@code setting} block, then proposed the same change on every plan
|
||||
* after apply, because the state they read never matched the configuration they sent.
|
||||
*
|
||||
* <p>Real AWS accepts settings on CreateCluster itself, not only through UpdateClusterSettings.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class EcsCreateClusterSettingsIntegrationTest {
|
||||
|
||||
private static final String TARGET_PREFIX = "AmazonEC2ContainerServiceV20141113.";
|
||||
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static io.restassured.specification.RequestSpecification ecs(String action) {
|
||||
return given()
|
||||
.contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", TARGET_PREFIX + action);
|
||||
}
|
||||
|
||||
@Test
|
||||
void settingsGivenOnCreateAreReturnedByCreateAndSurviveToDescribe() {
|
||||
String cluster = "create-settings-" + Long.toString(System.nanoTime(), 36);
|
||||
|
||||
ecs("CreateCluster")
|
||||
.body("""
|
||||
{"clusterName": "%s",
|
||||
"settings": [{"name": "containerInsights", "value": "enabled"}]}
|
||||
""".formatted(cluster))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("cluster.clusterName", equalTo(cluster))
|
||||
.body("cluster.settings", hasSize(1))
|
||||
.body("cluster.settings[0].name", equalTo("containerInsights"))
|
||||
.body("cluster.settings[0].value", equalTo("enabled"));
|
||||
|
||||
// The drift the issue describes is not in the CreateCluster response but in what a later
|
||||
// read reports, which is what a client compares its configuration against.
|
||||
ecs("DescribeClusters")
|
||||
.body("""
|
||||
{"clusters": ["%s"]}
|
||||
""".formatted(cluster))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("clusters[0].settings", hasSize(1))
|
||||
.body("clusters[0].settings[0].name", equalTo("containerInsights"))
|
||||
.body("clusters[0].settings[0].value", equalTo("enabled"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterCreatedWithoutSettingsReportsNone() {
|
||||
// The absent case must stay absent rather than gaining an empty array, since a client
|
||||
// diffing its configuration would see that as a change too.
|
||||
String cluster = "create-nosettings-" + Long.toString(System.nanoTime(), 36);
|
||||
|
||||
ecs("CreateCluster")
|
||||
.body("""
|
||||
{"clusterName": "%s"}
|
||||
""".formatted(cluster))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("cluster.clusterName", equalTo(cluster))
|
||||
.body("cluster.settings", org.hamcrest.Matchers.nullValue());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user