From 0cf3042c57580ab7a17f9288b791cc494bb58adf Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Tue, 11 Jul 2023 16:44:42 -0400 Subject: [PATCH 1/2] Fixing Launch Template Issue #768 --- examples/blueprint-construct/index.ts | 51 ++++--------------- .../generic-cluster-provider.ts | 7 ++- 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/examples/blueprint-construct/index.ts b/examples/blueprint-construct/index.ts index 513be4169..ad56ad9f8 100644 --- a/examples/blueprint-construct/index.ts +++ b/examples/blueprint-construct/index.ts @@ -299,10 +299,11 @@ function addCustomNodeGroup(): blueprints.ManagedNodeGroup { return { id: "mng2-customami", + amiType: NodegroupAmiType.AL2_X86_64, instanceTypes: [new ec2.InstanceType('t3.large')], nodeGroupCapacityType: CapacityType.SPOT, - desiredSize: 0, - minSize: 0, + desiredSize: 1, + minSize: 1, nodeRole: blueprints.getNamedResource("node-role") as iam.Role, launchTemplate: { tags: { @@ -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" } }; } diff --git a/lib/cluster-providers/generic-cluster-provider.ts b/lib/cluster-providers/generic-cluster-provider.ts index 6e600e6ca..983209542 100644 --- a/lib/cluster-providers/generic-cluster-provider.ts +++ b/lib/cluster-providers/generic-cluster-provider.ts @@ -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); From 155f0d2d8b4d7a8a48bfc41a37e6a938d8e5e4a2 Mon Sep 17 00:00:00 2001 From: Elamaran Shanmugam Date: Tue, 11 Jul 2023 16:46:08 -0400 Subject: [PATCH 2/2] Fixing Launch Template Issue #768 --- examples/blueprint-construct/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/blueprint-construct/index.ts b/examples/blueprint-construct/index.ts index ad56ad9f8..3f9ec2491 100644 --- a/examples/blueprint-construct/index.ts +++ b/examples/blueprint-construct/index.ts @@ -302,8 +302,8 @@ function addCustomNodeGroup(): blueprints.ManagedNodeGroup { amiType: NodegroupAmiType.AL2_X86_64, instanceTypes: [new ec2.InstanceType('t3.large')], nodeGroupCapacityType: CapacityType.SPOT, - desiredSize: 1, - minSize: 1, + desiredSize: 0, + minSize: 0, nodeRole: blueprints.getNamedResource("node-role") as iam.Role, launchTemplate: { tags: {