Skip to content

Commit b3adb27

Browse files
authored
Adds additional tests to getRunnerTypes, simplifies code a bit, adds the support for c. runners (#6403)
## Support for `c.` runners We don't really support well our canary environment with variants, not sure why, but this condition was not present, so variants will get the wrong naming when running at meta canary environment. `variant.c.runner.name` instead of `c.variant.runner.name`. This fix is very low impact and should not change anything in production. ## Simplifies the code There is a useless `if` that I noticed when reading `getRunnerTypes`. I am removing that conditional; ## Additional tests for getRunnerTypes As we're adding empty variants as part of the ephemeral migration, I want to make sure that we have green tests and we're covering this situation in our unit tests. The new situations to cover are: 1) Empty variants 2) meta's canary environment naming convention `c.`
1 parent 749d206 commit b3adb27

File tree

2 files changed

+65
-20
lines changed

2 files changed

+65
-20
lines changed

Diff for: terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/gh-runners.test.ts

+45
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,23 @@ runner_types:
695695
variants:
696696
ephemeral:
697697
is_ephemeral: true
698+
c.linux.4xlarge:
699+
instance_type: c5.2xlarge
700+
os: linux
701+
min_available: 1
702+
max_available: 1
703+
disk_size: 150
704+
is_ephemeral: false
705+
variants:
706+
dummyvariant: {}
698707
lf.c.linux.4xlarge:
699708
instance_type: c5.2xlarge
700709
os: linux
701710
min_available: 1
702711
disk_size: 150
703712
is_ephemeral: false
704713
variants:
714+
dummyvariant: {}
705715
ephemeral:
706716
is_ephemeral: true`;
707717

@@ -766,6 +776,30 @@ runner_types:
766776
ami: 'ami-123',
767777
},
768778
],
779+
[
780+
'c.dummyvariant.linux.4xlarge',
781+
{
782+
runnerTypeName: 'c.dummyvariant.linux.4xlarge',
783+
instance_type: 'c5.2xlarge',
784+
os: 'linux',
785+
min_available: 1,
786+
max_available: 1,
787+
disk_size: 150,
788+
is_ephemeral: false,
789+
},
790+
],
791+
[
792+
'c.linux.4xlarge',
793+
{
794+
runnerTypeName: 'c.linux.4xlarge',
795+
instance_type: 'c5.2xlarge',
796+
os: 'linux',
797+
min_available: 1,
798+
max_available: 1,
799+
disk_size: 150,
800+
is_ephemeral: false,
801+
},
802+
],
769803
[
770804
'lf.linux.4xlarge',
771805
{
@@ -801,6 +835,17 @@ runner_types:
801835
is_ephemeral: false,
802836
},
803837
],
838+
[
839+
'lf.c.dummyvariant.linux.4xlarge',
840+
{
841+
runnerTypeName: 'lf.c.dummyvariant.linux.4xlarge',
842+
instance_type: 'c5.2xlarge',
843+
os: 'linux',
844+
min_available: 1,
845+
disk_size: 150,
846+
is_ephemeral: false,
847+
},
848+
],
804849
[
805850
'lf.c.ephemeral.linux.4xlarge',
806851
{

Diff for: terraform-aws-github-runner/modules/runners/lambdas/runners/src/scale-runners/gh-runners.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -377,26 +377,26 @@ export async function getRunnerTypes(
377377
return;
378378
}
379379

380-
if (runnerType.variants.size > 0) {
381-
Array.from(runnerType.variants.keys()).forEach((variant) => {
382-
const variantType = runnerType.variants?.get(variant);
383-
/* istanbul ignore next */
384-
if (!variantType) {
385-
return;
386-
}
387-
388-
let variantRunnTypeName: string;
389-
if (key.startsWith('lf.c.')) {
390-
variantRunnTypeName = `lf.c.${variant}.${key.slice(5)}`;
391-
} else if (key.startsWith('lf.')) {
392-
variantRunnTypeName = `lf.${variant}.${key.slice(3)}`;
393-
} else {
394-
variantRunnTypeName = `${variant}.${key}`;
395-
}
396-
397-
result.set(variantRunnTypeName, { ...runnerType, ...variantType, runnerTypeName: variantRunnTypeName });
398-
});
399-
}
380+
Array.from(runnerType.variants.keys()).forEach((variant) => {
381+
const variantType = runnerType.variants?.get(variant);
382+
/* istanbul ignore next */
383+
if (!variantType) {
384+
return;
385+
}
386+
387+
let variantRunnTypeName: string;
388+
if (key.startsWith('lf.c.')) {
389+
variantRunnTypeName = `lf.c.${variant}.${key.slice(5)}`;
390+
} else if (key.startsWith('lf.')) {
391+
variantRunnTypeName = `lf.${variant}.${key.slice(3)}`;
392+
} else if (key.startsWith('c.')) {
393+
variantRunnTypeName = `c.${variant}.${key.slice(2)}`;
394+
} else {
395+
variantRunnTypeName = `${variant}.${key}`;
396+
}
397+
398+
result.set(variantRunnTypeName, { ...runnerType, ...variantType, runnerTypeName: variantRunnTypeName });
399+
});
400400
});
401401

402402
const filteredResult: Map<string, RunnerType> = new Map(

0 commit comments

Comments
 (0)