Skip to content

Commit

Permalink
feat(deadline): adds UserData property to WorkerInstanceFleet (#781)
Browse files Browse the repository at this point in the history
This PR adds the ability to provide your own UserData object to
the deadline.WorkerInstanceFleet.

Co-authored-by: Daniel Neilson <[email protected]>
  • Loading branch information
ddneilson and Daniel Neilson authored Aug 22, 2022
1 parent 43be0a2 commit b7e48b0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/aws-rfdk/lib/deadline/lib/worker-fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Port,
SubnetSelection,
SubnetType,
UserData,
} from 'aws-cdk-lib/aws-ec2';
import {IApplicationLoadBalancerTarget} from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import {
Expand Down Expand Up @@ -223,6 +224,15 @@ export interface WorkerInstanceFleetProps extends WorkerSettings {
*/
readonly blockDevices?: BlockDevice[];

/**
* The specific UserData to use.
*
* The UserData will be mutated by this construct and may be mutated afterwards as well.
*
* @default A UserData object appropriate for the MachineImage's Operating System is created.
*/
readonly userData?: UserData;

/**
* An optional provider of user data commands to be injected at various points during the Worker configuration lifecycle.
* You can provide a subclass of InstanceUserDataProvider with the methods overridden as desired.
Expand Down Expand Up @@ -455,6 +465,7 @@ export class WorkerInstanceFleet extends WorkerInstanceFleetBase {
role: props.role,
spotPrice: props.spotPrice?.toString(),
blockDevices: props.blockDevices,
userData: props.userData,
});

this.targetCapacity = parseInt((this.fleet.node.defaultChild as CfnAutoScalingGroup).maxSize, 10);
Expand Down
20 changes: 20 additions & 0 deletions packages/aws-rfdk/lib/deadline/test/worker-fleet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Peer,
SecurityGroup,
SubnetType,
UserData,
Vpc,
} from 'aws-cdk-lib/aws-ec2';
import {
Expand Down Expand Up @@ -477,6 +478,25 @@ test.each([
});
});

test('worker fleet uses given UserData', () => {
// GIVEN
const id = 'workerFleet';
const userData = UserData.forLinux();

// WHEN
const workerFleet = new WorkerInstanceFleet(stack, id, {
vpc,
workerMachineImage: new GenericLinuxImage({
'us-east-1': '123',
}),
renderQueue,
userData,
});

// THEN
expect(workerFleet.fleet.userData).toBe(userData);
});

test('default linux worker fleet is created correctly custom subnet values', () => {
vpc = new Vpc(stack, 'VPC1Az', {
maxAzs: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,7 @@ test('decrypt private key', async () => {
// THEN
expect(decryptedKey).toEqual(expectedDecryptedKey);
// Must have the decrypted private key
expect(decryptedKey).toContain('-----BEGIN RSA PRIVATE KEY-----');
// OpenSSL 1.0.x: -----BEGIN RSA PRIVATE KEY-----
// OpenSSL 1.1.x: -----BEGIN PRIVATE KEY-----
expect(decryptedKey).toMatch(/-----BEGIN (?:RSA )?PRIVATE KEY-----/);
});

0 comments on commit b7e48b0

Please sign in to comment.