mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ecs): report serviceConnectConfiguration on the service's deployment (#3662)
* fix(ecs): report serviceConnectConfiguration on the service's deployment CreateService and UpdateService accepted a serviceConnectConfiguration and dropped it. DescribeServices then reported nothing, so a client that sets one saw it missing on every read. AWS's Service shape declares no serviceConnectConfiguration member. The field lives on Deployment, which is where a generated client reads it and where Terraform's aws_ecs_service reads it. Storing it on the service and reporting it on each deployments[] entry matches the model, and a client that reads it back no longer sees a pending change on every plan. The widest createService and updateService overloads take the configuration; the previous signatures delegate to them, so existing callers are unchanged. * fix(ecs): roll the deployment when serviceConnectConfiguration changes Review feedback on #3662. UpdateServiceRequest.serviceConnectConfiguration is documented as "This parameter triggers a new service deployment", and the rollover below only fired on a task-definition change or forceNewDeployment. A Service-Connect-only change therefore reported the new configuration under the old deployment id and skipped SERVICE_DEPLOYMENT_STARTED. updateService now treats a changed configuration as deployment-triggering state, alongside the two conditions already there. An omitted parameter stays a no-op, and resending an identical configuration is not a change. Three tests cover it. A changed configuration rolls the deployment id, an identical one does not, and an update that omits the parameter does not. None of the original four asserted on deploymentId, which is why they passed.
This commit is contained in:
1 parent
7813d14ee4
commit
7da4ee0b6b
5 files changed
+265
-3
No files matched your search
+180
@@ -0,0 +1,180 @@
|
||||
package io.github.hectorvent.floci.services.ecs;
|
||||
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* DescribeServices has to report a Service Connect configuration on each {@code deployments[]}
|
||||
* entry. AWS's {@code Service} shape declares no {@code serviceConnectConfiguration} member, so a
|
||||
* generated client parses the field only at the deployment location and drops it anywhere else.
|
||||
* Terraform's provider reads it from there too, and reports a service with no readable value as a
|
||||
* pending change on every plan.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class EcsServiceConnectConfigurationIntegrationTest {
|
||||
|
||||
private static final String TARGET = "AmazonEC2ContainerServiceV20141113.";
|
||||
private static final String CT = "application/x-amz-json-1.1";
|
||||
private static final String CLUSTER = "sc-cluster";
|
||||
private static final String FAMILY = "sc-fam";
|
||||
|
||||
private static final String CONFIG = "{\"enabled\":true,\"namespace\":\"sc-ns\","
|
||||
+ "\"services\":[{\"portName\":\"http\",\"discoveryName\":\"web\","
|
||||
+ "\"clientAliases\":[{\"port\":8080,\"dnsName\":\"web.sc-ns\"}]}]}";
|
||||
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
private static Response call(String action, String body) {
|
||||
return given().contentType(CT).header("X-Amz-Target", TARGET + action)
|
||||
.body(body)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().response();
|
||||
}
|
||||
|
||||
private static void seed() {
|
||||
call("CreateCluster", "{\"clusterName\":\"" + CLUSTER + "\"}");
|
||||
call("RegisterTaskDefinition", "{\"family\":\"" + FAMILY + "\","
|
||||
+ "\"containerDefinitions\":[{\"name\":\"web\",\"image\":\"nginx\",\"memory\":128}]}");
|
||||
}
|
||||
|
||||
private static Response describe(String serviceName) {
|
||||
return call("DescribeServices", "{\"cluster\":\"" + CLUSTER + "\","
|
||||
+ "\"services\":[\"" + serviceName + "\"]}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createService_reportsServiceConnectConfigurationOnTheDeployment() {
|
||||
seed();
|
||||
String name = "sc-create";
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + name + "\","
|
||||
+ "\"taskDefinition\":\"" + FAMILY + "\",\"desiredCount\":0,"
|
||||
+ "\"serviceConnectConfiguration\":" + CONFIG + "}");
|
||||
|
||||
Response described = describe(name);
|
||||
String base = "services[0].deployments[0].serviceConnectConfiguration.";
|
||||
|
||||
assertEquals(true, described.jsonPath().getBoolean(base + "enabled"));
|
||||
assertEquals("sc-ns", described.jsonPath().getString(base + "namespace"));
|
||||
assertEquals("http", described.jsonPath().getString(base + "services[0].portName"));
|
||||
assertEquals("web", described.jsonPath().getString(base + "services[0].discoveryName"));
|
||||
assertEquals("web.sc-ns",
|
||||
described.jsonPath().getString(base + "services[0].clientAliases[0].dnsName"));
|
||||
assertEquals(8080, described.jsonPath().getInt(base + "services[0].clientAliases[0].port"));
|
||||
|
||||
// The Service shape has no member for it, so nothing should appear at the top level.
|
||||
assertNull(described.jsonPath().get("services[0].serviceConnectConfiguration"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateService_replacesTheStoredServiceConnectConfiguration() {
|
||||
seed();
|
||||
String name = "sc-update";
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + name + "\","
|
||||
+ "\"taskDefinition\":\"" + FAMILY + "\",\"desiredCount\":0,"
|
||||
+ "\"serviceConnectConfiguration\":" + CONFIG + "}");
|
||||
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"" + name + "\","
|
||||
+ "\"serviceConnectConfiguration\":{\"enabled\":false}}");
|
||||
|
||||
Response described = describe(name);
|
||||
String base = "services[0].deployments[0].serviceConnectConfiguration.";
|
||||
assertEquals(false, described.jsonPath().getBoolean(base + "enabled"));
|
||||
assertNull(described.jsonPath().get(base + "namespace"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateService_withoutTheField_keepsTheStoredConfiguration() {
|
||||
seed();
|
||||
String name = "sc-keep";
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + name + "\","
|
||||
+ "\"taskDefinition\":\"" + FAMILY + "\",\"desiredCount\":0,"
|
||||
+ "\"serviceConnectConfiguration\":" + CONFIG + "}");
|
||||
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"" + name + "\","
|
||||
+ "\"desiredCount\":0}");
|
||||
|
||||
Response described = describe(name);
|
||||
assertEquals("sc-ns", described.jsonPath()
|
||||
.getString("services[0].deployments[0].serviceConnectConfiguration.namespace"));
|
||||
}
|
||||
|
||||
private static String deploymentId(String serviceName) {
|
||||
return describe(serviceName).jsonPath().getString("services[0].deployments[0].id");
|
||||
}
|
||||
|
||||
// UpdateServiceRequest.serviceConnectConfiguration is documented as triggering a new service
|
||||
// deployment, so a changed configuration must not be reported under the old deployment id.
|
||||
@Test
|
||||
void updateService_changingTheConfiguration_rollsTheDeployment() {
|
||||
seed();
|
||||
String name = "sc-rolls";
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + name + "\","
|
||||
+ "\"taskDefinition\":\"" + FAMILY + "\",\"desiredCount\":0,"
|
||||
+ "\"serviceConnectConfiguration\":" + CONFIG + "}");
|
||||
String before = deploymentId(name);
|
||||
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"" + name + "\","
|
||||
+ "\"serviceConnectConfiguration\":{\"enabled\":false}}");
|
||||
|
||||
assertNotEquals(before, deploymentId(name),
|
||||
"a Service Connect change starts a new deployment");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateService_resendingTheSameConfiguration_keepsTheDeployment() {
|
||||
seed();
|
||||
String name = "sc-same";
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + name + "\","
|
||||
+ "\"taskDefinition\":\"" + FAMILY + "\",\"desiredCount\":0,"
|
||||
+ "\"serviceConnectConfiguration\":" + CONFIG + "}");
|
||||
String before = deploymentId(name);
|
||||
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"" + name + "\","
|
||||
+ "\"serviceConnectConfiguration\":" + CONFIG + "}");
|
||||
|
||||
assertEquals(before, deploymentId(name),
|
||||
"resending an identical configuration is not a change");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateService_withoutTheField_keepsTheDeployment() {
|
||||
seed();
|
||||
String name = "sc-untouched";
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + name + "\","
|
||||
+ "\"taskDefinition\":\"" + FAMILY + "\",\"desiredCount\":0,"
|
||||
+ "\"serviceConnectConfiguration\":" + CONFIG + "}");
|
||||
String before = deploymentId(name);
|
||||
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"" + name + "\","
|
||||
+ "\"desiredCount\":0}");
|
||||
|
||||
assertEquals(before, deploymentId(name),
|
||||
"omitting the parameter is not a change");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createService_withoutTheField_reportsNoServiceConnectConfiguration() {
|
||||
seed();
|
||||
String name = "sc-absent";
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + name + "\","
|
||||
+ "\"taskDefinition\":\"" + FAMILY + "\",\"desiredCount\":0}");
|
||||
|
||||
Response described = describe(name);
|
||||
assertTrue(described.jsonPath().getList("services[0].deployments").size() == 1);
|
||||
assertNull(described.jsonPath()
|
||||
.get("services[0].deployments[0].serviceConnectConfiguration"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user