-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change to use eks.nodeGroupOptions in the builder #895
Merged
shapirov103
merged 3 commits into
aws-quickstart:main
from
ROunofF:add-windows-karpenter
Feb 28, 2024
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,50 +21,50 @@ | |
*/ | ||
kubernetesVersion: eks.KubernetesVersion, | ||
|
||
/** | ||
* Required, Instance class to use for the cluster. | ||
/** | ||
* Required, Instance class to use for the cluster. | ||
*/ | ||
instanceClass: ec2.InstanceClass, | ||
|
||
/** | ||
* Required, Instance size to use for the cluster. | ||
/** | ||
* Required, Instance size to use for the cluster. | ||
*/ | ||
instanceSize: ec2.InstanceSize, | ||
|
||
/** | ||
* optional, Node IAM Role to be attached to Windows | ||
/** | ||
* optional, Node IAM Role to be attached to Windows | ||
* and Non-windows nodes. | ||
*/ | ||
nodeRole?: iam.Role, | ||
|
||
/** | ||
/** | ||
* Optional, AMI Type for Windows Nodes | ||
*/ | ||
windowsAmiType?: NodegroupAmiType, | ||
|
||
/** | ||
* Optional, Desired number of nodes to use for the cluster. | ||
/** | ||
* Optional, Desired number of nodes to use for the cluster. | ||
*/ | ||
desiredNodeSize?: number, | ||
desiredNodeCount?: number, | ||
|
||
/** | ||
* Optional, Minimum number of nodes to use for the cluster. | ||
/** | ||
* Optional, Minimum number of nodes to use for the cluster. | ||
*/ | ||
minNodeSize?: number, | ||
|
||
/** | ||
* Optional, Maximum number of nodes to use for the cluster. | ||
/** | ||
* Optional, Maximum number of nodes to use for the cluster. | ||
*/ | ||
maxNodeSize?: number, | ||
|
||
/** | ||
/** | ||
* Optional, Block device size. | ||
*/ | ||
blockDeviceSize?: number, | ||
|
||
/** | ||
* Optional, No Schedule for Windows Nodes, this allows Windows | ||
* nodes to be marked as no-schedule by default to prevent any | ||
* Optional, No Schedule for Windows Nodes, this allows Windows | ||
* nodes to be marked as no-schedule by default to prevent any | ||
* linux workloads from scheduling. | ||
*/ | ||
noScheduleForWindowsNodes?: boolean, | ||
|
@@ -76,24 +76,12 @@ | |
[key: string]: string; | ||
}, | ||
|
||
/** | ||
* Optional, Generic Node Group Tags for non-windows nodes | ||
* which run standard cluster software. | ||
*/ | ||
genericNodeGroupTags?: { | ||
[key: string]: string; | ||
} | ||
|
||
/** | ||
* Optional, Windows Node Group Tags. | ||
*/ | ||
windowsNodeGroupTags?: { | ||
[key: string]: string; | ||
} | ||
genericNodeGroupOptions: eks.NodegroupOptions | ||
windowsNodeGroupOptions: eks.NodegroupOptions | ||
} | ||
|
||
/** | ||
* Default props to be used when creating the non-windows and windows nodes | ||
* Default props to be used when creating the non-windows and windows nodes | ||
* for Windows EKS cluster | ||
*/ | ||
const defaultOptions: WindowsOptions = { | ||
|
@@ -102,7 +90,7 @@ | |
instanceSize: ec2.InstanceSize.XLARGE4, | ||
nodeRole: resourceproviders.getNamedResource("node-role") as iam.Role, | ||
windowsAmiType: NodegroupAmiType.WINDOWS_FULL_2022_X86_64, | ||
desiredNodeSize: 2, | ||
desiredNodeCount: 2, | ||
minNodeSize: 2, | ||
maxNodeSize: 3, | ||
blockDeviceSize: 50, | ||
|
@@ -111,21 +99,28 @@ | |
"Name": "blueprints-windows-eks-cluster", | ||
"Type": "generic-windows-cluster" | ||
}, | ||
genericNodeGroupTags: { | ||
"Name": "Mng-linux", | ||
"Type": "Managed-linux-Node-Group", | ||
"LaunchTemplate": "Linux-Launch-Template", | ||
genericNodeGroupOptions: { | ||
nodegroupName: "default-linux", | ||
tags: { | ||
"Name": "Mng-linux", | ||
"Type": "Managed-linux-Node-Group", | ||
"LaunchTemplate": "Linux-Launch-Template", | ||
} | ||
}, | ||
windowsNodeGroupTags: { | ||
"Name": "Managed-Node-Group", | ||
"Type": "Windows-Node-Group", | ||
"LaunchTemplate": "WindowsLT", | ||
"kubernetes.io/cluster/windows-eks-blueprint": "owned" | ||
windowsNodeGroupOptions: { | ||
nodegroupName: "default-windows", | ||
amiType: NodegroupAmiType.WINDOWS_CORE_2022_X86_64, | ||
tags: { | ||
"Name": "Managed-Node-Group", | ||
"Type": "Windows-Node-Group", | ||
"LaunchTemplate": "WindowsLT", | ||
"kubernetes.io/cluster/windows-eks-blueprint": "owned" | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* This builder class helps you prepare a blueprint for setting up | ||
/** | ||
* This builder class helps you prepare a blueprint for setting up | ||
* windows nodes with EKS cluster. The `WindowsBuilder` creates the following: | ||
* 1. An EKS Cluster` with passed k8s version and cluster tags. | ||
* 2. A non-windows nodegroup for standard software. | ||
|
@@ -134,7 +129,7 @@ | |
export class WindowsBuilder extends BlueprintBuilder { | ||
|
||
/** | ||
* This method helps you prepare a blueprint for setting up windows nodes with | ||
* This method helps you prepare a blueprint for setting up windows nodes with | ||
* usage tracking addon | ||
*/ | ||
public static builder(options: WindowsOptions): WindowsBuilder { | ||
|
@@ -147,7 +142,7 @@ | |
version: mergedOptions.kubernetesVersion, | ||
tags: mergedOptions.clusterProviderTags, | ||
role: resourceproviders.getResource(context => { | ||
return new iam.Role(context.scope, 'ClusterRole', { | ||
return new iam.Role(context.scope, 'ClusterRole', { | ||
assumedBy: new iam.ServicePrincipal("eks.amazonaws.com"), | ||
managedPolicies: [ | ||
iam.ManagedPolicy.fromAwsManagedPolicyName("AmazonEKSClusterPolicy"), | ||
|
@@ -156,8 +151,8 @@ | |
}); | ||
}), | ||
managedNodeGroups: [ | ||
addGenericNodeGroup(mergedOptions), | ||
addWindowsNodeGroup(mergedOptions) | ||
buildGenericNodeGroup(mergedOptions), | ||
buildWindowsNodeGroup(mergedOptions) | ||
] | ||
}) | ||
) | ||
|
@@ -191,47 +186,53 @@ | |
} | ||
} | ||
|
||
/** | ||
* This function adds a generic node group to the windows cluster. | ||
/** | ||
* Return the instanceType based off nodegroup or if not defined from options instanceClass and instanceSize. Default to m5.4xlarge | ||
* @param nodegroupOptions To override instanceType return | ||
* @param nodegroup default cluster level settings | ||
* @returns clusterprovider.ManagedNodeGroup | ||
*/ | ||
function getInstanceType(nodegroupOptions: eks.NodegroupOptions, windowsOptions: WindowsOptions): ec2.InstanceType[] { | ||
|
||
if ( nodegroupOptions.instanceTypes ) { return nodegroupOptions.instanceTypes; } | ||
|
||
if ( windowsOptions.instanceClass && windowsOptions.instanceSize ) | ||
return [ new ec2.InstanceType(`${windowsOptions.instanceClass}.${windowsOptions.instanceSize}`) ]; | ||
|
||
return [ new ec2.InstanceType('m5.4xlarge')]; | ||
} | ||
|
||
/** | ||
* This function adds a generic node group to the cluster. | ||
* @param: options: WindowsOptions | ||
* @returns: blueprints.ManagedNodeGroup | ||
*/ | ||
function addGenericNodeGroup(options: WindowsOptions): clusterproviders.ManagedNodeGroup { | ||
function buildGenericNodeGroup(options: WindowsOptions, overrideOptions?: eks.NodegroupOptions): clusterproviders.ManagedNodeGroup { | ||
|
||
let currentOptions = options.genericNodeGroupOptions; | ||
if ( overrideOptions ) { currentOptions = merge(options.genericNodeGroupOptions, overrideOptions) } | ||
|
||
return { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the GH action issue |
||
id: "mng-linux", | ||
amiType: NodegroupAmiType.AL2_X86_64, | ||
instanceTypes: [new ec2.InstanceType('m5.4xlarge')], | ||
desiredSize: options.desiredNodeSize, | ||
minSize: options.minNodeSize, | ||
maxSize: options.maxNodeSize, | ||
nodeRole: options.nodeRole, | ||
id: currentOptions.nodegroupName || "", | ||
amiType: currentOptions.amiType, | ||
instanceTypes: getInstanceType(currentOptions, options), | ||
desiredSize: currentOptions.desiredSize, | ||
minSize: currentOptions.minSize, | ||
maxSize: currentOptions.maxSize, | ||
nodeRole: currentOptions.nodeRole, | ||
nodeGroupSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, | ||
launchTemplate: { | ||
tags: options.genericNodeGroupTags, | ||
requireImdsv2: false | ||
} | ||
tags: currentOptions.tags, | ||
}; | ||
} | ||
|
||
/** | ||
* This function adds a windows node group to the windows cluster. | ||
* This function adds a windows node group to the cluster. | ||
* @param options: WindowsOptions | ||
* @returns: blueprints.ManagedNodeGroup | ||
*/ | ||
function addWindowsNodeGroup(options: WindowsOptions): clusterproviders.ManagedNodeGroup { | ||
const result : clusterproviders.ManagedNodeGroup = { | ||
id: "mng-windows", | ||
amiType: options.windowsAmiType, | ||
instanceTypes: [new ec2.InstanceType(`${options.instanceClass}.${options.instanceSize}`)], | ||
desiredSize: options.desiredNodeSize, | ||
minSize: options.minNodeSize, | ||
maxSize: options.maxNodeSize, | ||
nodeRole: options.nodeRole, | ||
nodeGroupSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, | ||
diskSize: options.blockDeviceSize, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this property removed? |
||
tags: options.windowsNodeGroupTags | ||
}; | ||
function buildWindowsNodeGroup(options: WindowsOptions): clusterproviders.ManagedNodeGroup { | ||
|
||
const result = buildGenericNodeGroup(options, options.windowsNodeGroupOptions); | ||
|
||
if(options.noScheduleForWindowsNodes) { | ||
utils.setPath(result, "taints", [ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon