Skip to content

Commit f4016d8

Browse files
fix: fix runner owner logic
1 parent 1d52f11 commit f4016d8

3 files changed

Lines changed: 14 additions & 6 deletions

File tree

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
314314
type MessagesWithClient = {
315315
messages: ActionRequestMessageSQS[];
316316
githubInstallationClient: Octokit;
317+
runnerOwner: string;
317318
};
318319

319320
const validMessages = new Map<string, MessagesWithClient>();
@@ -343,8 +344,9 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
343344
continue;
344345
}
345346

346-
let key = enableOrgLevel ? payload.repositoryOwner : `${payload.repositoryOwner}/${payload.repositoryName}`;
347+
const runnerOwner = enableOrgLevel ? payload.repositoryOwner : `${payload.repositoryOwner}/${payload.repositoryName}`;
347348

349+
let key = runnerOwner;
348350
if (dynamicEc2ConfigEnabled && labels?.length) {
349351
const requestedDynamicEc2Config = labels.find((l) => l.startsWith('ghr-ec2-'))?.slice('ghr-ec2-'.length);
350352

@@ -366,6 +368,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
366368
entry = {
367369
messages: [],
368370
githubInstallationClient,
371+
runnerOwner: runnerOwner,
369372
};
370373

371374
validMessages.set(key, entry);
@@ -387,15 +390,17 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
387390

388391
logger.info(`Received events`);
389392

390-
for (const [group, { githubInstallationClient, messages }] of validMessages.entries()) {
393+
for (const [group, { githubInstallationClient, messages, runnerOwner }] of validMessages.entries()) {
391394
// Work out how much we want to scale up by.
392395
let scaleUp = 0;
393396

394397
if (messages.length > 0 && dynamicEc2ConfigEnabled) {
395-
logger.info('Dynamic EC2 config enabled, processing labels');
398+
logger.info('Dynamic EC2 config enabled, processing labels', {labels: messages[0].labels});
396399

397400
const ec2Labels =
398-
messages[0].labels?.filter(l => l.startsWith('ghr-ec2-')) ?? [];
401+
messages[0].labels
402+
?.map(l => l.trim())
403+
.filter(l => l.startsWith('ghr-ec2-')) ?? [];
399404

400405
logger.info('EC2 labels detected', { ec2Labels });
401406

@@ -454,7 +459,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
454459

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

459464
logger.info('Current runners', {
460465
currentRunners,
@@ -500,7 +505,7 @@ export async function scaleUp(payloads: ActionRequestMessageSQS[]): Promise<stri
500505
runnerLabels,
501506
runnerGroup,
502507
runnerNamePrefix,
503-
runnerOwner: group,
508+
runnerOwner: runnerOwner,
504509
runnerType,
505510
disableAutoUpdate,
506511
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)