Skip to content

Commit

Permalink
Merge branch 'main' into janslow/aws-scheduler-pool
Browse files Browse the repository at this point in the history
  • Loading branch information
npalm authored Aug 16, 2024
2 parents 7d6b44e + 98b1560 commit 98175a4
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 3 deletions.
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Before you submit your pull request consider the following guidelines:
terraform init
```

* For updating docs, you have to enable GitHub actions on your forked repository. Simply go to the tab Actions and enable actions.
* Commit your changes using a descriptive commit message:

```shell
Expand Down
1 change: 1 addition & 0 deletions lambdas/functions/control-plane/src/lambda.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const body: ActionRequestMessage = {
installationId: 1,
repositoryName: 'name',
repositoryOwner: 'owner',
repoOwnerType: 'Organization',
};

const sqsRecord: SQSRecord = {
Expand Down
10 changes: 10 additions & 0 deletions lambdas/functions/control-plane/src/scale-runners/scale-up.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const TEST_DATA: scaleUpModule.ActionRequestMessage = {
repositoryName: 'hello-world',
repositoryOwner: 'Codertocat',
installationId: 2,
repoOwnerType: 'Organization',
};

// installationId 0 means no installationId is set.
Expand All @@ -62,6 +63,7 @@ const TEST_DATA_WITH_ZERO_INSTALL_ID: scaleUpModule.ActionRequestMessage = {
repositoryName: 'hello-world',
repositoryOwner: 'Codertocat',
installationId: 0,
repoOwnerType: 'Organization',
};

const cleanEnv = process.env;
Expand Down Expand Up @@ -305,6 +307,14 @@ describe('scaleUp with GHES', () => {
expect(mockOctokit.paginate).toHaveBeenCalledTimes(1);
});

it('Discards event if it is a User repo and org level runners is enabled', async () => {
process.env.ENABLE_ORGANIZATION_RUNNERS = 'true';
const USER_REPO_TEST_DATA = { ...TEST_DATA };
USER_REPO_TEST_DATA.repoOwnerType = 'User';
await scaleUpModule.scaleUp('aws:sqs', USER_REPO_TEST_DATA);
expect(createRunner).not.toHaveBeenCalled();
});

it('create SSM parameter for runner group id if it doesnt exist', async () => {
mockSSMClient.on(GetParameterCommand).rejects();
await scaleUpModule.scaleUp('aws:sqs', TEST_DATA);
Expand Down
15 changes: 15 additions & 0 deletions lambdas/functions/control-plane/src/scale-runners/scale-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface ActionRequestMessage {
repositoryName: string;
repositoryOwner: string;
installationId: number;
repoOwnerType: string;
}

interface CreateGitHubRunnerConfig {
Expand Down Expand Up @@ -250,6 +251,16 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage
`Please ensure you have enabled workflow_job events.`,
);
}

if (!isValidRepoOwnerTypeIfOrgLevelEnabled(payload, enableOrgLevel)) {
logger.warn(
`Repository ${payload.repositoryOwner}/${payload.repositoryName} does not belong to a GitHub` +
`organization and organization runners are enabled. This is not supported. Not scaling up for this event.` +
`Not throwing error to prevent re-queueing and just ignoring the event.`,
);
return;
}

const ephemeral = ephemeralEnabled && payload.eventType === 'workflow_job';
const runnerType = enableOrgLevel ? 'Org' : 'Repo';
const runnerOwner = enableOrgLevel ? payload.repositoryOwner : `${payload.repositoryOwner}/${payload.repositoryName}`;
Expand Down Expand Up @@ -341,6 +352,10 @@ async function createStartRunnerConfig(
}
}

function isValidRepoOwnerTypeIfOrgLevelEnabled(payload: ActionRequestMessage, enableOrgLevel: boolean): boolean {
return !(enableOrgLevel && payload.repoOwnerType !== 'Organization');
}

function addDelay(instances: string[]) {
const delay = async (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
const ssmParameterStoreMaxThroughput = 40;
Expand Down
1 change: 1 addition & 0 deletions lambdas/functions/webhook/src/sqs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Test sending message to SQS.', () => {
repositoryOwner: 'owner',
queueId: queueUrl,
queueFifo: false,
repoOwnerType: 'Organization',
};

afterEach(() => {
Expand Down
1 change: 1 addition & 0 deletions lambdas/functions/webhook/src/sqs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ActionRequestMessage {
installationId: number;
queueId: string;
queueFifo: boolean;
repoOwnerType: string;
}

export interface MatcherConfig {
Expand Down
3 changes: 3 additions & 0 deletions lambdas/functions/webhook/src/webhook/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ describe('handler', () => {
installationId: 0,
queueId: 'ubuntu-queue-id',
queueFifo: false,
repoOwnerType: 'Organization',
});
});
it('Check webhook will accept jobs for latest labels if workflow labels are not specific', async () => {
Expand Down Expand Up @@ -492,6 +493,7 @@ describe('handler', () => {
installationId: 0,
queueId: 'ubuntu-queue-id',
queueFifo: false,
repoOwnerType: 'Organization',
});
});
});
Expand Down Expand Up @@ -531,6 +533,7 @@ describe('handler', () => {
installationId: 0,
queueId: 'ubuntu-queue-id',
queueFifo: false,
repoOwnerType: 'Organization',
});
});

Expand Down
1 change: 1 addition & 0 deletions lambdas/functions/webhook/src/webhook/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function handleWorkflowJob(
installationId: installationId,
queueId: queue.id,
queueFifo: queue.fifo,
repoOwnerType: body.repository.owner.type,
});
logger.info(`Successfully queued job for ${body.repository.full_name} to the queue ${queue.id}`);
return { statusCode: 201 };
Expand Down
2 changes: 1 addition & 1 deletion modules/multi-runner/README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion modules/multi-runner/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ variable "multi_runner_config" {
ebs_optimized: "The EC2 EBS optimized configuration."
enable_ephemeral_runners: "Enable ephemeral runners, runners will only be used once."
enable_job_queued_check: "Enables JIT configuration for creating runners instead of registration token based registraton. JIT configuration will only be applied for ephemeral runners. By default JIT confiugration is enabled for ephemeral runners an can be disabled via this override. When running on GHES without support for JIT configuration this variable should be set to true for ephemeral runners."
enable_runner_on_demand_failover_for_errors "Enable on-demand failover. For example to fall back to on demand when no spot capacity is available the variable can be set to `InsufficientInstanceCapacity`. When not defined the default behavior is to retry later."
enable_on_demand_failover_for_errors: "Enable on-demand failover. For example to fall back to on demand when no spot capacity is available the variable can be set to `InsufficientInstanceCapacity`. When not defined the default behavior is to retry later."
enable_organization_runners: "Register runners to organization, instead of repo level"
enable_runner_binaries_syncer: "Option to disable the lambda to sync GitHub runner distribution, useful when using a pre-build AMI."
enable_ssm_on_runners: "Enable to allow access the runner instances for debugging purposes via SSM. Note that this adds additional permissions to the runner instances."
Expand Down

0 comments on commit 98175a4

Please sign in to comment.