From 86a5d2849a98ef040d59c7a481936665f0cdf865 Mon Sep 17 00:00:00 2001 From: Niek Palm Date: Fri, 14 Oct 2022 15:59:17 +0200 Subject: [PATCH] feat!: Remove old scale down mechanism (< 0.19.0) (#2519) Migration: Option 1, upgrade to 2.x could cause orphan instances which will not be terminated by the scale-down function, thoses instances needs to be removed manual. Option 2, upgrade first to a verions 1.x and keep this version running till all instances before the upgrade are terminated. Next upgrade to 2.x. --- .../src/scale-runners/scale-down.test.ts | 4 ++-- .../runners/src/scale-runners/scale-down.ts | 20 +------------------ 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-down.test.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-down.test.ts index f05d713f41..b27069af79 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-down.test.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-down.test.ts @@ -444,7 +444,7 @@ describe('scaleDown', () => { expect(mockOctokit.apps.getRepoInstallation).toBeCalledTimes(2); expect(mockOctokit.apps.getOrgInstallation).toBeCalledTimes(1); - expect(terminateRunner).toBeCalledTimes(8); + expect(terminateRunner).toBeCalledTimes(7); for (const toTerminate of RUNNERS_ALL_REMOVED) { expect(terminateRunner).toHaveBeenCalledWith(toTerminate.instanceId); } @@ -558,7 +558,7 @@ describe('scaleDown', () => { expect(mockOctokit.apps.getRepoInstallation).toBeCalledTimes(2); expect(mockOctokit.apps.getOrgInstallation).toBeCalledTimes(1); - expect(terminateRunner).toBeCalledTimes(8); + expect(terminateRunner).toBeCalledTimes(7); for (const toTerminate of RUNNERS_ALL_REMOVED) { expect(terminateRunner).toHaveBeenCalledWith(toTerminate.instanceId); } diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts index 605221c58f..a9b268f48f 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts @@ -220,21 +220,6 @@ async function listAndSortRunners(environment: string) { }); } -/** - * We are moving to a new strategy to find and remove runners, this function will ensure - * during migration runners tagged in the old way are removed. - */ -function filterLegacyRunners(ec2runners: RunnerList[]): RunnerInfo[] { - return ec2runners - .filter((ec2Runner) => ec2Runner.repo || ec2Runner.org) - .map((ec2Runner) => ({ - instanceId: ec2Runner.instanceId, - launchTime: ec2Runner.launchTime, - type: ec2Runner.org ? 'Org' : 'Repo', - owner: ec2Runner.org ? (ec2Runner.org as string) : (ec2Runner.repo as string), - })); -} - function filterRunners(ec2runners: RunnerList[]): RunnerInfo[] { return ec2runners.filter((ec2Runner) => ec2Runner.type) as RunnerInfo[]; } @@ -256,12 +241,9 @@ export async function scaleDown(): Promise { logger.debug(`No active runners found for environment: '${environment}'`, LogFields.print()); return; } - const legacyRunners = filterLegacyRunners(ec2Runners); - logger.debug(JSON.stringify(legacyRunners), LogFields.print()); - const runners = filterRunners(ec2Runners); + const runners = filterRunners(ec2Runners); await evaluateAndRemoveRunners(runners, scaleDownConfigs); - await evaluateAndRemoveRunners(legacyRunners, scaleDownConfigs); const activeEc2RunnersCountAfter = (await listAndSortRunners(environment)).length; logger.info(