Skip to content

Commit

Permalink
feat: namespace EC2 tags
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm committed Oct 3, 2023
1 parent 726565f commit bcc8101
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions lambdas/functions/control-plane/src/aws/runners.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const mockRunningInstances: DescribeInstancesResult = {
{ Key: 'ghr:Application', Value: 'github-action-runner' },
{ Key: 'ghr:runner_name_prefix', Value: RUNNER_NAME_PREFIX },
{ Key: 'ghr:created_by', Value: 'scale-up-lambda' },
{ Key: 'Type', Value: 'Org' },
{ Key: 'Owner', Value: 'CoderToCat' },
{ Key: 'ghr:Type', Value: 'Org' },
{ Key: 'ghr:Owner', Value: 'CoderToCat' },
],
},
],
Expand Down Expand Up @@ -80,8 +80,8 @@ describe('list instances', () => {
expect(mockEC2Client).toHaveReceivedCommandWith(DescribeInstancesCommand, {
Filters: [
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
{ Name: 'tag:Type', Values: ['Repo'] },
{ Name: 'tag:Owner', Values: [REPO_NAME] },
{ Name: 'tag:ghr:Type', Values: ['Repo'] },
{ Name: 'tag:ghr:Owner', Values: [REPO_NAME] },
{ Name: 'tag:ghr:Application', Values: ['github-action-runner'] },
],
});
Expand All @@ -93,8 +93,8 @@ describe('list instances', () => {
expect(mockEC2Client).toHaveReceivedCommandWith(DescribeInstancesCommand, {
Filters: [
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
{ Name: 'tag:Type', Values: ['Org'] },
{ Name: 'tag:Owner', Values: [ORG_NAME] },
{ Name: 'tag:ghr:Type', Values: ['Org'] },
{ Name: 'tag:ghr:Owner', Values: [ORG_NAME] },
{ Name: 'tag:ghr:Application', Values: ['github-action-runner'] },
],
});
Expand Down Expand Up @@ -382,8 +382,8 @@ function expectedCreateFleetRequest(expectedValues: ExpectedFleetRequestValues):
const tags = [
{ Key: 'ghr:Application', Value: 'github-action-runner' },
{ Key: 'ghr:created_by', Value: expectedValues.totalTargetCapacity > 1 ? 'pool-lambda' : 'scale-up-lambda' },
{ Key: 'Type', Value: expectedValues.type },
{ Key: 'Owner', Value: REPO_NAME },
{ Key: 'ghr:Type', Value: expectedValues.type },
{ Key: 'ghr:Owner', Value: REPO_NAME },
];
const request: CreateFleetCommandInput = {
LaunchTemplateConfigs: [
Expand Down
16 changes: 8 additions & 8 deletions lambdas/functions/control-plane/src/aws/runners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function constructFilters(filters?: Runners.ListRunnerFilters): Ec2Filter[][] {
ec2FiltersBase.push({ Name: 'tag:ghr:environment', Values: [filters.environment] });
}
if (filters.runnerType && filters.runnerOwner) {
ec2FiltersBase.push({ Name: `tag:Type`, Values: [filters.runnerType] });
ec2FiltersBase.push({ Name: `tag:Owner`, Values: [filters.runnerOwner] });
ec2FiltersBase.push({ Name: `tag:ghr:Type`, Values: [filters.runnerType] });
ec2FiltersBase.push({ Name: `tag:ghr:Owner`, Values: [filters.runnerOwner] });
}
}

Expand Down Expand Up @@ -79,10 +79,10 @@ function getRunnerInfo(runningInstances: DescribeInstancesResult) {
runners.push({
instanceId: i.InstanceId as string,
launchTime: i.LaunchTime,
owner: i.Tags?.find((e) => e.Key === 'Owner')?.Value as string,
type: i.Tags?.find((e) => e.Key === 'Type')?.Value as string,
repo: i.Tags?.find((e) => e.Key === 'Repo')?.Value as string,
org: i.Tags?.find((e) => e.Key === 'Org')?.Value as string,
owner: i.Tags?.find((e) => e.Key === 'ghr:Owner')?.Value as string,
type: i.Tags?.find((e) => e.Key === 'ghr:Type')?.Value as string,
repo: i.Tags?.find((e) => e.Key === 'ghr:Repo')?.Value as string,
org: i.Tags?.find((e) => e.Key === 'ghr:Org')?.Value as string,
});
}
}
Expand Down Expand Up @@ -147,8 +147,8 @@ export async function createRunner(runnerParameters: Runners.RunnerInputParamete
const tags = [
{ Key: 'ghr:Application', Value: 'github-action-runner' },
{ Key: 'ghr:created_by', Value: numberOfRunners === 1 ? 'scale-up-lambda' : 'pool-lambda' },
{ Key: 'Type', Value: runnerParameters.runnerType },
{ Key: 'Owner', Value: runnerParameters.runnerOwner },
{ Key: 'ghr:Type', Value: runnerParameters.runnerType },
{ Key: 'ghr:Owner', Value: runnerParameters.runnerOwner },
];

let fleet: CreateFleetResult;
Expand Down

0 comments on commit bcc8101

Please sign in to comment.