Skip to content

Commit 7e33d64

Browse files
committed
fix: improve error handling in createJitConfig for instance creation
This ensures that even if there's a failed jit config creation for one of the instances, it proceeds with the other ones and does not just skip the entire batch. It will report the failed instances at the end.
1 parent 264ee5d commit 7e33d64

File tree

1 file changed

+55
-38
lines changed
  • lambdas/functions/control-plane/src/scale-runners

1 file changed

+55
-38
lines changed

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

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -534,48 +534,65 @@ async function createJitConfig(githubRunnerConfig: CreateGitHubRunnerConfig, ins
534534
const runnerGroupId = await getRunnerGroupId(githubRunnerConfig, ghClient);
535535
const { isDelay, delay } = addDelay(instances);
536536
const runnerLabels = githubRunnerConfig.runnerLabels.split(',');
537+
const failedInstances: string[] = [];
537538

538539
logger.debug(`Runner group id: ${runnerGroupId}`);
539540
logger.debug(`Runner labels: ${runnerLabels}`);
540541
for (const instance of instances) {
541-
// generate jit config for runner registration
542-
const ephemeralRunnerConfig: EphemeralRunnerConfig = {
543-
runnerName: `${githubRunnerConfig.runnerNamePrefix}${instance}`,
544-
runnerGroupId: runnerGroupId,
545-
runnerLabels: runnerLabels,
546-
};
547-
logger.debug(`Runner name: ${ephemeralRunnerConfig.runnerName}`);
548-
const runnerConfig =
549-
githubRunnerConfig.runnerType === 'Org'
550-
? await ghClient.actions.generateRunnerJitconfigForOrg({
551-
org: githubRunnerConfig.runnerOwner,
552-
name: ephemeralRunnerConfig.runnerName,
553-
runner_group_id: ephemeralRunnerConfig.runnerGroupId,
554-
labels: ephemeralRunnerConfig.runnerLabels,
555-
})
556-
: await ghClient.actions.generateRunnerJitconfigForRepo({
557-
owner: githubRunnerConfig.runnerOwner.split('/')[0],
558-
repo: githubRunnerConfig.runnerOwner.split('/')[1],
559-
name: ephemeralRunnerConfig.runnerName,
560-
runner_group_id: ephemeralRunnerConfig.runnerGroupId,
561-
labels: ephemeralRunnerConfig.runnerLabels,
562-
});
563-
564-
metricGitHubAppRateLimit(runnerConfig.headers);
565-
566-
// tag the EC2 instance with the Github runner id
567-
await tagRunnerId(instance, runnerConfig.data.runner.id.toString());
568-
569-
// store jit config in ssm parameter store
570-
logger.debug('Runner JIT config for ephemeral runner generated.', {
571-
instance: instance,
572-
});
573-
await putParameter(`${githubRunnerConfig.ssmTokenPath}/${instance}`, runnerConfig.data.encoded_jit_config, true, {
574-
tags: [{ Key: 'InstanceId', Value: instance }],
575-
});
576-
if (isDelay) {
577-
// Delay to prevent AWS ssm rate limits by being within the max throughput limit
578-
await delay(25);
542+
try {
543+
// generate jit config for runner registration
544+
const ephemeralRunnerConfig: EphemeralRunnerConfig = {
545+
runnerName: `${githubRunnerConfig.runnerNamePrefix}${instance}`,
546+
runnerGroupId: runnerGroupId,
547+
runnerLabels: runnerLabels,
548+
};
549+
logger.debug(`Runner name: ${ephemeralRunnerConfig.runnerName}`);
550+
const runnerConfig =
551+
githubRunnerConfig.runnerType === 'Org'
552+
? await ghClient.actions.generateRunnerJitconfigForOrg({
553+
org: githubRunnerConfig.runnerOwner,
554+
name: ephemeralRunnerConfig.runnerName,
555+
runner_group_id: ephemeralRunnerConfig.runnerGroupId,
556+
labels: ephemeralRunnerConfig.runnerLabels,
557+
})
558+
: await ghClient.actions.generateRunnerJitconfigForRepo({
559+
owner: githubRunnerConfig.runnerOwner.split('/')[0],
560+
repo: githubRunnerConfig.runnerOwner.split('/')[1],
561+
name: ephemeralRunnerConfig.runnerName,
562+
runner_group_id: ephemeralRunnerConfig.runnerGroupId,
563+
labels: ephemeralRunnerConfig.runnerLabels,
564+
});
565+
566+
metricGitHubAppRateLimit(runnerConfig.headers);
567+
568+
// tag the EC2 instance with the Github runner id
569+
await tagRunnerId(instance, runnerConfig.data.runner.id.toString());
570+
571+
// store jit config in ssm parameter store
572+
logger.debug('Runner JIT config for ephemeral runner generated.', {
573+
instance: instance,
574+
});
575+
await putParameter(`${githubRunnerConfig.ssmTokenPath}/${instance}`, runnerConfig.data.encoded_jit_config, true, {
576+
tags: [{ Key: 'InstanceId', Value: instance }],
577+
});
578+
if (isDelay) {
579+
// Delay to prevent AWS ssm rate limits by being within the max throughput limit
580+
await delay(25);
581+
}
582+
} catch (error) {
583+
failedInstances.push(instance);
584+
logger.warn('Failed to create JIT config for instance, continuing with remaining instances', {
585+
instance: instance,
586+
error: error instanceof Error ? error.message : String(error),
587+
});
579588
}
580589
}
590+
591+
if (failedInstances.length > 0) {
592+
logger.error('Failed to create JIT config for some instances', {
593+
failedInstances: failedInstances,
594+
totalInstances: instances.length,
595+
successfulInstances: instances.length - failedInstances.length,
596+
});
597+
}
581598
}

0 commit comments

Comments
 (0)