Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runners): Remove Application legacy tag #2705

Merged
merged 5 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 8 additions & 49 deletions modules/runners/lambdas/runners/src/aws/runners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,6 @@ const mockRunningInstances: AWS.EC2.DescribeInstancesResult = {
},
],
};
const mockRunningInstancesLegacy: AWS.EC2.DescribeInstancesResult = {
Reservations: [
{
Instances: [
{
LaunchTime: new Date('2020-10-11T14:48:00.000+09:00'),
InstanceId: 'i-5678',
Tags: [
{ Key: 'Owner', Value: REPO_NAME },
{ Key: 'Type', Value: 'Repo' },
{ Key: 'Application', Value: 'github-action-runner' },
],
},
],
},
],
};

describe('list instances', () => {
beforeEach(() => {
Expand All @@ -60,37 +43,25 @@ describe('list instances', () => {
});

it('returns a list of instances', async () => {
mockDescribeInstances.promise
.mockReturnValueOnce(mockRunningInstances)
.mockReturnValueOnce(mockRunningInstancesLegacy);
mockDescribeInstances.promise.mockReturnValue(mockRunningInstances);
const resp = await listEC2Runners();
expect(resp.length).toBe(2);
expect(resp.length).toBe(1);
expect(resp).toContainEqual({
instanceId: 'i-1234',
launchTime: new Date('2020-10-10T14:48:00.000+09:00'),
type: 'Org',
owner: 'CoderToCat',
});
expect(resp).toContainEqual({
instanceId: 'i-5678',
launchTime: new Date('2020-10-11T14:48:00.000+09:00'),
type: 'Repo',
owner: REPO_NAME,
});
});

it('calls EC2 describe instances', async () => {
mockDescribeInstances.promise
.mockReturnValueOnce(mockRunningInstances)
.mockReturnValueOnce(mockRunningInstancesLegacy);
mockDescribeInstances.promise.mockReturnValueOnce(mockRunningInstances);
await listEC2Runners();
expect(mockEC2.describeInstances).toBeCalled();
});

it('filters instances on repo name', async () => {
mockDescribeInstances.promise
.mockReturnValueOnce(mockRunningInstances)
.mockReturnValueOnce(mockRunningInstancesLegacy);
mockDescribeInstances.promise.mockReturnValueOnce(mockRunningInstances);
await listEC2Runners({ runnerType: 'Repo', runnerOwner: REPO_NAME, environment: undefined });
expect(mockEC2.describeInstances).toBeCalledWith({
Filters: [
Expand All @@ -100,20 +71,10 @@ describe('list instances', () => {
{ Name: 'tag:ghr:Application', Values: ['github-action-runner'] },
],
});
expect(mockEC2.describeInstances).toBeCalledWith({
Filters: [
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
{ Name: 'tag:Type', Values: ['Repo'] },
{ Name: 'tag:Owner', Values: [REPO_NAME] },
{ Name: 'tag:Application', Values: ['github-action-runner'] },
],
});
});

it('filters instances on org name', async () => {
mockDescribeInstances.promise
.mockReturnValueOnce(mockRunningInstances)
.mockReturnValueOnce(mockRunningInstancesLegacy);
mockDescribeInstances.promise.mockReturnValueOnce(mockRunningInstances);
await listEC2Runners({ runnerType: 'Org', runnerOwner: ORG_NAME, environment: undefined });
expect(mockEC2.describeInstances).toBeCalledWith({
Filters: [
Expand All @@ -126,9 +87,7 @@ describe('list instances', () => {
});

it('filters instances on environment', async () => {
mockDescribeInstances.promise
.mockReturnValueOnce(mockRunningInstances)
.mockReturnValueOnce(mockRunningInstancesLegacy);
mockDescribeInstances.promise.mockReturnValueOnce(mockRunningInstances);
await listEC2Runners({ environment: ENVIRONMENT });
expect(mockEC2.describeInstances).toBeCalledWith({
Filters: [
Expand Down Expand Up @@ -156,7 +115,7 @@ describe('list instances', () => {
},
],
};
mockDescribeInstances.promise.mockReturnValueOnce(noInstances).mockReturnValueOnce(noInstances);
mockDescribeInstances.promise.mockReturnValueOnce(noInstances);
const resp = await listEC2Runners();
expect(resp.length).toBe(0);
});
Expand All @@ -175,7 +134,7 @@ describe('list instances', () => {
},
],
};
mockDescribeInstances.promise.mockReturnValueOnce(noInstances).mockReturnValue({});
mockDescribeInstances.promise.mockReturnValueOnce(noInstances);
const resp = await listEC2Runners();
expect(resp.length).toBe(1);
});
Expand Down
5 changes: 1 addition & 4 deletions modules/runners/lambdas/runners/src/aws/runners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ function constructFilters(filters?: ListRunnerFilters): Ec2Filter[][] {
}
}

// ***Deprecation Notice***
// Support for legacy `Application` tag keys
// will be removed in next major release.
for (const key of ['tag:ghr:Application', 'tag:Application']) {
for (const key of ['tag:ghr:Application']) {
const filter = [...ec2FiltersBase];
filter.push({ Name: key, Values: ['github-action-runner'] });
ec2Filters.push(filter);
Expand Down