Skip to content

Commit 56799e4

Browse files
committed
fix: only tag spot requests if no on-demand fallback
1 parent 0f15db3 commit 56799e4

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
CreateTagsCommand,
55
DescribeInstancesCommand,
66
DescribeInstancesResult,
7+
DescribeLaunchTemplateVersionsCommand,
78
EC2Client,
89
FleetLaunchTemplateOverridesRequest,
910
Tag,
@@ -227,6 +228,22 @@ async function getAmiIdOverride(runnerParameters: Runners.RunnerInputParameters)
227228
}
228229
}
229230

231+
async function getLaunchTemplateTags(
232+
runnerParameters: Runners.RunnerInputParameters,
233+
ec2Client: EC2Client,
234+
): Promise<Tag[] | undefined> {
235+
const command = new DescribeLaunchTemplateVersionsCommand({
236+
LaunchTemplateName: runnerParameters.launchTemplateName,
237+
Versions: ['$Default'],
238+
});
239+
const response = await ec2Client.send(command);
240+
const launchTemplateTags = response.LaunchTemplateVersions?.[0]?.LaunchTemplateData?.TagSpecifications?.flatMap(
241+
({ Tags }) => Tags,
242+
).filter((tag) => tag !== undefined);
243+
244+
return launchTemplateTags || [];
245+
}
246+
230247
async function createInstances(
231248
runnerParameters: Runners.RunnerInputParameters,
232249
amiIdOverride: string | undefined,
@@ -239,6 +256,8 @@ async function createInstances(
239256
{ Key: 'ghr:Owner', Value: runnerParameters.runnerOwner },
240257
];
241258

259+
const launchTemplateTags = await getLaunchTemplateTags(runnerParameters, ec2Client);
260+
242261
if (runnerParameters.tracingEnabled) {
243262
const traceId = tracer.getRootXrayTraceId();
244263
tags.push({ Key: 'ghr:trace_id', Value: traceId! });
@@ -278,6 +297,10 @@ async function createInstances(
278297
ResourceType: 'volume',
279298
Tags: tags,
280299
},
300+
{
301+
ResourceType: 'spot-instances-request',
302+
Tags: runnerParameters.ec2instanceCriteria.targetCapacityType === 'spot' ? launchTemplateTags : undefined,
303+
},
281304
],
282305
Type: 'instant',
283306
});

modules/runners/main.tf

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,23 +206,6 @@ resource "aws_launch_template" "runner" {
206206
)
207207
}
208208

209-
dynamic "tag_specifications" {
210-
for_each = var.instance_target_capacity_type == "spot" && var.enable_on_demand_failover_for_errors == null ? [1] : [] # Include the block only if the value is "spot" and on_demand_failover_for_errors is not enabled
211-
content {
212-
resource_type = "spot-instances-request"
213-
tags = merge(
214-
local.tags,
215-
{
216-
"Name" = format("%s", local.name_runner)
217-
},
218-
{
219-
"ghr:runner_name_prefix" = var.runner_name_prefix
220-
},
221-
var.runner_ec2_tags
222-
)
223-
}
224-
}
225-
226209
tag_specifications {
227210
resource_type = "network-interface"
228211
tags = merge(

0 commit comments

Comments
 (0)