Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 35aa73a

Browse files
authored
feat: namespace EC2 tags (#3523)
## 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
1 parent 1b24342 commit 35aa73a

File tree

9 files changed

+48
-22
lines changed

9 files changed

+48
-22
lines changed

Diff for: examples/default/.terraform.lock.hcl

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/default/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ module "runners" {
9999
}
100100

101101
module "webhook-github-app" {
102-
source = "../../modules/webhook-github-app"
102+
source = "../../modules/webhook-github-app"
103+
depends_on = [module.runners]
103104

104105
github_app = {
105106
key_base64 = var.github_app.key_base64

Diff for: examples/ephemeral/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ module "runners" {
8787
}
8888

8989
module "webhook-github-app" {
90-
source = "../../modules/webhook-github-app"
90+
source = "../../modules/webhook-github-app"
91+
depends_on = [module.runners]
9192

9293
github_app = {
9394
key_base64 = var.github_app.key_base64

Diff for: examples/multi-runner/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ module "multi-runner" {
4949
}
5050

5151
module "webhook-github-app" {
52-
source = "../../modules/webhook-github-app"
52+
source = "../../modules/webhook-github-app"
53+
depends_on = [module.multi-runner]
5354

5455
github_app = {
5556
key_base64 = var.github_app.key_base64

Diff for: examples/prebuilt/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ module "runners" {
6363
}
6464

6565
module "webhook-github-app" {
66-
source = "../../modules/webhook-github-app"
66+
source = "../../modules/webhook-github-app"
67+
depends_on = [module.runners]
6768

6869
github_app = {
6970
key_base64 = var.github_app.key_base64

Diff for: examples/ubuntu/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ module "runners" {
113113
}
114114

115115
module "webhook-github-app" {
116-
source = "../../modules/webhook-github-app"
116+
source = "../../modules/webhook-github-app"
117+
depends_on = [module.runners]
117118

118119
github_app = {
119120
key_base64 = var.github_app.key_base64

Diff for: examples/windows/main.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ module "runners" {
5555
}
5656

5757
module "webhook-github-app" {
58-
source = "../../modules/webhook-github-app"
58+
source = "../../modules/webhook-github-app"
59+
depends_on = [module.runners]
5960

6061
github_app = {
6162
key_base64 = var.github_app.key_base64

Diff for: lambdas/functions/control-plane/src/aws/runners.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const mockRunningInstances: DescribeInstancesResult = {
4141
{ Key: 'ghr:Application', Value: 'github-action-runner' },
4242
{ Key: 'ghr:runner_name_prefix', Value: RUNNER_NAME_PREFIX },
4343
{ Key: 'ghr:created_by', Value: 'scale-up-lambda' },
44-
{ Key: 'Type', Value: 'Org' },
45-
{ Key: 'Owner', Value: 'CoderToCat' },
44+
{ Key: 'ghr:Type', Value: 'Org' },
45+
{ Key: 'ghr:Owner', Value: 'CoderToCat' },
4646
],
4747
},
4848
],
@@ -80,8 +80,8 @@ describe('list instances', () => {
8080
expect(mockEC2Client).toHaveReceivedCommandWith(DescribeInstancesCommand, {
8181
Filters: [
8282
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
83-
{ Name: 'tag:Type', Values: ['Repo'] },
84-
{ Name: 'tag:Owner', Values: [REPO_NAME] },
83+
{ Name: 'tag:ghr:Type', Values: ['Repo'] },
84+
{ Name: 'tag:ghr:Owner', Values: [REPO_NAME] },
8585
{ Name: 'tag:ghr:Application', Values: ['github-action-runner'] },
8686
],
8787
});
@@ -93,8 +93,8 @@ describe('list instances', () => {
9393
expect(mockEC2Client).toHaveReceivedCommandWith(DescribeInstancesCommand, {
9494
Filters: [
9595
{ Name: 'instance-state-name', Values: ['running', 'pending'] },
96-
{ Name: 'tag:Type', Values: ['Org'] },
97-
{ Name: 'tag:Owner', Values: [ORG_NAME] },
96+
{ Name: 'tag:ghr:Type', Values: ['Org'] },
97+
{ Name: 'tag:ghr:Owner', Values: [ORG_NAME] },
9898
{ Name: 'tag:ghr:Application', Values: ['github-action-runner'] },
9999
],
100100
});
@@ -382,8 +382,8 @@ function expectedCreateFleetRequest(expectedValues: ExpectedFleetRequestValues):
382382
const tags = [
383383
{ Key: 'ghr:Application', Value: 'github-action-runner' },
384384
{ Key: 'ghr:created_by', Value: expectedValues.totalTargetCapacity > 1 ? 'pool-lambda' : 'scale-up-lambda' },
385-
{ Key: 'Type', Value: expectedValues.type },
386-
{ Key: 'Owner', Value: REPO_NAME },
385+
{ Key: 'ghr:Type', Value: expectedValues.type },
386+
{ Key: 'ghr:Owner', Value: REPO_NAME },
387387
];
388388
const request: CreateFleetCommandInput = {
389389
LaunchTemplateConfigs: [

Diff for: lambdas/functions/control-plane/src/aws/runners.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ function constructFilters(filters?: Runners.ListRunnerFilters): Ec2Filter[][] {
4141
ec2FiltersBase.push({ Name: 'tag:ghr:environment', Values: [filters.environment] });
4242
}
4343
if (filters.runnerType && filters.runnerOwner) {
44-
ec2FiltersBase.push({ Name: `tag:Type`, Values: [filters.runnerType] });
45-
ec2FiltersBase.push({ Name: `tag:Owner`, Values: [filters.runnerOwner] });
44+
ec2FiltersBase.push({ Name: `tag:ghr:Type`, Values: [filters.runnerType] });
45+
ec2FiltersBase.push({ Name: `tag:ghr:Owner`, Values: [filters.runnerOwner] });
4646
}
4747
}
4848

@@ -79,10 +79,10 @@ function getRunnerInfo(runningInstances: DescribeInstancesResult) {
7979
runners.push({
8080
instanceId: i.InstanceId as string,
8181
launchTime: i.LaunchTime,
82-
owner: i.Tags?.find((e) => e.Key === 'Owner')?.Value as string,
83-
type: i.Tags?.find((e) => e.Key === 'Type')?.Value as string,
84-
repo: i.Tags?.find((e) => e.Key === 'Repo')?.Value as string,
85-
org: i.Tags?.find((e) => e.Key === 'Org')?.Value as string,
82+
owner: i.Tags?.find((e) => e.Key === 'ghr:Owner')?.Value as string,
83+
type: i.Tags?.find((e) => e.Key === 'ghr:Type')?.Value as string,
84+
repo: i.Tags?.find((e) => e.Key === 'ghr:Repo')?.Value as string,
85+
org: i.Tags?.find((e) => e.Key === 'ghr:Org')?.Value as string,
8686
});
8787
}
8888
}
@@ -147,8 +147,8 @@ export async function createRunner(runnerParameters: Runners.RunnerInputParamete
147147
const tags = [
148148
{ Key: 'ghr:Application', Value: 'github-action-runner' },
149149
{ Key: 'ghr:created_by', Value: numberOfRunners === 1 ? 'scale-up-lambda' : 'pool-lambda' },
150-
{ Key: 'Type', Value: runnerParameters.runnerType },
151-
{ Key: 'Owner', Value: runnerParameters.runnerOwner },
150+
{ Key: 'ghr:Type', Value: runnerParameters.runnerType },
151+
{ Key: 'ghr:Owner', Value: runnerParameters.runnerOwner },
152152
];
153153

154154
let fleet: CreateFleetResult;

0 commit comments

Comments
 (0)