Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lambdas/functions/control-plane/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"dependencies": {
"@aws-github-runner/aws-powertools-util": "*",
"@aws-github-runner/aws-ssm-util": "*",
"@aws-github-runner/runner-providers": "*",
"@aws-github-runner/compute-providers": "*",
"@aws-lambda-powertools/parameters": "^2.31.0",
"@aws-sdk/client-ec2": "^3.1009.0",
"@aws-sdk/client-sqs": "^3.1009.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createControlPlaneProviderRegistry } from '@aws-github-runner/runner-providers/control-plane';
import { runnerProviderTypes } from '@aws-github-runner/runner-providers/provider-types';
import { createControlPlaneProviderRegistry } from '@aws-github-runner/compute-providers/control-plane';
import { computeProviderTypes } from '@aws-github-runner/compute-providers/provider-types';

import { createStartRunnerConfig } from './scale-runners/github-runner';

export const controlPlaneProviderRegistry = createControlPlaneProviderRegistry(createStartRunnerConfig);

export { runnerProviderTypes };
export { computeProviderTypes };
2 changes: 1 addition & 1 deletion lambdas/functions/control-plane/src/modules.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare namespace NodeJS {
PARAMETER_GITHUB_APP_ID_NAME: string;
PARAMETER_GITHUB_APP_KEY_BASE64_NAME: string;
RUNNER_OWNER: string;
RUNNER_PROVIDER_TYPE?: string;
COMPUTE_PROVIDER_TYPE?: string;
SCALE_DOWN_CONFIG: string;
SSM_TOKEN_PATH: string;
SSM_CLEANUP_CONFIG: string;
Expand Down
16 changes: 8 additions & 8 deletions lambdas/functions/control-plane/src/pool/pool-contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Octokit } from '@octokit/rest';
import type { RunnerProviderType } from '@aws-github-runner/runner-providers/provider-types';
import type { ComputeProviderType } from '@aws-github-runner/compute-providers/provider-types';
import { beforeEach, vi } from 'vitest';

import { definePoolContractTests } from '../test/runner-provider-contracts/pool';
import { providerTypes } from '../test/runner-provider-contracts/provider-types';
import { definePoolContractTests } from '../test/compute-provider-contracts/pool';
import { providerTypes } from '../test/compute-provider-contracts/provider-types';
import * as ghAuth from '../github/auth';
import { controlPlaneProviderRegistry } from '../control-plane-providers';
import * as githubRunner from '../scale-runners/github-runner';
import { adjust } from './pool';
import type { PoolRunnerProvider } from './pool-provider';
import type { PoolComputeProvider } from './pool-provider';

vi.mock('../github/auth', () => ({
createGithubAppAuth: vi.fn(),
Expand All @@ -35,13 +35,13 @@ const githubClient = {

const cleanEnv = process.env;

const lanes = providerTypes.map((type) => ({
const computeProviders = providerTypes.map((type) => ({
provider: {
type,
listRunners: vi.fn(),
countAvailableRunners: vi.fn(),
createRunners: vi.fn(),
} satisfies PoolRunnerProvider,
} satisfies PoolComputeProvider,
}));

beforeEach(() => {
Expand All @@ -66,9 +66,9 @@ beforeEach(() => {
vi.mocked(githubClient.paginate).mockResolvedValue([]);
});

definePoolContractTests<RunnerProviderType>({
definePoolContractTests<ComputeProviderType>({
adjust,
computeProviders,
githubInstallationClient: githubClient,
lanes,
resolveCapability: mockedResolveCapability,
});
4 changes: 2 additions & 2 deletions lambdas/functions/control-plane/src/pool/pool-provider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type {
CreatePoolRunnersInput,
ListPoolRunnersInput,
PoolRunnerProvider,
PoolComputeProvider,
RunnerStatus,
} from '@aws-github-runner/runner-providers/core';
} from '@aws-github-runner/compute-providers/core';
14 changes: 8 additions & 6 deletions lambdas/functions/control-plane/src/pool/pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Octokit } from '@octokit/rest';
import moment from 'moment-timezone';
import * as nock from 'nock';

import { createRunners } from '@aws-github-runner/runner-providers/aws/ec2/control-plane/runner-config';
import { listEC2Runners } from '@aws-github-runner/runner-providers/aws/ec2/control-plane/runners';
import { createRunners } from '@aws-github-runner/compute-providers/aws/ec2/control-plane/runner-config';
import { listEC2Runners } from '@aws-github-runner/compute-providers/aws/ec2/control-plane/runners';
import * as ghAuth from '../github/auth';
import { getGitHubEnterpriseApiUrl } from '../scale-runners/github-runner';
import { adjust } from './pool';
Expand All @@ -26,7 +26,7 @@ vi.mock('@octokit/rest', () => ({
}),
}));

vi.mock('@aws-github-runner/runner-providers/aws/ec2/control-plane/runners', async () => ({
vi.mock('@aws-github-runner/compute-providers/aws/ec2/control-plane/runners', async () => ({
listEC2Runners: vi.fn(),
// Include any other functions from the module that might be used
bootTimeExceeded: vi.fn(),
Expand All @@ -37,8 +37,10 @@ vi.mock('./../github/auth', async () => ({
createOctokitClient: vi.fn(),
}));

vi.mock('@aws-github-runner/runner-providers/aws/ec2/control-plane/runner-config', async (importOriginal) => ({
...(await importOriginal<typeof import('@aws-github-runner/runner-providers/aws/ec2/control-plane/runner-config')>()),
vi.mock('@aws-github-runner/compute-providers/aws/ec2/control-plane/runner-config', async (importOriginal) => ({
...(await importOriginal<
typeof import('@aws-github-runner/compute-providers/aws/ec2/control-plane/runner-config')
>()),
createRunners: vi.fn(),
}));

Expand Down Expand Up @@ -244,7 +246,7 @@ describe('Test simple pool.', () => {

it('Rejects unsupported pool provider types.', async () => {
await expect(adjust({ poolSize: 10, type: 'microvm' })).rejects.toThrow(
"Unsupported runner provider type 'microvm'",
"Unsupported compute provider type 'microvm'",
);
expect(mockListRunners).not.toHaveBeenCalled();
});
Expand Down
18 changes: 9 additions & 9 deletions lambdas/functions/control-plane/src/pool/pool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from '@octokit/rest';
import { createChildLogger } from '@aws-github-runner/aws-powertools-util';
import { resolveRunnerProviderType } from '@aws-github-runner/runner-providers/provider-types';
import { resolveComputeProviderType } from '@aws-github-runner/compute-providers/provider-types';
import yn from 'yn';

import { createGithubAppAuth, createGithubInstallationAuth, createOctokitClient } from '../github/auth';
Expand All @@ -16,12 +16,12 @@ export interface PoolEvent {
}

export async function adjust(event: PoolEvent): Promise<void> {
const runnerProviderType = resolveRunnerProviderType(event.type);
const runnerProvider = {
...controlPlaneProviderRegistry.capability(runnerProviderType, 'pool')(),
type: runnerProviderType,
const computeProviderType = resolveComputeProviderType(event.type);
const computeProvider = {
...controlPlaneProviderRegistry.capability(computeProviderType, 'pool')(),
type: computeProviderType,
};
logger.info(`Checking current ${runnerProvider.type} pool size against pool of size: ${event.poolSize}`);
logger.info(`Checking current ${computeProvider.type} pool size against pool of size: ${event.poolSize}`);
const runnerLabels = process.env.RUNNER_LABELS || '';
const runnerGroup = process.env.RUNNER_GROUP_NAME || '';
const runnerNamePrefix = process.env.RUNNER_NAME_PREFIX || '';
Expand Down Expand Up @@ -55,13 +55,13 @@ export async function adjust(event: PoolEvent): Promise<void> {
);

// Look up the managed provider runners, but running does not mean idle.
const poolRunners = await runnerProvider.listRunners({
const poolRunners = await computeProvider.listRunners({
environment,
runnerOwner,
runnerType: 'Org',
});

const numberOfRunnersInPool = runnerProvider.countAvailableRunners(poolRunners, runnerStatusses, includeBusyRunners);
const numberOfRunnersInPool = computeProvider.countAvailableRunners(poolRunners, runnerStatusses, includeBusyRunners);
let topUp = event.poolSize - numberOfRunnersInPool;

// The pool must never push the total number of runners (busy + idle) past the configured maximum.
Expand All @@ -81,7 +81,7 @@ export async function adjust(event: PoolEvent): Promise<void> {

if (topUp > 0) {
logger.info(`The pool will be topped up with ${topUp} runners.`);
await runnerProvider.createRunners({
await computeProvider.createRunners({
githubRunnerConfig: {
ephemeral,
enableJitConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import type { RunnerProviderType } from '@aws-github-runner/runner-providers/provider-types';
import type { ComputeProviderType } from '@aws-github-runner/compute-providers/provider-types';
import { beforeEach, vi } from 'vitest';

import { providerTypes } from '../test/runner-provider-contracts/provider-types';
import { defineScaleDownContractTests } from '../test/runner-provider-contracts/scale-down';
import { providerTypes } from '../test/compute-provider-contracts/provider-types';
import { defineScaleDownContractTests } from '../test/compute-provider-contracts/scale-down';
import { controlPlaneProviderRegistry } from '../control-plane-providers';
import { scaleDown } from './scale-down';
import type { ScaleDownRunnerProvider } from './types';
import type { ScaleDownComputeProvider } from './types';

const mockedResolveCapability = vi.spyOn(controlPlaneProviderRegistry, 'capability');

const cleanEnv = process.env;

const lanes = providerTypes.map((type) => ({
const computeProviders = providerTypes.map((type) => ({
provider: {
type,
list: vi.fn(),
bootTimeExceeded: vi.fn(),
markOrphan: vi.fn(),
unmarkOrphan: vi.fn(),
terminate: vi.fn(),
} satisfies ScaleDownRunnerProvider,
} satisfies ScaleDownComputeProvider,
}));

beforeEach(() => {
vi.clearAllMocks();
process.env = { ...cleanEnv };
});

defineScaleDownContractTests<RunnerProviderType>({
lanes,
defineScaleDownContractTests<ComputeProviderType>({
computeProviders,
resolveCapability: mockedResolveCapability,
scaleDown,
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { controlPlaneProviderRegistry } from '../control-plane-providers';
import * as ghAuth from '../github/auth';
import { githubCache } from './cache';
import { newestFirstStrategy, oldestFirstStrategy, scaleDown } from './scale-down';
import type { RunnerInfo, RunnerType, ScaleDownRunnerProvider } from './types';
import type { RunnerInfo, RunnerType, ScaleDownComputeProvider } from './types';

vi.mock('../github/auth', () => ({
createGithubAppAuth: vi.fn(),
Expand All @@ -31,24 +31,24 @@ const mockOctokit = {
paginate: vi.fn(),
};

const mockRunnerProvider = {
const mockComputeProvider = {
type: 'ec2',
list: vi.fn(),
bootTimeExceeded: vi.fn(),
markOrphan: vi.fn(),
unmarkOrphan: vi.fn(),
terminate: vi.fn(),
} satisfies ScaleDownRunnerProvider;
} satisfies ScaleDownComputeProvider;

const mockedResolveCapability = vi.spyOn(controlPlaneProviderRegistry, 'capability');
const mockedAppAuth = vi.mocked(ghAuth.createGithubAppAuth);
const mockedInstallationAuth = vi.mocked(ghAuth.createGithubInstallationAuth);
const mockCreateClient = vi.mocked(ghAuth.createOctokitClient);
const mockListRunners = vi.mocked(mockRunnerProvider.list);
const mockBootTimeExceeded = vi.mocked(mockRunnerProvider.bootTimeExceeded);
const mockMarkOrphan = vi.mocked(mockRunnerProvider.markOrphan);
const mockUnmarkOrphan = vi.mocked(mockRunnerProvider.unmarkOrphan);
const mockTerminateRunners = vi.mocked(mockRunnerProvider.terminate);
const mockListRunners = vi.mocked(mockComputeProvider.list);
const mockBootTimeExceeded = vi.mocked(mockComputeProvider.bootTimeExceeded);
const mockMarkOrphan = vi.mocked(mockComputeProvider.markOrphan);
const mockUnmarkOrphan = vi.mocked(mockComputeProvider.unmarkOrphan);
const mockTerminateRunners = vi.mocked(mockComputeProvider.terminate);

const cleanEnv = process.env;

Expand Down Expand Up @@ -176,13 +176,13 @@ describe('Scale down runners', () => {
process.env.ENVIRONMENT = ENVIRONMENT;
process.env.MINIMUM_RUNNING_TIME_IN_MINUTES = MINIMUM_TIME_RUNNING_IN_MINUTES.toString();
process.env.RUNNER_BOOT_TIME_IN_MINUTES = MINIMUM_BOOT_TIME.toString();
process.env.RUNNER_PROVIDER_TYPE = mockRunnerProvider.type;
process.env.COMPUTE_PROVIDER_TYPE = mockComputeProvider.type;

vi.clearAllMocks();
githubCache.clients.clear();
githubCache.runners.clear();

mockedResolveCapability.mockReturnValue(() => mockRunnerProvider);
mockedResolveCapability.mockReturnValue(() => mockComputeProvider);
mockBootTimeExceeded.mockImplementation((runner) => {
const launchTimePlusBootTime = moment(runner.launchTime).utc().add(MINIMUM_BOOT_TIME, 'minutes');
return launchTimePlusBootTime < moment(new Date()).utc();
Expand Down
Loading
Loading