Skip to content

Commit 7d4304e

Browse files
authored
fix(ecs): only show tasks from the selected container (#3598)
## Problem See #3589 ## Solution Add `serviceName` to the `ListTasks` operation Note that previously container instances spawned in a cluster but outside of a service were shown in the quick pick as well. If there is a valid use-case for this, we should consider adding some task-orientated UI.
1 parent e763827 commit 7d4304e

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "ECS: tasks from unrelated task definitions are shown in the \"Open Terminal...\" command"
4+
}

src/ecs/model.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ interface ContainerDescription extends ECS.ContainerDefinition {
3333
export class Container {
3434
public readonly id = this.description.name!
3535

36-
public constructor(private readonly client: DefaultEcsClient, public readonly description: ContainerDescription) {}
36+
public constructor(
37+
private readonly client: DefaultEcsClient,
38+
public readonly serviceName: string,
39+
public readonly description: ContainerDescription
40+
) {}
3741

3842
public async listTasks() {
39-
const resp = await this.client.listTasks({ cluster: this.description.clusterArn })
43+
const resp = await this.client.listTasks({
44+
cluster: this.description.clusterArn,
45+
serviceName: this.serviceName,
46+
})
4047
const tasks = await this.client.describeTasks(this.description.clusterArn, resp)
4148

4249
return tasks.filter(createValidTaskFilter(this.description.name!))
@@ -81,7 +88,7 @@ export class Service {
8188

8289
return containers.map(
8390
c =>
84-
new Container(this.client, {
91+
new Container(this.client, this.description.serviceName!, {
8592
...c,
8693
enableExecuteCommand: this.description.enableExecuteCommand,
8794
taskRoleArn: definition.taskRoleArn!,

src/test/ecs/model.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ const containerData = {
2929
const getClient = () => stub(DefaultEcsClient, { regionCode: 'us-east-1' })
3030

3131
describe('Container', function () {
32+
const serviceName = 'my-service'
33+
3234
it('has a tree item', async function () {
33-
const container = new Container(getClient(), containerData)
35+
const container = new Container(getClient(), serviceName, containerData)
3436

3537
await assertTreeItem(container, {
3638
label: containerData.name,
@@ -39,7 +41,7 @@ describe('Container', function () {
3941
})
4042

4143
it('has a tree item when "enableExecuteCommand" is set', async function () {
42-
const container = new Container(getClient(), { ...containerData, enableExecuteCommand: true })
44+
const container = new Container(getClient(), serviceName, { ...containerData, enableExecuteCommand: true })
4345

4446
await assertTreeItem(container, {
4547
label: containerData.name,

src/test/ecs/wizards/executeCommand.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('CreateServiceWizard', function () {
1313
let tester: WizardTester<CommandWizardState>
1414

1515
const createContainer = () =>
16-
new Container(stub(DefaultEcsClient, { regionCode: '' }), { clusterArn: '', taskRoleArn: '' })
16+
new Container(stub(DefaultEcsClient, { regionCode: '' }), '', { clusterArn: '', taskRoleArn: '' })
1717

1818
beforeEach(function () {
1919
tester = createWizardTester(new CommandWizard(createContainer(), false))

0 commit comments

Comments
 (0)