-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Managed Node Group launch template disk size fix (#1305)
This fixes the handling of disk size changes when a custom launch template is created for the MNG. It is based on the Community PR #1229 by @JustASquid, I just added some test fixes on top. Fixes #1228 --------- Co-authored-by: Daniel West <daniel.west.279@gmail.com>
- Loading branch information
1 parent
0c527e3
commit 180f88b
Showing
10 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
name: managed-ng-disk-size | ||
description: Tests that disk size can be specified correctly when a custom launch template is automatically created. | ||
runtime: nodejs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# tests/managed-ng-disk-size | ||
|
||
Tests that disk size can be specified correctly when a custom launch template is automatically created. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import * as aws from "@pulumi/aws"; | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as iam from "./iam"; | ||
|
||
const managedPolicyArns: string[] = [ | ||
"arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy", | ||
"arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy", | ||
"arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly", | ||
]; | ||
|
||
// Creates a role and attaches the EKS worker node IAM managed policies | ||
export function createRole(name: string): aws.iam.Role { | ||
const role = new aws.iam.Role(name, { | ||
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ | ||
Service: "ec2.amazonaws.com", | ||
}), | ||
}); | ||
|
||
let counter = 0; | ||
for (const policy of managedPolicyArns) { | ||
// Create RolePolicyAttachment without returning it. | ||
const rpa = new aws.iam.RolePolicyAttachment(`${name}-policy-${counter++}`, | ||
{ policyArn: policy, role: role }, | ||
); | ||
} | ||
|
||
return role; | ||
} | ||
|
||
// Creates a collection of IAM roles. | ||
export function createRoles(name: string, quantity: number): aws.iam.Role[] { | ||
const roles: aws.iam.Role[] = []; | ||
|
||
for (let i = 0; i < quantity; i++) { | ||
roles.push(iam.createRole(`${name}-role-${i}`)); | ||
} | ||
|
||
return roles; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as awsx from '@pulumi/awsx'; | ||
import * as eks from "@pulumi/eks"; | ||
import * as pulumi from "@pulumi/pulumi"; | ||
import * as iam from "./iam"; | ||
|
||
const eksVpc = new awsx.ec2.Vpc("eks-vpc", { | ||
enableDnsHostnames: true, | ||
cidrBlock: "10.0.0.0/16", | ||
}); | ||
|
||
// IAM roles for the node groups. | ||
const role = iam.createRole("example-role"); | ||
|
||
const projectName = pulumi.getProject(); | ||
|
||
const cluster = new eks.Cluster(`${projectName}`, { | ||
skipDefaultNodeGroup: true, | ||
deployDashboard: false, | ||
vpcId: eksVpc.vpcId, | ||
// Public subnets will be used for load balancers | ||
publicSubnetIds: eksVpc.publicSubnetIds, | ||
// Private subnets will be used for cluster nodes | ||
privateSubnetIds: eksVpc.privateSubnetIds, | ||
instanceRoles: [role], | ||
}); | ||
|
||
// Export the cluster's kubeconfig. | ||
export const kubeconfig = cluster.kubeconfig; | ||
|
||
// Create a managed node group using a cluster as input. | ||
eks.createManagedNodeGroup(`${projectName}-managed-ng`, { | ||
cluster: cluster, | ||
nodeRole: role, | ||
// Force creating a custom launch template | ||
bootstrapExtraArgs: "--max-pods=500", | ||
diskSize: 50, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "managed-ng-disk-size", | ||
"devDependencies": { | ||
"typescript": "^4.0.0", | ||
"@types/node": "latest" | ||
}, | ||
"dependencies": { | ||
"@pulumi/pulumi": "^3.0.0", | ||
"@pulumi/aws": "^6.0.0", | ||
"@pulumi/eks": "latest", | ||
"@pulumi/awsx": "^2.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "bin", | ||
"target": "es6", | ||
"lib": [ | ||
"es6" | ||
], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"declaration": true, | ||
"sourceMap": true, | ||
"stripInternal": true, | ||
"experimentalDecorators": true, | ||
"pretty": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitAny": true, | ||
"noImplicitReturns": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"strictNullChecks": true | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters