Skip to content

Commit 079ecee

Browse files
feat: add support for all fields in FleetLaunchTemplateOverridesRequest
1 parent e93e296 commit 079ecee

5 files changed

Lines changed: 771 additions & 60 deletions

File tree

lambdas/functions/control-plane/src/aws/runners.d.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DefaultTargetCapacityType, SpotAllocationStrategy } from '@aws-sdk/client-ec2';
1+
import { DefaultTargetCapacityType, InstanceRequirementsRequest, SpotAllocationStrategy, _InstanceType, Placement, FleetBlockDeviceMappingRequest } from '@aws-sdk/client-ec2';
22

33
export type RunnerType = 'Org' | 'Repo';
44

@@ -29,6 +29,20 @@ export interface ListRunnerFilters {
2929
statuses?: string[];
3030
}
3131

32+
export interface Ec2OverrideConfig {
33+
InstanceType?: _InstanceType
34+
MaxPrice?: string
35+
SubnetId?: string
36+
AvailabilityZone?: string
37+
WeightedCapacity?: number
38+
Priority?: number
39+
Placement?: Placement
40+
BlockDeviceMappings?: FleetBlockDeviceMappingRequest[]
41+
InstanceRequirements?: InstanceRequirementsRequest
42+
ImageId?: string
43+
AvailabilityZoneId?: string
44+
}
45+
3246
export interface RunnerInputParameters {
3347
environment: string;
3448
runnerType: RunnerType;
@@ -41,6 +55,7 @@ export interface RunnerInputParameters {
4155
maxSpotPrice?: string;
4256
instanceAllocationStrategy: SpotAllocationStrategy;
4357
};
58+
ec2OverrideConfig?: Ec2OverrideConfig;
4459
numberOfRunners: number;
4560
amiIdSsmParameterName?: string;
4661
tracingEnabled?: boolean;

lambdas/functions/control-plane/src/aws/runners.test.ts

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,215 @@ describe('create runner', () => {
425425
}),
426426
});
427427
});
428+
429+
it('overrides SubnetId when specified in ec2OverrideConfig', async () => {
430+
await createRunner({
431+
...createRunnerConfig(defaultRunnerConfig),
432+
ec2OverrideConfig: {
433+
SubnetId: 'subnet-override',
434+
},
435+
});
436+
437+
expect(mockEC2Client).toHaveReceivedCommandWith(CreateFleetCommand, {
438+
LaunchTemplateConfigs: [
439+
{
440+
LaunchTemplateSpecification: {
441+
LaunchTemplateName: 'lt-1',
442+
Version: '$Default',
443+
},
444+
Overrides: [
445+
{
446+
InstanceType: 'm5.large',
447+
SubnetId: 'subnet-override',
448+
},
449+
{
450+
InstanceType: 'c5.large',
451+
SubnetId: 'subnet-override',
452+
},
453+
],
454+
},
455+
],
456+
SpotOptions: {
457+
AllocationStrategy: SpotAllocationStrategy.CAPACITY_OPTIMIZED,
458+
},
459+
TagSpecifications: expect.any(Array),
460+
TargetCapacitySpecification: {
461+
DefaultTargetCapacityType: 'spot',
462+
TotalTargetCapacity: 1,
463+
},
464+
Type: 'instant',
465+
});
466+
});
467+
468+
it('overrides InstanceType when specified in ec2OverrideConfig', async () => {
469+
await createRunner({
470+
...createRunnerConfig(defaultRunnerConfig),
471+
ec2OverrideConfig: {
472+
InstanceType: 't3.xlarge',
473+
},
474+
});
475+
476+
expect(mockEC2Client).toHaveReceivedCommandWith(CreateFleetCommand, {
477+
LaunchTemplateConfigs: [
478+
{
479+
LaunchTemplateSpecification: {
480+
LaunchTemplateName: 'lt-1',
481+
Version: '$Default',
482+
},
483+
Overrides: [
484+
{
485+
InstanceType: 't3.xlarge',
486+
SubnetId: 'subnet-123',
487+
},
488+
{
489+
InstanceType: 't3.xlarge',
490+
SubnetId: 'subnet-456',
491+
},
492+
],
493+
},
494+
],
495+
SpotOptions: {
496+
AllocationStrategy: SpotAllocationStrategy.CAPACITY_OPTIMIZED,
497+
},
498+
TagSpecifications: expect.any(Array),
499+
TargetCapacitySpecification: {
500+
DefaultTargetCapacityType: 'spot',
501+
TotalTargetCapacity: 1,
502+
},
503+
Type: 'instant',
504+
});
505+
});
506+
507+
it('overrides ImageId when specified in ec2OverrideConfig', async () => {
508+
await createRunner({
509+
...createRunnerConfig(defaultRunnerConfig),
510+
ec2OverrideConfig: {
511+
ImageId: 'ami-override-123',
512+
},
513+
});
514+
515+
expect(mockEC2Client).toHaveReceivedCommandWith(CreateFleetCommand, {
516+
LaunchTemplateConfigs: [
517+
{
518+
LaunchTemplateSpecification: {
519+
LaunchTemplateName: 'lt-1',
520+
Version: '$Default',
521+
},
522+
Overrides: [
523+
{
524+
InstanceType: 'm5.large',
525+
SubnetId: 'subnet-123',
526+
ImageId: 'ami-override-123',
527+
},
528+
{
529+
InstanceType: 'c5.large',
530+
SubnetId: 'subnet-123',
531+
ImageId: 'ami-override-123',
532+
},
533+
{
534+
InstanceType: 'm5.large',
535+
SubnetId: 'subnet-456',
536+
ImageId: 'ami-override-123',
537+
},
538+
{
539+
InstanceType: 'c5.large',
540+
SubnetId: 'subnet-456',
541+
ImageId: 'ami-override-123',
542+
},
543+
],
544+
},
545+
],
546+
SpotOptions: {
547+
AllocationStrategy: SpotAllocationStrategy.CAPACITY_OPTIMIZED,
548+
},
549+
TagSpecifications: expect.any(Array),
550+
TargetCapacitySpecification: {
551+
DefaultTargetCapacityType: 'spot',
552+
TotalTargetCapacity: 1,
553+
},
554+
Type: 'instant',
555+
});
556+
});
557+
558+
it('overrides all three fields (SubnetId, InstanceType, ImageId) when specified in ec2OverrideConfig', async () => {
559+
await createRunner({
560+
...createRunnerConfig(defaultRunnerConfig),
561+
ec2OverrideConfig: {
562+
SubnetId: 'subnet-custom',
563+
InstanceType: 'c5.2xlarge',
564+
ImageId: 'ami-custom-456',
565+
},
566+
});
567+
568+
expect(mockEC2Client).toHaveReceivedCommandWith(CreateFleetCommand, {
569+
LaunchTemplateConfigs: [
570+
{
571+
LaunchTemplateSpecification: {
572+
LaunchTemplateName: 'lt-1',
573+
Version: '$Default',
574+
},
575+
Overrides: [
576+
{
577+
InstanceType: 'c5.2xlarge',
578+
SubnetId: 'subnet-custom',
579+
ImageId: 'ami-custom-456',
580+
},
581+
],
582+
},
583+
],
584+
SpotOptions: {
585+
AllocationStrategy: SpotAllocationStrategy.CAPACITY_OPTIMIZED,
586+
},
587+
TagSpecifications: expect.any(Array),
588+
TargetCapacitySpecification: {
589+
DefaultTargetCapacityType: 'spot',
590+
TotalTargetCapacity: 1,
591+
},
592+
Type: 'instant',
593+
});
594+
});
595+
596+
it('spreads additional ec2OverrideConfig properties to Overrides', async () => {
597+
await createRunner({
598+
...createRunnerConfig(defaultRunnerConfig),
599+
ec2OverrideConfig: {
600+
SubnetId: 'subnet-override',
601+
InstanceType: 't3.medium',
602+
MaxPrice: '0.05',
603+
Priority: 1.5,
604+
WeightedCapacity: 2.0,
605+
},
606+
});
607+
608+
expect(mockEC2Client).toHaveReceivedCommandWith(CreateFleetCommand, {
609+
LaunchTemplateConfigs: [
610+
{
611+
LaunchTemplateSpecification: {
612+
LaunchTemplateName: 'lt-1',
613+
Version: '$Default',
614+
},
615+
Overrides: [
616+
{
617+
InstanceType: 't3.medium',
618+
SubnetId: 'subnet-override',
619+
MaxPrice: '0.05',
620+
Priority: 1.5,
621+
WeightedCapacity: 2.0,
622+
},
623+
],
624+
},
625+
],
626+
SpotOptions: {
627+
AllocationStrategy: SpotAllocationStrategy.CAPACITY_OPTIMIZED,
628+
},
629+
TagSpecifications: expect.any(Array),
630+
TargetCapacitySpecification: {
631+
DefaultTargetCapacityType: 'spot',
632+
TotalTargetCapacity: 1,
633+
},
634+
Type: 'instant',
635+
});
636+
});
428637
});
429638

430639
describe('create runner with errors', () => {

lambdas/functions/control-plane/src/aws/runners.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,22 @@ function generateFleetOverrides(
125125
subnetIds: string[],
126126
instancesTypes: string[],
127127
amiId?: string,
128+
ec2OverrideConfig?: Runners.Ec2OverrideConfig,
128129
): FleetLaunchTemplateOverridesRequest[] {
129130
const result: FleetLaunchTemplateOverridesRequest[] = [];
130-
subnetIds.forEach((s) => {
131-
instancesTypes.forEach((i) => {
131+
132+
// Use override values if available, otherwise use parameter arrays
133+
const subnetsToUse = ec2OverrideConfig?.SubnetId ? [ec2OverrideConfig.SubnetId] : subnetIds;
134+
const instanceTypesToUse = ec2OverrideConfig?.InstanceType ? [ec2OverrideConfig.InstanceType] : instancesTypes;
135+
const amiIdToUse = ec2OverrideConfig?.ImageId ?? amiId;
136+
137+
subnetsToUse.forEach((s) => {
138+
instanceTypesToUse.forEach((i) => {
132139
const item: FleetLaunchTemplateOverridesRequest = {
133140
SubnetId: s,
134141
InstanceType: i as _InstanceType,
135-
ImageId: amiId,
142+
ImageId: amiIdToUse,
143+
...ec2OverrideConfig,
136144
};
137145
result.push(item);
138146
});
@@ -265,6 +273,7 @@ async function createInstances(
265273
runnerParameters.subnets,
266274
runnerParameters.ec2instanceCriteria.instanceTypes,
267275
amiIdOverride,
276+
runnerParameters.ec2OverrideConfig,
268277
),
269278
},
270279
],

0 commit comments

Comments
 (0)