Skip to content

Commit

Permalink
feat: namespace EC2 tags (#3523)
Browse files Browse the repository at this point in the history
## Problem
The runners are still using a some ec2 tags such as Type, Repo, Owner
for selecting runners controlled by the control plane. Since the tags
are not namespaced they can conflict existing tags used in an AWS
account. This PR is namespacing the tags like the other tags used by the
module with `ghr`.

## Verification

- [x] - deploy single runner (root) module. Check runners getting proper
started and terminated
- [x] - deploy multi runner module. Check runners getting proper started
and terminated
  • Loading branch information
npalm authored Oct 4, 2023
1 parent 1b24342 commit 35aa73a
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 22 deletions.
20 changes: 20 additions & 0 deletions examples/default/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ module "runners" {
}

module "webhook-github-app" {
source = "../../modules/webhook-github-app"
source = "../../modules/webhook-github-app"
depends_on = [module.runners]

github_app = {
key_base64 = var.github_app.key_base64
Expand Down
3 changes: 2 additions & 1 deletion examples/ephemeral/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ module "runners" {
}

module "webhook-github-app" {
source = "../../modules/webhook-github-app"
source = "../../modules/webhook-github-app"
depends_on = [module.runners]

github_app = {
key_base64 = var.github_app.key_base64
Expand Down
3 changes: 2 additions & 1 deletion examples/multi-runner/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module "multi-runner" {
}

module "webhook-github-app" {
source = "../../modules/webhook-github-app"
source = "../../modules/webhook-github-app"
depends_on = [module.multi-runner]

github_app = {
key_base64 = var.github_app.key_base64
Expand Down
3 changes: 2 additions & 1 deletion examples/prebuilt/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ module "runners" {
}

module "webhook-github-app" {
source = "../../modules/webhook-github-app"
source = "../../modules/webhook-github-app"
depends_on = [module.runners]

github_app = {
key_base64 = var.github_app.key_base64
Expand Down
3 changes: 2 additions & 1 deletion examples/ubuntu/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ module "runners" {
}

module "webhook-github-app" {
source = "../../modules/webhook-github-app"
source = "../../modules/webhook-github-app"
depends_on = [module.runners]

github_app = {
key_base64 = var.github_app.key_base64
Expand Down
3 changes: 2 additions & 1 deletion examples/windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module "runners" {
}

module "webhook-github-app" {
source = "../../modules/webhook-github-app"
source = "../../modules/webhook-github-app"
depends_on = [module.runners]

github_app = {
key_base64 = var.github_app.key_base64
Expand Down
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 35aa73a

Please sign in to comment.