Skip to content

Commit

Permalink
Merge pull request #770 from aws-quickstart/fix/launchTemplateIssues
Browse files Browse the repository at this point in the history
Fixing Launch Template Issue #768
  • Loading branch information
elamaran11 authored Jul 12, 2023
2 parents 0020d18 + 155f0d2 commit 4b1c85f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 41 deletions.
47 changes: 8 additions & 39 deletions examples/blueprint-construct/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ function addCustomNodeGroup(): blueprints.ManagedNodeGroup {

return {
id: "mng2-customami",
amiType: NodegroupAmiType.AL2_X86_64,
instanceTypes: [new ec2.InstanceType('t3.large')],
nodeGroupCapacityType: CapacityType.SPOT,
desiredSize: 0,
Expand Down Expand Up @@ -326,52 +327,20 @@ function addCustomNodeGroup(): blueprints.ManagedNodeGroup {
}

function addWindowsNodeGroup(): blueprints.ManagedNodeGroup {

const windowsUserData = ec2.UserData.forWindows();
windowsUserData.addCommands(`
$ErrorActionPreference = 'Stop'
$EKSBootstrapScriptPath = "C:\\\\Program Files\\\\Amazon\\\\EKS\\\\Start-EKSBootstrap.ps1"
Try {
& $EKSBootstrapScriptPath -EKSClusterName 'blueprint-construct-dev'
} Catch {
Throw $_
}
`);
const ebsDeviceProps: ec2.EbsDeviceProps = {
deleteOnTermination: false,
volumeType: ec2.EbsDeviceVolumeType.GP2
};

return {
id: "mng3-windowsami",
amiType: NodegroupAmiType.AL2_X86_64,
amiType: NodegroupAmiType.WINDOWS_CORE_2019_X86_64,
instanceTypes: [new ec2.InstanceType('m5.4xlarge')],
desiredSize: 0,
minSize: 0,
nodeRole: blueprints.getNamedResource("node-role") as iam.Role,
launchTemplate: {
blockDevices: [
{
deviceName: "/dev/sda1",
volume: ec2.BlockDeviceVolume.ebs(50, ebsDeviceProps),
}
],
machineImage: ec2.MachineImage.genericWindows({
'us-east-1': 'ami-0e80b8d281637c6c1',
'us-east-2': 'ami-039ecff89038848a6',
'us-west-1': 'ami-0c0815035bf1efb6e',
'us-west-2': 'ami-029e1340b254a7667',
'eu-west-1': 'ami-09af50f599f7f882c',
'eu-west-2': 'ami-0bf1fec1eaef78230',
}),
securityGroup: blueprints.getNamedResource("my-cluster-security-group") as ec2.ISecurityGroup,
tags: {
"Name": "Mng3",
"Type": "Managed-WindowsNode-Group",
"LaunchTemplate": "WindowsLT",
"kubernetes.io/cluster/blueprint-construct-dev": "owned"
},
userData: windowsUserData,
diskSize: 50,
tags: {
"Name": "Mng3",
"Type": "Managed-WindowsNode-Group",
"LaunchTemplate": "WindowsLT",
"kubernetes.io/cluster/blueprint-construct-dev": "owned"
}
};
}
Expand Down
7 changes: 5 additions & 2 deletions lib/cluster-providers/generic-cluster-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,11 @@ export class GenericClusterProvider implements ClusterProvider {
});
const tags = Object.entries(nodeGroup.launchTemplate.tags ?? {});
tags.forEach(([key, options]) => Tags.of(lt).add(key,options));
delete nodegroupOptions.amiType;
delete nodegroupOptions.releaseVersion;
if (nodeGroup.launchTemplate?.machineImage) {
delete nodegroupOptions.amiType;
delete nodegroupOptions.releaseVersion;
delete nodeGroup.amiReleaseVersion;
}
}

const result = cluster.addNodegroupCapacity(nodeGroup.id + "-ng", nodegroupOptions);
Expand Down

0 comments on commit 4b1c85f

Please sign in to comment.