Skip to content

Commit 29d0529

Browse files
authored
Fixing the behaviour for getRunnerTypes with scaleConfigOrg (#7062)
Currently, when scaleConfigOrg is pointing to an organization that is not the one runners are assigned to, it is not always correctly selected for `getRunnerTypes` call. Triggering errors similar to: ``` ERROR [getRunnerTypes]: HttpError: Not Found ``` This is due it not be correctly matched in all places where its usage is called.
1 parent cbb742e commit 29d0529

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/gh-runners.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ export async function getRunnerTypes(
323323
? await createGitHubClientForRunnerOrg(repo.owner, metrics)
324324
: await createGitHubClientForRunnerRepo(repo, metrics);
325325

326+
console.debug(
327+
`[getRunnerTypes]: Fetching runner types from ${filepath} for https://github.com/${repo.owner}/${repo.repo}/`,
328+
);
329+
326330
const response = await expBackOff(() => {
327331
return metrics.trackRequest(metrics.reposGetContentGHCallSuccess, metrics.reposGetContentGHCallFailure, () => {
328332
return githubAppClient.repos.getContent({
@@ -435,6 +439,9 @@ export async function getRunnerTypes(
435439
status = 'success';
436440
return filteredResult;
437441
} catch (e) {
442+
console.error(
443+
`[getRunnerTypes]: Error for path '${filepath}' for https://github.com/${repo.owner}/${repo.repo}/`,
444+
);
438445
console.error(`[getRunnerTypes]: ${e}`);
439446
throw e;
440447
} finally {

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,25 @@ export async function getGHRunnerRepo(ec2runner: RunnerInfo, metrics: ScaleDownM
250250
return ghRunner;
251251
}
252252

253+
export function backwardCompatibleGetRepoForgetRunnerTypes(ec2runner: RunnerInfo): Repo {
254+
if (Config.Instance.scaleConfigRepo) {
255+
if (Config.Instance.scaleConfigOrg) {
256+
return getRepo(Config.Instance.scaleConfigOrg, Config.Instance.scaleConfigRepo);
257+
}
258+
return getRepo(
259+
ec2runner.org !== undefined ? (ec2runner.org as string) : getRepo(ec2runner.repo as string).owner,
260+
Config.Instance.scaleConfigRepo,
261+
);
262+
}
263+
return getRepo(ec2runner.repo as string);
264+
}
265+
253266
export async function isEphemeralRunner(ec2runner: RunnerInfo, metrics: ScaleDownMetrics): Promise<boolean> {
254267
if (ec2runner.runnerType === undefined) {
255268
return false;
256269
}
257270

258-
const repo: Repo = (() => {
259-
if (Config.Instance.scaleConfigRepo) {
260-
return {
261-
owner: ec2runner.org !== undefined ? (ec2runner.org as string) : getRepo(ec2runner.repo as string).owner,
262-
repo: Config.Instance.scaleConfigRepo,
263-
};
264-
}
265-
return getRepo(ec2runner.repo as string);
266-
})();
267-
268-
const runnerTypes = await getRunnerTypes(repo, metrics);
269-
271+
const runnerTypes = await getRunnerTypes(backwardCompatibleGetRepoForgetRunnerTypes(ec2runner), metrics);
270272
return runnerTypes.get(ec2runner.runnerType)?.is_ephemeral ?? false;
271273
}
272274

@@ -276,18 +278,7 @@ export async function minRunners(ec2runner: RunnerInfo, metrics: ScaleDownMetric
276278
return Config.Instance.minAvailableRunners;
277279
}
278280

279-
const repo: Repo = (() => {
280-
if (Config.Instance.scaleConfigRepo) {
281-
return {
282-
owner: ec2runner.org !== undefined ? (ec2runner.org as string) : getRepo(ec2runner.repo as string).owner,
283-
repo: Config.Instance.scaleConfigRepo,
284-
};
285-
}
286-
return getRepo(ec2runner.repo as string);
287-
})();
288-
289-
const runnerTypes = await getRunnerTypes(repo, metrics);
290-
281+
const runnerTypes = await getRunnerTypes(backwardCompatibleGetRepoForgetRunnerTypes(ec2runner), metrics);
291282
return runnerTypes.get(ec2runner.runnerType)?.min_available ?? Config.Instance.minAvailableRunners;
292283
}
293284

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/scale-up-chron.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ export async function scaleUpChron(metrics: ScaleUpChronMetrics): Promise<void>
1414
// 3. For each runner queued for longer than the minimum delay, try to scale it up
1515

1616
try {
17-
const scaleConfigRepo = getRepo(Config.Instance.scaleConfigOrg, Config.Instance.scaleConfigRepo);
18-
const validRunnerTypes = await getRunnerTypes(scaleConfigRepo, metrics, Config.Instance.scaleConfigRepoPath);
17+
const validRunnerTypes = await getRunnerTypes(
18+
getRepo(Config.Instance.scaleConfigOrg, Config.Instance.scaleConfigRepo),
19+
metrics,
20+
Config.Instance.scaleConfigRepoPath,
21+
);
1922

2023
if (!Config.Instance.scaleUpChronRecordQueueUrl) {
2124
throw new Error('scaleUpChronRecordQueueUrl is not set. Cannot send queued scale up requests');

terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export async function scaleUp(
6565
}
6666

6767
const scaleConfigRepo = {
68-
owner: repo.owner,
68+
owner: Config.Instance.scaleConfigOrg || repo.owner,
6969
repo: Config.Instance.scaleConfigRepo || repo.repo,
7070
};
7171
const runnerTypes = await getRunnerTypes(scaleConfigRepo, metrics);

0 commit comments

Comments
 (0)