mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ecs): accept a service ARN in ListTasks (#4859)
ListTasks looked the serviceName filter up by the string it was given, so only a bare service name matched. A service ARN, which is what CDK passes, found no service, and the call returned an empty taskArns list even while the service had running tasks. The filter now goes through extractServiceName, the helper UpdateService and DeleteService already use, which keeps the last path segment. A name, a full service/<cluster>/<name> ARN, the older service/<name> ARN and <cluster>/<name> all resolve to the service in the request's cluster. AWS accepts each of these forms. An unknown service still lists nothing, which is unchanged.
This commit is contained in:
1 parent
ddc47a465d
commit
5a8694e97a
3 files changed
+57
-2
No files matched your search
@@ -2186,9 +2186,10 @@ public class EcsService implements ContainerTeardown, ResourceProvider, Resettab
|
||||
: (serviceName != null ? clusters.get(clusterKey(region, DEFAULT_CLUSTER)) : null);
|
||||
String clusterArn = clusterRef != null ? cluster.getClusterArn() : null;
|
||||
// A serviceName filter selects the service's own tasks, so it resolves through the
|
||||
// reconciler-stamped ownership rather than the caller-supplied group.
|
||||
// reconciler-stamped ownership rather than the caller-supplied group. It may be the
|
||||
// service's name or its ARN; as on AWS, only the last path segment names the service.
|
||||
EcsServiceModel svc = serviceName != null && cluster != null
|
||||
? services.get(serviceKey(region, cluster.getClusterName(), serviceName))
|
||||
? services.get(serviceKey(region, cluster.getClusterName(), extractServiceName(serviceName)))
|
||||
: null;
|
||||
String family = request.getFamily();
|
||||
LaunchType launchType = request.getLaunchType();
|
||||
|
||||
+31
@@ -6,10 +6,12 @@ import io.restassured.response.Response;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
@@ -524,6 +526,35 @@ class EcsFargateEdgeCaseIntegrationTest {
|
||||
"the last page carries no token");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTasksTakesTheServiceNameOrItsArn() {
|
||||
String family = seed("edge-list-service");
|
||||
String serviceArn = call("CreateService", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"serviceName\":\"edge-list-svc\",\"taskDefinition\":\"" + family
|
||||
+ "\",\"desiredCount\":1,\"launchType\":\"FARGATE\"," + NETWORK + "}", 200)
|
||||
.jsonPath().getString("service.serviceArn");
|
||||
String idleArn = call("CreateService", "{\"cluster\":\"" + CLUSTER
|
||||
+ "\",\"serviceName\":\"edge-list-idle-svc\",\"taskDefinition\":\"" + family
|
||||
+ "\",\"desiredCount\":0,\"launchType\":\"FARGATE\"," + NETWORK + "}", 200)
|
||||
.jsonPath().getString("service.serviceArn");
|
||||
|
||||
// The reconciler launches the service's task on its own schedule.
|
||||
await().atMost(Duration.ofSeconds(30)).pollInterval(Duration.ofMillis(200))
|
||||
.until(() -> listTaskArns("edge-list-svc").size() == 1);
|
||||
List<String> byName = listTaskArns("edge-list-svc");
|
||||
|
||||
assertEquals(byName, listTaskArns(serviceArn), "the service ARN must select the same task");
|
||||
assertEquals(byName, listTaskArns(serviceArn.replace("service/" + CLUSTER + "/", "service/")),
|
||||
"the old service/<name> ARN format must select it too");
|
||||
assertEquals(List.of(), listTaskArns(idleArn),
|
||||
"another service's ARN must not select this service's task");
|
||||
}
|
||||
|
||||
private static List<String> listTaskArns(String serviceName) {
|
||||
return call("ListTasks", "{\"cluster\":\"" + CLUSTER + "\",\"serviceName\":\"" + serviceName
|
||||
+ "\"}", 200).jsonPath().getList("taskArns");
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyTheDocumentedUpdatesRollTheServiceDeployment() {
|
||||
String family = seed("edge-update-rolls");
|
||||
|
||||
+23
@@ -149,6 +149,29 @@ class EcsServiceTaskOwnershipTest {
|
||||
"a task that merely names the service as its group is not service-owned");
|
||||
}
|
||||
|
||||
@Test
|
||||
void listTasksByServiceArnListsTheSameTasksAsByServiceName() {
|
||||
EcsService service = newMockModeService();
|
||||
service.createCluster("arn-cluster", REGION);
|
||||
registerTaskDef(service);
|
||||
String serviceArn = service.createService("arn-cluster", "svc", "own-fam", 1, LaunchType.FARGATE,
|
||||
List.of(), null, REGION).getServiceArn();
|
||||
String idleArn = service.createService("arn-cluster", "idle", "own-fam", 0, LaunchType.FARGATE,
|
||||
List.of(), null, REGION).getServiceArn();
|
||||
service.reconcileServices();
|
||||
|
||||
List<String> byName = service.listTasks("arn-cluster", null, null, "svc", REGION);
|
||||
String shortArn = serviceArn.replace("service/arn-cluster/", "service/");
|
||||
|
||||
assertEquals(1, byName.size(), "the service runs its one task");
|
||||
assertEquals(byName, service.listTasks("arn-cluster", null, null, serviceArn, REGION),
|
||||
"the service ARN selects the same tasks as the service name");
|
||||
assertEquals(byName, service.listTasks("arn-cluster", null, null, shortArn, REGION),
|
||||
"the old service/<name> ARN format selects them too");
|
||||
assertEquals(List.of(), service.listTasks("arn-cluster", null, null, idleArn, REGION),
|
||||
"another service's ARN does not select this service's tasks");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSameNamedClusterInAnotherRegionIsNotSweptIntoReconciliation() {
|
||||
EcsService service = newMockModeService();
|
||||
|
||||
Reference in new issue
Block a user