-
Notifications
You must be signed in to change notification settings - Fork 661
fix(runners): Namespace Application
tag
#2182
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
Changes from all commits
ac26958
2d805c8
c10dc91
95abc52
707012f
1bfafc5
321cd35
af34741
66bcc58
8baf486
1eb3612
069d87f
5e7f145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,24 +45,47 @@ export interface RunnerInputParameters { | |
amiIdSsmParameterName?: string; | ||
} | ||
|
||
interface Ec2Filter { | ||
Name: string; | ||
Values: string[]; | ||
} | ||
|
||
export async function listEC2Runners(filters: ListRunnerFilters | undefined = undefined): Promise<RunnerList[]> { | ||
const ec2Statuses = filters?.statuses ? filters.statuses : ['running', 'pending']; | ||
const ec2 = new EC2(); | ||
const ec2Filters = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if it is really needed, but back in the days we have implemented here hardcoded that if not set a filter. A filter got enforced. I think this was done to avoid the scale down can terminate anything that is not owned. Don't like this hidden magic and we should got cleaned it at some moment. I also updated the tested to see the impact when we remove the depecrated tag There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which test did you update? I'll replicate and resolve. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Despite There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems this bug is being hit. I'll try to work up a fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not been able to find a work-around for the testing bug. @npalm any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I check the tests again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least I know what the problem is. When I remove the support vor the tag Application in (runner.ts). Merge the two mocks back in a single mock like before, returning 2 objects. The test "Instances with no tags." starts failing. Running the test in isolation is not causing a problem. So somehow the mocks are not resetting well. Was not able to find a solution, but this eems the issue. |
||
{ Name: 'tag:Application', Values: ['github-action-runner'] }, | ||
{ Name: 'instance-state-name', Values: ec2Statuses }, | ||
]; | ||
const ec2Filters = constructFilters(filters); | ||
const runners: RunnerList[] = []; | ||
for (const filter of ec2Filters) { | ||
runners.push(...(await getRunners(filter))); | ||
npalm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return runners; | ||
} | ||
|
||
function constructFilters(filters?: ListRunnerFilters): Ec2Filter[][] { | ||
const ec2Statuses = filters?.statuses ? filters.statuses : ['running', 'pending']; | ||
const ec2Filters: Ec2Filter[][] = []; | ||
const ec2FiltersBase = [{ Name: 'instance-state-name', Values: ec2Statuses }]; | ||
if (filters) { | ||
if (filters.environment !== undefined) { | ||
ec2Filters.push({ Name: 'tag:ghr:environment', Values: [filters.environment] }); | ||
ec2FiltersBase.push({ Name: 'tag:ghr:environment', Values: [filters.environment] }); | ||
} | ||
if (filters.runnerType && filters.runnerOwner) { | ||
ec2Filters.push({ Name: `tag:Type`, Values: [filters.runnerType] }); | ||
ec2Filters.push({ Name: `tag:Owner`, Values: [filters.runnerOwner] }); | ||
ec2FiltersBase.push({ Name: `tag:Type`, Values: [filters.runnerType] }); | ||
ec2FiltersBase.push({ Name: `tag:Owner`, Values: [filters.runnerOwner] }); | ||
} | ||
} | ||
|
||
// ***Deprecation Notice*** | ||
// Support for legacy `Application` tag keys | ||
// will be removed in next major release. | ||
for (const key of ['tag:ghr:Application', 'tag:Application']) { | ||
const filter = [...ec2FiltersBase]; | ||
filter.push({ Name: key, Values: ['github-action-runner'] }); | ||
ec2Filters.push(filter); | ||
} | ||
return ec2Filters; | ||
} | ||
|
||
async function getRunners(ec2Filters: Ec2Filter[]): Promise<RunnerList[]> { | ||
const ec2 = new EC2(); | ||
const runners: RunnerList[] = []; | ||
let nextToken; | ||
let hasNext = true; | ||
|
@@ -191,7 +214,7 @@ export async function createRunner(runnerParameters: RunnerInputParameters): Pro | |
{ | ||
ResourceType: 'instance', | ||
Tags: [ | ||
{ Key: 'Application', Value: 'github-action-runner' }, | ||
{ Key: 'ghr:Application', Value: 'github-action-runner' }, | ||
{ Key: 'Type', Value: runnerParameters.runnerType }, | ||
{ Key: 'Owner', Value: runnerParameters.runnerOwner }, | ||
], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,62 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ec2:DescribeInstances", | ||
"ec2:DescribeTags" | ||
], | ||
"Resource": [ | ||
"*" | ||
] | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ec2:TerminateInstances" | ||
], | ||
"Resource": [ | ||
"*" | ||
], | ||
"Condition": { | ||
"StringEquals": { | ||
"ec2:ResourceTag/Application": "github-action-runner" | ||
} | ||
} | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ssm:GetParameter" | ||
], | ||
"Resource": [ | ||
"${github_app_key_base64_arn}", | ||
"${github_app_id_arn}" | ||
] | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ec2:DescribeInstances", | ||
"ec2:DescribeTags" | ||
], | ||
"Resource": [ | ||
"*" | ||
] | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ec2:TerminateInstances" | ||
], | ||
"Resource": [ | ||
"*" | ||
], | ||
"Condition": { | ||
"StringEquals": { | ||
"ec2:ResourceTag/ghr:Application": "github-action-runner" | ||
} | ||
} | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ec2:TerminateInstances" | ||
], | ||
"Resource": [ | ||
"*" | ||
], | ||
"Condition": { | ||
"StringEquals": { | ||
"ec2:ResourceTag/Application": "github-action-runner" | ||
} | ||
} | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"ssm:GetParameter" | ||
], | ||
"Resource": [ | ||
"${github_app_key_base64_arn}", | ||
"${github_app_id_arn}" | ||
] | ||
%{ if kms_key_arn != "" ~} | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"kms:Decrypt" | ||
], | ||
"Resource": "${kms_key_arn}" | ||
}, | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"kms:Decrypt" | ||
], | ||
"Resource": "${kms_key_arn}" | ||
%{ endif ~} | ||
} | ||
] | ||
} | ||
] | ||
} |
Uh oh!
There was an error while loading. Please reload this page.