fix(ecs): create the initial CodeDeploy task set (#8464)

Creating an ECS service with the CODE_DEPLOY deployment controller now
creates its initial PRIMARY task set at 100 percent scale, as the ECS
guide describes. The set reuses the service scheduler's deployment ID, so
its running and pending counts follow the tasks the scheduler already
launches, and it reaches STEADY_STATE once they converge. CreateService,
DescribeServices and DescribeTaskSets return it, CODE_DEPLOY services
report an empty deployments list, and the set is removed with the
service. Task sets added through CreateTaskSet keep their simulated
counts.

Closes #8235
This commit is contained in:
Rashen Anupama authored and GitHub committed 2026-11-15 10:46:20 -04:00
1 parent 00fdb95ab5
commit 0a40ab728c
3 files changed
+154 -25

No files matched your search

@@ -8,8 +8,10 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.math.BigDecimal;
import java.time.Duration;
import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
@@ -76,6 +78,71 @@ class EcsDescribeServicesIntegrationTest {
"{\"cluster\":\"" + cluster + "\",\"services\":[\"" + service + "\"]}");
}
@Test
void codeDeployServiceStartsWithAPrimaryTaskSet() {
seedClusterAndTaskDef("blue-cluster", "blue-task");
Response created = call("CreateService", """
{"cluster":"blue-cluster","serviceName":"blue-service",
"taskDefinition":"blue-task","desiredCount":0,
"deploymentController":{"type":"CODE_DEPLOY"}}
""");
String taskDefinition = created.path("service.taskDefinition");
Response described = describe("blue-cluster", "blue-service");
described.then()
.body("services[0].taskSets", hasSize(1))
.body("services[0].taskSets[0].status", equalTo("PRIMARY"))
.body("services[0].taskSets[0].taskDefinition", equalTo(taskDefinition))
.body("services[0].taskSets[0].computedDesiredCount", equalTo(0))
.body("services[0].deployments", hasSize(0));
String taskSetArn = described.path("services[0].taskSets[0].taskSetArn");
created.then().body("service.taskSets[0].taskSetArn", equalTo(taskSetArn));
call("DescribeTaskSets", """
{"cluster":"blue-cluster","service":"blue-service"}
""").then().body("taskSets[0].taskSetArn", equalTo(taskSetArn));
}
@Test
void codeDeployPrimaryTaskSetOwnsTheScheduledWorkload() {
call("CreateCluster", """
{"clusterName":"blue-running-cluster"}
""");
call("RegisterTaskDefinition", """
{"family":"blue-running-task","networkMode":"awsvpc",
"requiresCompatibilities":["FARGATE"],"cpu":"256","memory":"512",
"containerDefinitions":[{"name":"web","image":"nginx"}]}
""");
Response created = call("CreateService", """
{"cluster":"blue-running-cluster","serviceName":"blue-running-service",
"taskDefinition":"blue-running-task","desiredCount":1,"launchType":"FARGATE",
"networkConfiguration":{"awsvpcConfiguration":{"subnets":["subnet-default-us-east-1-a"]}},
"deploymentController":{"type":"CODE_DEPLOY"}}
""");
String primaryId = created.path("service.taskSets[0].id");
await().atMost(Duration.ofSeconds(30)).untilAsserted(() ->
describe("blue-running-cluster", "blue-running-service").then()
.body("services[0].runningCount", equalTo(1))
.body("services[0].taskSets", hasSize(1))
.body("services[0].taskSets[0].id", equalTo(primaryId))
.body("services[0].taskSets[0].computedDesiredCount", equalTo(1))
.body("services[0].taskSets[0].runningCount", equalTo(1))
.body("services[0].taskSets[0].pendingCount", equalTo(0))
.body("services[0].taskSets[0].stabilityStatus", equalTo("STEADY_STATE")));
Response listed = call("ListTasks", """
{"cluster":"blue-running-cluster","serviceName":"blue-running-service"}
""");
listed.then().body("taskArns", hasSize(1));
String taskArn = listed.path("taskArns[0]");
call("DescribeTasks", """
{"cluster":"blue-running-cluster","tasks":["%s"]}
""".formatted(taskArn)).then().body("tasks[0].startedBy", equalTo(primaryId));
call("DeleteService", """
{"cluster":"blue-running-cluster","service":"blue-running-service","force":true}
""").then().body("service.taskSets", hasSize(0));
}
@Test
void describeServicesReportsExactlyOnePrimaryDeployment() {
seedClusterAndTaskDef("dep-cluster-1", "dep-td-1");