Skip to content
Open
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
4 changes: 2 additions & 2 deletions lambdas/functions/control-plane/src/pool/pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import moment from 'moment-timezone';
import * as nock from 'nock';

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 { listEC2Runners } from '@aws-github-runner/compute-providers/aws/ec2/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/compute-providers/aws/ec2/control-plane/runners', async () => ({
vi.mock('@aws-github-runner/compute-providers/aws/ec2/runners', async () => ({
listEC2Runners: vi.fn(),
// Include any other functions from the module that might be used
bootTimeExceeded: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type {
CreateRunnerResult,
CreateScaleUpRunnersInput,
CurrentRunnersInput,
LambdaRunnerSource,
RunnerSource,
RunnerLabelResolution,
RunnerInfo,
RunnerType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from '@aws-sdk/client-ec2';
import { getTracedAWSV3Client } from '@aws-github-runner/aws-powertools-util';

import { Ec2OverrideConfig } from './runners.d';
import { Ec2OverrideConfig } from '../runners.d';

const EC2_OVERRIDE_LIST_VALUE_SEPARATOR = ';';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { RunnerInfo } from '../../../../core';
import { bootTimeExceeded } from './runners';
import { bootTimeExceeded } from '../runners';
import { calculateEc2PoolSize } from './pool';
import { beforeEach, describe, expect, it, vi } from 'vitest';

vi.mock('./runners', () => ({
vi.mock('../runners', () => ({
bootTimeExceeded: vi.fn(),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
RunnerStatus,
} from '../../../../core';
import { createRunners, loadEc2ProviderConfig } from './runner-config';
import { bootTimeExceeded, listEC2Runners } from './runners';
import { bootTimeExceeded, listEC2Runners } from '../runners';

const logger = createChildLogger('pool');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type {
CreateRunnerResult,
CreateStartRunnerConfig,
GitHubRunnerMetadata,
LambdaRunnerSource,
RunnerSource,
StartRunnerConfigOptions,
} from '../../../../core';
import { Octokit } from '@octokit/rest';
import type { Tag } from '@aws-sdk/client-ec2';
import yn from 'yn';

import { createRunner, tag, terminateRunner } from './runners';
import type { RunnerInputParameters } from './runners.d';
import { createRunner, tag, terminateRunner } from '../runners';
import type { RunnerInputParameters } from '../runners.d';

const logger = createChildLogger('ec2-runners');
const RUNNER_LABELS_TAG_KEY = 'ghr:runner_labels';
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function createRunners(
numberOfRunners: number,
ghClient: Octokit,
createStartRunnerConfig: CreateStartRunnerConfig,
source: LambdaRunnerSource = 'scale-up-lambda',
source: RunnerSource,
): Promise<CreateRunnerResult> {
let result: CreateRunnerResult;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';

import type { RunnerInfo, RunnerType } from '../../../../core';
import { createEc2ScaleDownProvider } from './scale-down';
import { listEC2Runners, tag, terminateRunner, untag } from './runners';
import { listEC2Runners, tag, terminateRunner, untag } from '../runners';

vi.mock('./runners', async (importOriginal) => {
const actual = await importOriginal<typeof import('./runners')>();
vi.mock('../runners', async (importOriginal) => {
const actual = await importOriginal<typeof import('../runners')>();
return {
...actual,
listEC2Runners: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RunnerInfo, ScaleDownComputeProvider } from '../../../../core';
import { bootTimeExceeded, listEC2Runners, tag, terminateRunner, untag } from './runners';
import { bootTimeExceeded, listEC2Runners, tag, terminateRunner, untag } from '../runners';

async function listEc2ScaleDownRunners(environment: string, orphan?: boolean): Promise<RunnerInfo[]> {
return await listEC2Runners({ environment, orphan });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';

import { parseEc2OverrideConfig } from './dynamic-labels';
import { EC2_TAG_VALUE_MAX_LENGTH, RUNNER_LABELS_TAG_MAX_COUNT } from './runner-config';
import { createRunner, listEC2Runners, tag, terminateRunner } from './runners';
import type { RunnerInputParameters } from './runners.d';
import { createRunner, listEC2Runners, tag, terminateRunner } from '../runners';
import type { RunnerInputParameters } from '../runners.d';
import { createEc2ScaleUpProvider } from './scale-up';

vi.mock('./runners', () => ({
vi.mock('../runners', () => ({
createRunner: vi.fn(),
listEC2Runners: vi.fn(),
tag: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type {
} from '../../../../core';
import yn from 'yn';

import { listEC2Runners } from './runners';
import type { Ec2OverrideConfig } from './runners.d';
import { listEC2Runners } from '../runners';
import type { Ec2OverrideConfig } from '../runners.d';
import {
getDefaultBlockDeviceNameFromLaunchTemplate,
parseEc2OverrideConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Placement,
FleetBlockDeviceMappingRequest,
} from '@aws-sdk/client-ec2';
import type { LambdaRunnerSource, ListRunnerFilters, RunnerType } from '../../../../core';
import type { ListRunnerFilters, RunnerSource, RunnerType } from '../../../core';

export interface Ec2ListRunnerFilters extends ListRunnerFilters {
statuses?: string[];
Expand Down Expand Up @@ -42,7 +42,7 @@ export interface RunnerInputParameters {
};
ec2OverrideConfig?: Ec2OverrideConfig;
numberOfRunners: number;
source: LambdaRunnerSource;
source: RunnerSource;
amiIdSsmParameterName?: string;
tracingEnabled?: boolean;
onDemandFailoverOnError?: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { mockClient } from 'aws-sdk-client-mock';
import 'aws-sdk-client-mock-jest/vitest';

import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { LambdaRunnerSource, RunnerInfo, RunnerType } from '../../../../core';
import type { RunnerInfo, RunnerSource, RunnerType } from '../../../core';
import { createRunner, listEC2Runners, tag, terminateRunner, untag } from './runners';
import type { Ec2OverrideConfig, RunnerInputParameters } from './runners.d';

Expand Down Expand Up @@ -371,7 +371,7 @@ describe('create runner', () => {
});
});

it('calls create fleet of multiple instances with pool-lambda source when specified', async () => {
it('calls create fleet of multiple instances with pool source when specified', async () => {
const instances = [{ InstanceIds: ['i-1234', 'i-5678', 'i-9012'] }];

mockEC2Client.on(CreateFleetCommand).resolves({ Instances: instances });
Expand Down Expand Up @@ -1170,7 +1170,7 @@ interface RunnerConfig {
tracingEnabled?: boolean;
onDemandFailoverOnError?: string[];
scaleErrors: string[];
source: LambdaRunnerSource;
source: RunnerSource;
useDedicatedHost?: boolean;
ec2OverrideConfig?: Ec2OverrideConfig;
}
Expand Down Expand Up @@ -1209,7 +1209,7 @@ interface ExpectedFleetRequestValues {
totalTargetCapacity: number;
imageId?: string;
tracingEnabled?: boolean;
source: LambdaRunnerSource;
source: RunnerSource;
}

function expectedCreateFleetRequest(expectedValues: ExpectedFleetRequestValues): CreateFleetCommandInput {
Expand Down Expand Up @@ -1318,6 +1318,7 @@ describe('create runner with useDedicatedHost', () => {
const dedicatedHostRunnerConfig: RunnerConfig = {
allocationStrategy: SpotAllocationStrategy.CAPACITY_OPTIMIZED,
capacityType: 'on-demand',
source: 'scale-up-lambda',
type: 'Org',
scaleErrors: [],
useDedicatedHost: true,
Expand Down Expand Up @@ -1411,14 +1412,15 @@ describe('create runner with useDedicatedHost', () => {
});
});

it('creates multiple instances via RunInstances', async () => {
it('creates multiple instances via RunInstances and preserves the caller source', async () => {
mockEC2Client.on(RunInstancesCommand).resolves({
Instances: [{ InstanceId: 'i-dedicated-1' }, { InstanceId: 'i-dedicated-2' }],
});

const result = await createRunner({
...createRunnerConfig(dedicatedHostRunnerConfig),
numberOfRunners: 2,
source: 'scale-up-lambda',
});

expect(result).toEqual({
Expand All @@ -1440,7 +1442,7 @@ describe('create runner with useDedicatedHost', () => {
ResourceType: 'instance',
Tags: [
{ Key: 'ghr:Application', Value: 'github-action-runner' },
{ Key: 'ghr:created_by', Value: 'pool-lambda' },
{ Key: 'ghr:created_by', Value: 'scale-up-lambda' },
{ Key: 'ghr:Type', Value: 'Org' },
{ Key: 'ghr:Owner', Value: REPO_NAME },
],
Expand All @@ -1449,7 +1451,7 @@ describe('create runner with useDedicatedHost', () => {
ResourceType: 'volume',
Tags: [
{ Key: 'ghr:Application', Value: 'github-action-runner' },
{ Key: 'ghr:created_by', Value: 'pool-lambda' },
{ Key: 'ghr:created_by', Value: 'scale-up-lambda' },
{ Key: 'ghr:Type', Value: 'Org' },
{ Key: 'ghr:Owner', Value: REPO_NAME },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getTracedAWSV3Client, tracer } from '@aws-github-runner/aws-powertools-
import { getParameter } from '@aws-github-runner/aws-ssm-util';
import moment from 'moment';

import type { CreateRunnerResult, RunnerInfo } from '../../../../core';
import type { CreateRunnerResult, RunnerInfo } from '../../../core';
import type { Ec2ListRunnerFilters, Ec2OverrideConfig, RunnerInputParameters } from './runners.d';

const logger = createChildLogger('runners');
Expand Down Expand Up @@ -584,7 +584,7 @@ async function createInstancesWithRunInstances(
): Promise<CreateRunnerResult> {
const tags = [
{ Key: 'ghr:Application', Value: 'github-action-runner' },
{ Key: 'ghr:created_by', Value: runnerParameters.numberOfRunners === 1 ? 'scale-up-lambda' : 'pool-lambda' },
{ Key: 'ghr:created_by', Value: runnerParameters.source },
{ Key: 'ghr:Type', Value: runnerParameters.runnerType },
{ Key: 'ghr:Owner', Value: runnerParameters.runnerOwner },
];
Expand Down
2 changes: 1 addition & 1 deletion lambdas/libs/compute-providers/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface ComputeProvider {
type: ComputeProviderType;
}

export type LambdaRunnerSource = 'scale-up-lambda' | 'pool-lambda';
export type RunnerSource = 'scale-up-lambda' | 'pool-lambda';
export type RunnerType = 'Org' | 'Repo';

export interface CreateGitHubRunnerConfig {
Expand Down
2 changes: 1 addition & 1 deletion lambdas/libs/compute-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"./control-plane": "./control-plane.ts",
"./aws/ec2/webhook": "./aws/ec2/webhook.ts",
"./aws/ec2/control-plane": "./aws/ec2/control-plane.ts",
"./aws/ec2/control-plane/runners": "./aws/ec2/src/control-plane/runners.ts",
"./aws/ec2/runners": "./aws/ec2/src/runners.ts",
"./aws/ec2/control-plane/runner-config": "./aws/ec2/src/control-plane/runner-config.ts"
},
"type": "module",
Expand Down
Loading