Skip to content

Commit

Permalink
Fix ManagedNodeGroup instances not registering with EKS when using en…
Browse files Browse the repository at this point in the history
…ableIMDSv2 (#1287)
  • Loading branch information
flostadler authored Jul 30, 2024
1 parent db81ca1 commit 257f0d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
7 changes: 7 additions & 0 deletions examples/managed-nodegroups/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ const managedNodeGroup2 = eks.createManagedNodeGroup(
},
cluster
);

// Create a simple AWS managed node group with IMDSv2 enabled
const managedNodeGroup3 = eks.createManagedNodeGroup("example-managed-ng3", {
cluster: cluster,
nodeRole: role2,
enableIMDSv2: true,
});
11 changes: 10 additions & 1 deletion examples/tests/managed-ng-with-version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as iam from "./iam";
// IAM roles for the node groups.
const role0 = iam.createRole("example-role0");
const role1 = iam.createRole("example-role1");
const role2 = iam.createRole("example-role2");

// Create a new VPC
const eksVpc = new awsx.ec2.Vpc("eks-vpc", {
Expand All @@ -21,7 +22,7 @@ const cluster = new eks.Cluster("example-managed-nodegroups", {
publicSubnetIds: eksVpc.publicSubnetIds,
// Private subnets will be used for cluster nodes
privateSubnetIds: eksVpc.privateSubnetIds,
instanceRoles: [role0, role1],
instanceRoles: [role0, role1, role2],
});

// Export the cluster's kubeconfig.
Expand All @@ -43,3 +44,11 @@ const managedNodeGroup1 = eks.createManagedNodeGroup("example-managed-ng1", {
nodeRoleArn: role1.arn,
version: cluster.eksCluster.version,
}, cluster);

// Managed node group with IMDSv2 enabled
const managedNodeGroup2 = eks.createManagedNodeGroup("example-managed-ng2", {
cluster: cluster,
nodeRole: role2,
version: cluster.eksCluster.version,
enableIMDSv2: true,
}, cluster);
9 changes: 6 additions & 3 deletions nodejs/eks/nodegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,10 @@ function createManagedNodeGroupInternal(
let launchTemplate: aws.ec2.LaunchTemplate | undefined;
if (args.kubeletExtraArgs || args.bootstrapExtraArgs || args.enableIMDSv2) {
launchTemplate = createMNGCustomLaunchTemplate(name, args, core, parent, provider);
// EKS doesn't allow setting the kubernetes version in the node group if a custom launch template is used.
}

if (launchTemplate?.imageId) {
// EKS doesn't allow setting the kubernetes version in the node group if an image id is provided within the launch template.
delete nodeGroupArgs.version;
}

Expand Down Expand Up @@ -1843,9 +1846,9 @@ Content-Type: text/x-shellscript; charset="us-ascii"
{
userData,
metadataOptions,
// We need to always supply an imageId, otherwise AWS will attempt to merge the user data which will result in
// We need to supply an imageId if userData is set, otherwise AWS will attempt to merge the user data which will result in
// nodes failing to join the cluster.
imageId: getRecommendedAMI(args, core.cluster.version, parent),
imageId: userData ? getRecommendedAMI(args, core.cluster.version, parent) : undefined,
},
{ parent, provider },
);
Expand Down

0 comments on commit 257f0d6

Please sign in to comment.