Skip to content

Commit

Permalink
fix(core): Convert group names in SpotEventPluginFleet to lowercase (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kozlove-aws committed Jun 24, 2021
1 parent 1fe72a0 commit 11e30f6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export class ConfigureSpotEventPlugin extends Construct {

const spotFleetRequestConfigurations = fleet.deadlineGroups.map(group => {
const spotFleetRequestConfiguration: SpotFleetRequestConfiguration = {
[group]: spotFleetRequestProps,
[group.toLowerCase()]: spotFleetRequestProps,
};
return spotFleetRequestConfiguration;
});
Expand Down
12 changes: 6 additions & 6 deletions packages/aws-rfdk/lib/deadline/lib/spot-event-plugin-fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF
constructor(scope: Construct, id: string, props: SpotEventPluginFleetProps) {
super(scope, id);

this.deadlineGroups = props.deadlineGroups.map(group => group.toLocaleLowerCase());
this.validateProps(props);

this.securityGroups = props.securityGroups ?? [ new SecurityGroup(this, 'SpotFleetSecurityGroup', { vpc: props.vpc }) ];
Expand Down Expand Up @@ -447,7 +448,6 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF
this.maxCapacity = props.maxCapacity;
this.validUntil = props.validUntil;
this.keyName = props.keyName;
this.deadlineGroups = props.deadlineGroups;

const imageConfig = props.workerMachineImage.getImage(this);
this.osType = imageConfig.osType;
Expand All @@ -462,8 +462,8 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF
},
renderQueue: props.renderQueue,
workerSettings: {
groups: props.deadlineGroups,
pools: props.deadlinePools,
groups: this.deadlineGroups,
pools: props.deadlinePools?.map(pool => pool.toLocaleLowerCase()),
region: props.deadlineRegion,
},
userDataProvider: props.userDataProvider,
Expand Down Expand Up @@ -498,7 +498,7 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF
this.validateFleetInstanceRole(props.fleetInstanceRole);
this.validateInstanceTypes(props.instanceTypes);
this.validateSubnets(props.vpc, props.vpcSubnets);
this.validateGroups('deadlineGroups', props.deadlineGroups);
this.validateGroups('deadlineGroups', this.deadlineGroups);
this.validateRegion('deadlineRegion', props.deadlineRegion);
this.validateBlockDevices(props.blockDevices);
}
Expand All @@ -525,13 +525,13 @@ export class SpotEventPluginFleet extends Construct implements ISpotEventPluginF
}

private validateGroups(property: string, array: string[]): void {
const regex: RegExp = /^(?!none$)[a-zA-Z0-9-_]+$/i;
const regex: RegExp = /^(?!none$)[a-z0-9-_]+$/g;
if (array.length === 0) {
throw new Error('At least one Deadline Group is required for a Spot Fleet Request Configuration');
}
array.forEach(value => {
if (!regex.test(value)) {
throw new Error(`Invalid value: ${value} for property '${property}'. Valid characters are A-Z, a-z, 0-9, - and _. Also, group 'none' is reserved as the default group.`);
throw new Error(`Invalid value: ${value} for property '${property}'. Valid characters are a-z, 0-9, - and _. Also, group 'none' is reserved as the default group.`);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let vpc: IVpc;
let renderQueue: IRenderQueue;
let rcsImage: AssetImage;

const groupName = 'group_name';
const groupName = 'Group_Name';
const deadlineGroups = [
groupName,
];
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('SpotEventPluginFleet', () => {

// THEN
expect(fleet.userData).toBeDefined();
expect(renderedUserData).toMatch(groupName);
expect(renderedUserData).toMatch(groupName.toLocaleLowerCase());
});

test('adds RFDK tags', () => {
Expand Down Expand Up @@ -360,7 +360,7 @@ describe('SpotEventPluginFleet', () => {
const imageConfig = workerMachineImage.getImage(fleet);

// THEN
expect(fleet.deadlineGroups).toBe(deadlineGroups);
expect(fleet.deadlineGroups).toStrictEqual(deadlineGroups.map(group => group.toLocaleLowerCase()));
expect(fleet.instanceTypes).toBe(instanceTypes);
expect(fleet.imageId).toBe(imageConfig.imageId);
expect(fleet.osType).toBe(imageConfig.osType);
Expand Down Expand Up @@ -642,7 +642,7 @@ describe('SpotEventPluginFleet', () => {

test('adds deadline pools to user data', () => {
// GIVEN
const pool1 = 'pool1';
const pool1 = 'Pool1';
const pool2 = 'pool2';

// WHEN
Expand All @@ -661,8 +661,8 @@ describe('SpotEventPluginFleet', () => {
const renderedUserData = fleet.userData.render();

// THEN
expect(renderedUserData).toMatch(pool1);
expect(renderedUserData).toMatch(pool2);
expect(renderedUserData).toMatch(pool1.toLocaleLowerCase());
expect(renderedUserData).toMatch(pool2.toLocaleLowerCase());
});

test('uses provided ssh key name', () => {
Expand Down

0 comments on commit 11e30f6

Please sign in to comment.