mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ecs): service members, service role and capacity provider management (#4037)
CreateService and UpdateService carry the members AWS documents on the Service shape, rather than dropping them: deploymentConfiguration, serviceRegistries, platformVersion and platformFamily, enableExecuteCommand, enableECSManagedTags, propagateTags, healthCheckGracePeriodSeconds, the role, and anything else the request sent, which round-trips verbatim. A client that reads back what it wrote sees no drift. UpdateService rolls a new deployment only for the members UpdateService documents as starting new tasks, a changed network configuration, load balancers, service registries or platformVersion, and applies the rest in place. An update replaces only the members it names, so a service created with placementConstraints and updated with placementStrategy alone keeps its constraints; a member the update does name is replaced outright, which is how an empty array clears one. A service role is accepted only where AWS accepts one: with a load balancer, and not with awsvpc networking. Capacity provider management follows the documented rules. A name is at most 255 letters, numbers, underscores and hyphens and is never prefixed with aws, ecs or fargate. A provider reports its ARN, its type and the autoScalingGroupProvider it was created with. DescribeCapacityProviders gates tags behind include: ["TAGS"] and reports an unresolvable name as a MISSING failure. DeleteCapacityProvider refuses the reserved FARGATE and FARGATE_SPOT providers, one still attached to a cluster and one still named in an active service's capacity provider strategy, and reports the deleted one through updateStatus so the SDK is never handed an unmappable CapacityProviderStatus. Split out of the Fargate launch surface PR, which keeps the capacity provider strategy distribution and the service task launch.
This commit is contained in:
1 parent
d227ef9195
commit
ace99b34b0
11 files changed
+782
-36
No files matched your search
+9
-5
@@ -102,13 +102,12 @@ class CloudFormationEcsCapacityIntegrationTest {
|
||||
.statusCode(200)
|
||||
.body(containsString("<StackStatus>UPDATE_COMPLETE</StackStatus>"));
|
||||
|
||||
// One provider still, carrying the updated tag value. The updated AutoScalingGroupProvider
|
||||
// is asserted in EcsCapacityCfnProvisionerTest instead: DescribeCapacityProviders does not
|
||||
// serialize autoScalingGroupProvider, so it is not observable here.
|
||||
// One provider still, carrying the updated tag value and the updated scaling target.
|
||||
String providers = describeCapacityProviders(providerName);
|
||||
assertThat(providers, containsString(providerName));
|
||||
assertThat(providers, containsString("infra"));
|
||||
assertThat(providers, not(containsString("platform")));
|
||||
assertThat(providers, containsString("\"targetCapacity\":40"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,7 +134,11 @@ class CloudFormationEcsCapacityIntegrationTest {
|
||||
assertThat(settled, containsString("<StackStatus>DELETE_COMPLETE</StackStatus>"));
|
||||
|
||||
// The capacity provider must be deregistered, not left behind by an unsupported delete.
|
||||
assertThat(describeCapacityProviders(providerName), not(containsString(providerName)));
|
||||
// A name that resolves to nothing comes back as a MISSING failure, so the provider is
|
||||
// gone when the describe returns no providers at all.
|
||||
String afterDelete = describeCapacityProviders(providerName);
|
||||
assertThat(afterDelete, containsString("\"capacityProviders\":[]"));
|
||||
assertThat(afterDelete, containsString("\"reason\":\"MISSING\""));
|
||||
}
|
||||
|
||||
private static String template(String clusterName, String providerName) {
|
||||
@@ -190,11 +193,12 @@ class CloudFormationEcsCapacityIntegrationTest {
|
||||
return xml.substring(xml.indexOf("<StackId>") + "<StackId>".length(), xml.indexOf("</StackId>"));
|
||||
}
|
||||
|
||||
/** Asks for TAGS explicitly: without the include, AWS leaves them out of the response. */
|
||||
private String describeCapacityProviders(String providerName) {
|
||||
return given()
|
||||
.header("X-Amz-Target", ECS_TARGET + "DescribeCapacityProviders")
|
||||
.contentType(ECS_CT)
|
||||
.body("{\"capacityProviders\":[\"" + providerName + "\"]}")
|
||||
.body("{\"capacityProviders\":[\"" + providerName + "\"],\"include\":[\"TAGS\"]}")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
|
||||
+185
@@ -425,8 +425,95 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
"the attachment must carry the details AWS reports, got: " + names);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCreatedServiceReportsTheDocumentedDefaults() {
|
||||
String family = seed("edge-service-defaults");
|
||||
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-defaults-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,\"launchType\":\"FARGATE\","
|
||||
+ NETWORK + "}", 200)
|
||||
.then()
|
||||
.body("service.propagateTags", equalTo("NONE"))
|
||||
.body("service.healthCheckGracePeriodSeconds", equalTo(0))
|
||||
.body("service.enableExecuteCommand", equalTo(false))
|
||||
.body("service.enableECSManagedTags", equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aServiceRoleIsOnlyPermittedWithALoadBalancerAndWithoutAwsvpc() {
|
||||
String family = seed("edge-service-role");
|
||||
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-role-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,\"launchType\":\"FARGATE\","
|
||||
+ NETWORK + ",\"role\":\"arn:aws:iam::000000000000:role/ecsServiceRole\"}", 400)
|
||||
.then().body("message", containsString("role parameter"));
|
||||
}
|
||||
|
||||
// ── Service updates ──────────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void onlyTheDocumentedUpdatesRollTheServiceDeployment() {
|
||||
String family = seed("edge-update-rolls");
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-roll-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,\"launchType\":\"FARGATE\","
|
||||
+ NETWORK + "}", 200);
|
||||
|
||||
String initial = deploymentId("edge-roll-svc");
|
||||
|
||||
// desiredCount and the exec switch are documented as not triggering a deployment.
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-roll-svc\","
|
||||
+ "\"desiredCount\":0,\"enableExecuteCommand\":true}", 200);
|
||||
assertEquals(initial, deploymentId("edge-roll-svc"),
|
||||
"desiredCount and enableExecuteCommand must not roll the deployment");
|
||||
|
||||
// A changed network configuration starts new tasks, so it rolls.
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-roll-svc\","
|
||||
+ "\"networkConfiguration\":{\"awsvpcConfiguration\":{\"subnets\":"
|
||||
+ "[\"subnet-default-us-east-1-b\"]}}}", 200);
|
||||
assertNotEquals(initial, deploymentId("edge-roll-svc"),
|
||||
"a changed network configuration must roll the deployment");
|
||||
|
||||
// platformVersion is documented as triggering a deployment, but only where it changes:
|
||||
// LATEST on a service already running the version LATEST resolves to is not a change.
|
||||
String rolled = deploymentId("edge-roll-svc");
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-roll-svc\","
|
||||
+ "\"platformVersion\":\"LATEST\"}", 200);
|
||||
assertEquals(rolled, deploymentId("edge-roll-svc"),
|
||||
"LATEST on a service already at the resolved version must not roll the deployment");
|
||||
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-roll-svc\","
|
||||
+ "\"platformVersion\":\"1.3.0\"}", 200)
|
||||
.then().body("service.platformVersion", equalTo("1.3.0"));
|
||||
assertNotEquals(rolled, deploymentId("edge-roll-svc"),
|
||||
"a changed platformVersion must roll the deployment");
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUpdateReplacesOnlyTheMembersItNames() {
|
||||
String family = seed("edge-update-members");
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-members-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,\"launchType\":\"FARGATE\","
|
||||
+ NETWORK + ",\"placementConstraints\":[{\"type\":\"distinctInstance\"}]}", 200)
|
||||
.then().body("service.placementConstraints[0].type", equalTo("distinctInstance"));
|
||||
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-members-svc\","
|
||||
+ "\"placementStrategy\":[{\"type\":\"spread\","
|
||||
+ "\"field\":\"attribute:ecs.availability-zone\"}]}", 200)
|
||||
.then().body("service.placementStrategy[0].type", equalTo("spread"))
|
||||
.body("service.placementConstraints[0].type", equalTo("distinctInstance"));
|
||||
|
||||
call("DescribeServices", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"services\":[\"edge-members-svc\"]}", 200)
|
||||
.then().body("services[0].placementConstraints[0].type", equalTo("distinctInstance"))
|
||||
.body("services[0].placementStrategy[0].type", equalTo("spread"));
|
||||
|
||||
// A member the update does name is replaced outright, which is how an empty array clears it.
|
||||
call("UpdateService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-members-svc\","
|
||||
+ "\"placementConstraints\":[]}", 200)
|
||||
.then().body("service.placementConstraints", hasSize(0))
|
||||
.body("service.placementStrategy[0].type", equalTo("spread"));
|
||||
}
|
||||
|
||||
private static String deploymentId(String serviceName) {
|
||||
return call("DescribeServices", "{\"cluster\":\"" + CLUSTER + "\",\"services\":[\""
|
||||
+ serviceName + "\"]}", 200)
|
||||
@@ -534,6 +621,104 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
|
||||
// ── Capacity providers ───────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void capacityProviderNamesCannotUseTheReservedPrefixes() {
|
||||
for (String reserved : List.of("aws-edge-cp", "ecs-edge-cp", "fargate-edge-cp")) {
|
||||
call("CreateCapacityProvider", "{\"name\":\"" + reserved + "\","
|
||||
+ "\"autoScalingGroupProvider\":{\"autoScalingGroupArn\":\"arn:aws:autoscaling:"
|
||||
+ "us-east-1:000000000000:autoScalingGroup:x:autoScalingGroupName/asg-x\"}}", 400)
|
||||
.then().body("message", containsString("prefixed"));
|
||||
}
|
||||
call("CreateCapacityProvider", "{\"name\":\"edge cp with spaces\","
|
||||
+ "\"autoScalingGroupProvider\":{\"autoScalingGroupArn\":\"arn:aws:autoscaling:"
|
||||
+ "us-east-1:000000000000:autoScalingGroup:x:autoScalingGroupName/asg-x\"}}", 400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCapacityProviderRoundTripsItsGroupAndGatesItsTags() {
|
||||
String name = "edge-cp-roundtrip";
|
||||
call("CreateCapacityProvider", "{\"name\":\"" + name + "\","
|
||||
+ "\"autoScalingGroupProvider\":{\"autoScalingGroupArn\":\"arn:aws:autoscaling:"
|
||||
+ "us-east-1:000000000000:autoScalingGroup:x:autoScalingGroupName/asg-x\","
|
||||
+ "\"managedScaling\":{\"status\":\"ENABLED\",\"targetCapacity\":75}},"
|
||||
+ "\"tags\":[{\"key\":\"owner\",\"value\":\"platform\"}]}", 200)
|
||||
.then()
|
||||
.body("capacityProvider.type", equalTo("EC2_AUTOSCALING"))
|
||||
.body("capacityProvider.capacityProviderArn", containsString("capacity-provider/" + name));
|
||||
|
||||
call("DescribeCapacityProviders", "{\"capacityProviders\":[\"" + name + "\"]}", 200)
|
||||
.then()
|
||||
.body("capacityProviders[0].autoScalingGroupProvider.managedScaling.targetCapacity",
|
||||
equalTo(75))
|
||||
// Tags are held back until the request asks for them.
|
||||
.body("capacityProviders[0].tags", nullValue());
|
||||
|
||||
call("DescribeCapacityProviders", "{\"capacityProviders\":[\"" + name
|
||||
+ "\"],\"include\":[\"TAGS\"]}", 200)
|
||||
.then().body("capacityProviders[0].tags", hasSize(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnknownCapacityProviderIsAFailureAndTheFargateOnesCannotBeDeleted() {
|
||||
call("DescribeCapacityProviders", "{\"capacityProviders\":[\"edge-cp-nope\"]}", 200)
|
||||
.then()
|
||||
.body("capacityProviders", hasSize(0))
|
||||
.body("failures", hasSize(1))
|
||||
.body("failures[0].reason", equalTo("MISSING"))
|
||||
.body("failures[0].arn", containsString("capacity-provider/edge-cp-nope"));
|
||||
|
||||
call("DescribeCapacityProviders", "{\"capacityProviders\":[\"FARGATE\"]}", 200)
|
||||
.then()
|
||||
.body("capacityProviders[0].type", equalTo("FARGATE"))
|
||||
.body("capacityProviders[0].capacityProviderArn",
|
||||
containsString("capacity-provider/FARGATE"));
|
||||
|
||||
call("DeleteCapacityProvider", "{\"capacityProvider\":\"FARGATE\"}", 400)
|
||||
.then().body("message", containsString("reserved"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCapacityProviderAttachedToAClusterCannotBeDeleted() {
|
||||
String cluster = "edge-cp-attached-cluster";
|
||||
String name = "edge-cp-attached";
|
||||
call("CreateCapacityProvider", "{\"name\":\"" + name + "\","
|
||||
+ "\"autoScalingGroupProvider\":{\"autoScalingGroupArn\":\"arn:aws:autoscaling:"
|
||||
+ "us-east-1:000000000000:autoScalingGroup:x:autoScalingGroupName/asg-x\"}}", 200);
|
||||
call("CreateCluster", "{\"clusterName\":\"" + cluster + "\",\"capacityProviders\":[\""
|
||||
+ name + "\"]}", 200);
|
||||
|
||||
call("DeleteCapacityProvider", "{\"capacityProvider\":\"" + name + "\"}", 400)
|
||||
.then().body("message", containsString(cluster));
|
||||
|
||||
call("PutClusterCapacityProviders", "{\"cluster\":\"" + cluster + "\","
|
||||
+ "\"capacityProviders\":[],\"defaultCapacityProviderStrategy\":[]}", 200);
|
||||
call("DeleteCapacityProvider", "{\"capacityProvider\":\"" + name + "\"}", 200)
|
||||
.then().body("capacityProvider.updateStatus", equalTo("DELETE_IN_PROGRESS"))
|
||||
// DELETE_IN_PROGRESS is an updateStatus, never one of the four status values.
|
||||
.body("capacityProvider.status", equalTo("ACTIVE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCapacityProviderInAServiceStrategyCannotBeDeleted() {
|
||||
String family = seed("edge-cp-in-service");
|
||||
String name = "edge-cp-in-strategy";
|
||||
call("CreateCapacityProvider", "{\"name\":\"" + name + "\","
|
||||
+ "\"autoScalingGroupProvider\":{\"autoScalingGroupArn\":\"arn:aws:autoscaling:"
|
||||
+ "us-east-1:000000000000:autoScalingGroup:y:autoScalingGroupName/asg-y\"}}", 200);
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"edge-cp-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0," + NETWORK + ","
|
||||
+ "\"capacityProviderStrategy\":[{\"capacityProvider\":\"" + name
|
||||
+ "\",\"weight\":1}]}", 200);
|
||||
|
||||
// The provider is in no cluster, so only the service's strategy holds the delete back.
|
||||
call("DeleteCapacityProvider", "{\"capacityProvider\":\"" + name + "\"}", 400)
|
||||
.then().body("message", containsString("edge-cp-svc"));
|
||||
|
||||
call("DeleteService", "{\"cluster\":\"" + CLUSTER + "\",\"service\":\"edge-cp-svc\"}", 200);
|
||||
call("DeleteCapacityProvider", "{\"capacityProvider\":\"" + name + "\"}", 200)
|
||||
.then().body("capacityProvider.updateStatus", equalTo("DELETE_IN_PROGRESS"));
|
||||
}
|
||||
|
||||
// ── Round trips the parser used to drop ──────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
+27
@@ -250,6 +250,33 @@ class EcsFargateTaskIntegrationTest {
|
||||
.then().body("message", containsString("Network Configuration must be provided"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createServiceReportsThePlatformAndExecCommandMembers() {
|
||||
String family = seed("fargate-service-members");
|
||||
call("CreateService", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"fargate-members-svc\","
|
||||
+ "\"taskDefinition\":\"" + family + "\",\"desiredCount\":0,\"launchType\":\"FARGATE\","
|
||||
+ NETWORK + ",\"platformVersion\":\"LATEST\",\"enableExecuteCommand\":true,"
|
||||
+ "\"enableECSManagedTags\":true,\"propagateTags\":\"SERVICE\","
|
||||
+ "\"healthCheckGracePeriodSeconds\":30,"
|
||||
+ "\"deploymentConfiguration\":{\"maximumPercent\":200,\"minimumHealthyPercent\":100}}", 200)
|
||||
.then()
|
||||
.body("service.platformVersion", equalTo("1.4.0"))
|
||||
.body("service.platformFamily", equalTo("Linux"))
|
||||
.body("service.enableExecuteCommand", equalTo(true))
|
||||
.body("service.enableECSManagedTags", equalTo(true))
|
||||
.body("service.propagateTags", equalTo("SERVICE"))
|
||||
.body("service.healthCheckGracePeriodSeconds", equalTo(30))
|
||||
.body("service.deploymentConfiguration.maximumPercent", equalTo(200))
|
||||
.body("service.deploymentConfiguration.minimumHealthyPercent", equalTo(100));
|
||||
|
||||
call("DescribeServices", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"services\":[\"fargate-members-svc\"]}", 200)
|
||||
.then()
|
||||
.body("services[0].platformVersion", equalTo("1.4.0"))
|
||||
.body("services[0].enableExecuteCommand", equalTo(true))
|
||||
.body("services[0].deploymentConfiguration.minimumHealthyPercent", equalTo(100));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createServiceOnACapacityProviderStrategyReportsItInsteadOfALaunchType() {
|
||||
String family = seed("fargate-service-strategy");
|
||||
|
||||
Reference in new issue
Block a user