Skip to content

Commit 8e6cfab

Browse files
fix: fix runner owner logic
1 parent f09b291 commit 8e6cfab

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

lambdas/functions/control-plane/src/scale-runners/scale-up.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
275275
type MessagesWithClient = {
276276
messages: ActionRequestMessageSQS[];
277277
githubInstallationClient: Octokit;
278+
runnerOwner: string;
278279
};
279280

280281
const validMessages = new Map<string, MessagesWithClient>();
@@ -304,8 +305,9 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
304305
continue;
305306
}
306307

307-
let key = enableOrgLevel ? payload.repositoryOwner : `${payload.repositoryOwner}/${payload.repositoryName}`;
308+
const runnerOwner = enableOrgLevel ? payload.repositoryOwner : `${payload.repositoryOwner}/${payload.repositoryName}`;
308309

310+
let key = runnerOwner;
309311
if (dynamicEc2ConfigEnabled && labels?.length) {
310312
const requestedDynamicEc2Config = labels.find((l) => l.startsWith('ghr-ec2-'))?.slice('ghr-ec2-'.length);
311313

@@ -327,6 +329,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
327329
entry = {
328330
messages: [],
329331
githubInstallationClient,
332+
runnerOwner: runnerOwner,
330333
};
331334

332335
validMessages.set(key, entry);
@@ -348,15 +351,17 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
348351

349352
logger.info(`Received events`);
350353

351-
for (const [group, { githubInstallationClient, messages }] of validMessages.entries()) {
354+
for (const [group, { githubInstallationClient, messages, runnerOwner }] of validMessages.entries()) {
352355
// Work out how much we want to scale up by.
353356
let scaleUp = 0;
354357

355358
if (messages.length > 0 && dynamicEc2ConfigEnabled) {
356-
logger.info('Dynamic EC2 config enabled, processing labels');
359+
logger.info('Dynamic EC2 config enabled, processing labels', {labels: messages[0].labels});
357360

358361
const ec2Labels =
359-
messages[0].labels?.filter(l => l.startsWith('ghr-ec2-')) ?? [];
362+
messages[0].labels
363+
?.map(l => l.trim())
364+
.filter(l => l.startsWith('ghr-ec2-')) ?? [];
360365

361366
logger.info('EC2 labels detected', { ec2Labels });
362367

@@ -415,7 +420,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
415420

416421
// Don't call the EC2 API if we can create an unlimited number of runners.
417422
const currentRunners =
418-
maximumRunners === -1 ? 0 : (await listEC2Runners({ environment, runnerType, runnerOwner: group })).length;
423+
maximumRunners === -1 ? 0 : (await listEC2Runners({ environment, runnerType, runnerOwner: runnerOwner })).length;
419424

420425
logger.info('Current runners', {
421426
currentRunners,
@@ -461,7 +466,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
461466
runnerLabels,
462467
runnerGroup,
463468
runnerNamePrefix,
464-
runnerOwner: group,
469+
runnerOwner: runnerOwner,
465470
runnerType,
466471
disableAutoUpdate,
467472
ssmTokenPath,

lambdas/functions/webhook/src/runners/dispatch.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe('Dispatcher', () => {
103103
installationId: 0,
104104
queueId: runnerConfig[0].id,
105105
repoOwnerType: 'Organization',
106+
labels: ['self-hosted', 'Test']
106107
});
107108
});
108109

@@ -150,6 +151,7 @@ describe('Dispatcher', () => {
150151
installationId: 0,
151152
queueId: 'match',
152153
repoOwnerType: 'Organization',
154+
labels: ['self-hosted', 'match'],
153155
});
154156
});
155157

lambdas/functions/webhook/src/runners/dispatch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ async function handleWorkflowJob(
5656
installationId: body.installation?.id ?? 0,
5757
queueId: queue.id,
5858
repoOwnerType: body.repository.owner.type,
59+
labels: body.workflow_job.labels,
5960
});
6061
logger.info(
6162
`Successfully dispatched job for ${body.repository.full_name} to the queue ${queue.id} - ` +

0 commit comments

Comments
 (0)