Skip to content
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
merged 3 commits into from
Feb 28, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 77 additions & 76 deletions lib/builders/windows-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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 {
Expand All @@ -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"),
Expand All @@ -156,8 +151,8 @@
});
}),
managedNodeGroups: [
addGenericNodeGroup(mergedOptions),
addWindowsNodeGroup(mergedOptions)
buildGenericNodeGroup(mergedOptions),
buildWindowsNodeGroup(mergedOptions)
]
})
)
Expand Down Expand Up @@ -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) }

Check warning on line 213 in lib/builders/windows-builder.ts

View workflow job for this annotation

GitHub Actions / build (20.10.0)

Missing semicolon
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon


return {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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,
Copy link
Collaborator

Choose a reason for hiding this comment

The 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", [
Expand Down
Loading