From 10e8a58f65d60c25eaf4bce7a86a007a5ab0ca60 Mon Sep 17 00:00:00 2001 From: Abhinav Pathak Date: Tue, 12 Oct 2021 11:56:00 -0700 Subject: [PATCH 1/2] add support for creating self managed Windows Nodes --- ec2config/config.go | 2 ++ eks/ng/asg.go | 16 ++++++++++++++++ eksconfig/add-on-node-groups.go | 6 +++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ec2config/config.go b/ec2config/config.go index 7efc1035d..8bb0a2256 100644 --- a/ec2config/config.go +++ b/ec2config/config.go @@ -31,6 +31,8 @@ const ( // AMITypeAL2X8664GPU is the AMI type for Amazon Linux 2 AMI with GPU. AMITypeAL2X8664GPU = "AL2_x86_64_GPU" + AMITypeWindowsServerCore2019X8664 = "WINDOWS_SERVER_CORE_2019_x86_64" + // DefaultNodeInstanceTypeCPUARM is the default EC2 instance type for CPU worker node. // https://aws.amazon.com/ec2/instance-types/m6/ DefaultNodeInstanceTypeCPUARM = "m6g.xlarge" diff --git a/eks/ng/asg.go b/eks/ng/asg.go index 965ca7dc8..c4693f2a6 100644 --- a/eks/ng/asg.go +++ b/eks/ng/asg.go @@ -371,6 +371,22 @@ func (ts *tester) fetchImageID(ssmParam string) (img string, err error) { func (ts *tester) generateUserData(asgName string, amiType string, kubeletExtraArgs string, bootstrapArgs string) (d string, err error) { switch amiType { + case ec2config.AMITypeWindowsServerCore2019X8664: + d = fmt.Sprintf(` + +[string]$EKSBinDir = "$env:ProgramFiles\Amazon\EKS" +[string]$EKSBootstrapScriptName = 'Start-EKSBootstrap.ps1' +[string]$EKSBootstrapScriptFile = "$EKSBinDir\$EKSBootstrapScriptName" +[string]$cfn_signal = "$env:ProgramFiles\Amazon\cfn-bootstrap\cfn-signal.exe" +& $EKSBootstrapScriptFile -EKSClusterName %s -Base64ClusterCA %s -APIServerEndpoint %s -KubeletExtraArgs %s 3>&1 4>&1 5>&1 6>&1 +$LastError = if ($?) { 0 } else { $Error[0].Exception.HResult } +& $cfn_signal --exit-code=$LastError --stack="${AWS::StackName}" --resource="NodeGroup" --region=${AWS::Region} +`, + ts.cfg.EKSConfig.Name, + ts.cfg.EKSConfig.Status.ClusterCA, + ts.cfg.EKSConfig.Status.ClusterAPIServerEndpoint, + fmt.Sprintf("'--node-labels=NodeType=regular,AMIType=%s,NGType=custom,NGName=%s %s'", amiType, asgName, kubeletExtraArgs)) + case ec2config.AMITypeBottleRocketCPU: d = fmt.Sprintf(`[settings.kubernetes] cluster-name = "%s" diff --git a/eksconfig/add-on-node-groups.go b/eksconfig/add-on-node-groups.go index ba145bdde..f817fbc80 100644 --- a/eksconfig/add-on-node-groups.go +++ b/eksconfig/add-on-node-groups.go @@ -240,6 +240,10 @@ func (cfg *Config) validateAddOnNodeGroups() error { if cur.RemoteAccessUserName != "ec2-user" { return fmt.Errorf("AMIType %q but unexpected RemoteAccessUserName %q", cur.AMIType, cur.RemoteAccessUserName) } + case ec2config.AMITypeWindowsServerCore2019X8664: + if cur.RemoteAccessUserName != "ec2-user" { + return fmt.Errorf("AMIType %q but unexpected RemoteAccessUserName %q", cur.AMIType, cur.RemoteAccessUserName) + } default: return fmt.Errorf("unknown ASGs[%q].AMIType %q", k, cur.AMIType) } @@ -249,7 +253,7 @@ func (cfg *Config) validateAddOnNodeGroups() error { if cur.InstanceType == "" { cur.InstanceType = DefaultNodeInstanceTypeCPU } - case fmt.Sprint(aws_eks_v2_types.AMITypesAl2X8664): + case fmt.Sprint(aws_eks_v2_types.AMITypesAl2X8664), ec2config.AMITypeWindowsServerCore2019X8664: if cur.InstanceType == "" { cur.InstanceType = DefaultNodeInstanceTypeCPU } From 67666e07e5c5944fc6e483048a7bc9fe401fe3e3 Mon Sep 17 00:00:00 2001 From: Abhinav Pathak Date: Tue, 12 Oct 2021 15:25:00 -0700 Subject: [PATCH 2/2] disable cfn-signal since we use ASG without wait condition --- eks/ng/asg.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/eks/ng/asg.go b/eks/ng/asg.go index c4693f2a6..411dab506 100644 --- a/eks/ng/asg.go +++ b/eks/ng/asg.go @@ -377,15 +377,12 @@ func (ts *tester) generateUserData(asgName string, amiType string, kubeletExtraA [string]$EKSBinDir = "$env:ProgramFiles\Amazon\EKS" [string]$EKSBootstrapScriptName = 'Start-EKSBootstrap.ps1' [string]$EKSBootstrapScriptFile = "$EKSBinDir\$EKSBootstrapScriptName" -[string]$cfn_signal = "$env:ProgramFiles\Amazon\cfn-bootstrap\cfn-signal.exe" & $EKSBootstrapScriptFile -EKSClusterName %s -Base64ClusterCA %s -APIServerEndpoint %s -KubeletExtraArgs %s 3>&1 4>&1 5>&1 6>&1 -$LastError = if ($?) { 0 } else { $Error[0].Exception.HResult } -& $cfn_signal --exit-code=$LastError --stack="${AWS::StackName}" --resource="NodeGroup" --region=${AWS::Region} `, ts.cfg.EKSConfig.Name, ts.cfg.EKSConfig.Status.ClusterCA, ts.cfg.EKSConfig.Status.ClusterAPIServerEndpoint, - fmt.Sprintf("'--node-labels=NodeType=regular,AMIType=%s,NGType=custom,NGName=%s %s'", amiType, asgName, kubeletExtraArgs)) + fmt.Sprintf(`"--node-labels=NodeType=regular,AMIType=%s,NGType=custom,NGName=%s %s"`, amiType, asgName, kubeletExtraArgs)) case ec2config.AMITypeBottleRocketCPU: d = fmt.Sprintf(`[settings.kubernetes]