From a626e373fe0f7b07a0df866ce9c65f9209666bff Mon Sep 17 00:00:00 2001 From: Carter Date: Wed, 4 Dec 2024 06:55:52 -0800 Subject: [PATCH] Add support for auto mode (#518) --- kubetest2/go.mod | 10 +++---- kubetest2/go.sum | 20 ++++++------- .../internal/deployers/eksapi/cluster.go | 19 +++++++++++++ .../internal/deployers/eksapi/deployer.go | 3 +- .../deployers/eksapi/templates/infra.yaml | 28 +++++++++++++++++-- 5 files changed, 61 insertions(+), 19 deletions(-) diff --git a/kubetest2/go.mod b/kubetest2/go.mod index e8048ff02..09a935a69 100644 --- a/kubetest2/go.mod +++ b/kubetest2/go.mod @@ -6,14 +6,14 @@ toolchain go1.23.0 require ( github.com/aws/aws-sdk-go v1.51.2 - github.com/aws/aws-sdk-go-v2 v1.32.2 + github.com/aws/aws-sdk-go-v2 v1.32.6 github.com/aws/aws-sdk-go-v2/config v1.27.8 github.com/aws/aws-sdk-go-v2/service/autoscaling v1.40.4 github.com/aws/aws-sdk-go-v2/service/cloudformation v1.48.0 github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.36.3 github.com/aws/aws-sdk-go-v2/service/ec2 v1.151.1 - github.com/aws/aws-sdk-go-v2/service/eks v1.41.2 - github.com/aws/smithy-go v1.22.0 + github.com/aws/aws-sdk-go-v2/service/eks v1.53.0 + github.com/aws/smithy-go v1.22.1 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/octago/sflags v0.2.0 github.com/spf13/pflag v1.0.5 @@ -84,8 +84,8 @@ require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.17.8 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.4 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.25 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.25 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect github.com/aws/aws-sdk-go-v2/service/ecr v1.27.3 // indirect github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.23.3 // indirect diff --git a/kubetest2/go.sum b/kubetest2/go.sum index 487def019..374078df9 100644 --- a/kubetest2/go.sum +++ b/kubetest2/go.sum @@ -130,18 +130,18 @@ github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHS github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY= github.com/aws/aws-sdk-go v1.51.2 h1:Ruwgz5aqIXin5Yfcgc+PCzoqW5tEGb9aDL/JWDsre7k= github.com/aws/aws-sdk-go v1.51.2/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= -github.com/aws/aws-sdk-go-v2 v1.32.2 h1:AkNLZEyYMLnx/Q/mSKkcMqwNFXMAvFto9bNsHqcTduI= -github.com/aws/aws-sdk-go-v2 v1.32.2/go.mod h1:2SK5n0a2karNTv5tbP1SjsX0uhttou00v/HpXKM1ZUo= +github.com/aws/aws-sdk-go-v2 v1.32.6 h1:7BokKRgRPuGmKkFMhEg/jSul+tB9VvXhcViILtfG8b4= +github.com/aws/aws-sdk-go-v2 v1.32.6/go.mod h1:P5WJBrYqqbWVaOxgH0X/FYYD47/nooaPOZPlQdmiN2U= github.com/aws/aws-sdk-go-v2/config v1.27.8 h1:0r8epOsiJ7YJz65MGcb8i91ehFp4kvvFe2qkq5oYeRI= github.com/aws/aws-sdk-go-v2/config v1.27.8/go.mod h1:XsmYKxYNuIhLsFddpNds+j9H5XKzjWDdg/SZngiwFio= github.com/aws/aws-sdk-go-v2/credentials v1.17.8 h1:WUdNLXbyNbU07V/WFrSOBXqZTDgmmMNMgUFzpYOKJhw= github.com/aws/aws-sdk-go-v2/credentials v1.17.8/go.mod h1:iPZzLpaBIfhyvVS/XGD3JvR1GP3YdHTqpySKDlqkfs8= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.4 h1:S+L2QSKhUuShih3aq9P/mkzDBiOO5tTyVg+vXREfsfg= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.15.4/go.mod h1:nQ3how7DMnFMWiU1SpECohgC82fpn4cKZ875NDMmwtA= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21 h1:UAsR3xA31QGf79WzpG/ixT9FZvQlh5HY1NRqSHBNOCk= -github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.21/go.mod h1:JNr43NFf5L9YaG3eKTm7HQzls9J+A9YYcGI5Quh1r2Y= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21 h1:6jZVETqmYCadGFvrYEQfC5fAQmlo80CeL5psbno6r0s= -github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.21/go.mod h1:1SR0GbLlnN3QUmYaflZNiH1ql+1qrSiB2vwcJ+4UM60= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.25 h1:s/fF4+yDQDoElYhfIVvSNyeCydfbuTKzhxSXDXCPasU= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.25/go.mod h1:IgPfDv5jqFIzQSNbUEMoitNooSMXjRSDkhXv8jiROvU= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.25 h1:ZntTCl5EsYnhN/IygQEUugpdwbhdkom9uHcbCftiGgA= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.25/go.mod h1:DBdPrgeocww+CSl1C8cEV8PN1mHMBhuCDLpXezyvWkE= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= github.com/aws/aws-sdk-go-v2/service/autoscaling v1.40.4 h1:f4pkN5PVSqlGxD2gZvboz6SRaeoykgknflMPBVuhcGs= @@ -156,8 +156,8 @@ github.com/aws/aws-sdk-go-v2/service/ecr v1.27.3 h1:gfgt0D8MGL3gHrJPEv4rcWptA4Nz github.com/aws/aws-sdk-go-v2/service/ecr v1.27.3/go.mod h1:O5Fvd41s5KfDG093xLM7FhGiH6EmhmEli5D5MQH3TWw= github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.23.3 h1:gaq/4fd2/bQeJ33m4csgL7DJHrrmvGhqnrsxchNr46c= github.com/aws/aws-sdk-go-v2/service/ecrpublic v1.23.3/go.mod h1:vn+Rz9fAFGJtDXbBmYdTc71Q8iF/W/uK1/ec93hinD8= -github.com/aws/aws-sdk-go-v2/service/eks v1.41.2 h1:0X5g5H8YyW9QVtlp6j+ZGHl/h0ZS58jiLRXabyiB5uw= -github.com/aws/aws-sdk-go-v2/service/eks v1.41.2/go.mod h1:T2MBMUUCoSEvHuKPplubyQJbWNghbHhx3ToJpLoipDs= +github.com/aws/aws-sdk-go-v2/service/eks v1.53.0 h1:ACTxnLwL6YNmuYbxtp/VR3HGL9SWXU6VZkXPjWST9ZQ= +github.com/aws/aws-sdk-go-v2/service/eks v1.53.0/go.mod h1:ZzOjZXGGUQxOq+T3xmfPLKCZe4OaB5vm1LdGaC8IPn4= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 h1:EyBZibRTVAs6ECHZOw5/wlylS9OcTzwyjeQMudmREjE= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1/go.mod h1:JKpmtYhhPs7D97NL/ltqz7yCkERFW5dOlHyVl66ZYF8= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.6 h1:b+E7zIUHMmcB4Dckjpkapoy47W6C9QBv/zoUP+Hn8Kc= @@ -172,8 +172,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3 h1:uLq0BKatTmDzWa/Nu4WO0M1A github.com/aws/aws-sdk-go-v2/service/ssooidc v1.23.3/go.mod h1:b+qdhjnxj8GSR6t5YfphOffeoQSQ1KmpoVVuBn+PWxs= github.com/aws/aws-sdk-go-v2/service/sts v1.28.5 h1:J/PpTf/hllOjx8Xu9DMflff3FajfLxqM5+tepvVXmxg= github.com/aws/aws-sdk-go-v2/service/sts v1.28.5/go.mod h1:0ih0Z83YDH/QeQ6Ori2yGE2XvWYv/Xm+cZc01LC6oK0= -github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM= -github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= +github.com/aws/smithy-go v1.22.1 h1:/HPHZQ0g7f4eUeK6HKglFz8uwVfZKgoI25rb/J+dnro= +github.com/aws/smithy-go v1.22.1/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20240318154307-a1a918375412 h1:tfbmGNeOidVXzO1I7zo/WsT5QX7Aa0BGTbnEAE4FG3E= github.com/awslabs/amazon-ecr-credential-helper/ecr-login v0.0.0-20240318154307-a1a918375412/go.mod h1:kcUkjB9HwuV7PSck2b60kJtgDy+eTHWuAP0kb93FXsk= github.com/awslabs/operatorpkg v0.0.0-20240805231134-67d0acfb6306 h1:0dzaVod1XLEc38H4IB+KOgStoCt8RkCVI4t+XsSPrWE= diff --git a/kubetest2/internal/deployers/eksapi/cluster.go b/kubetest2/internal/deployers/eksapi/cluster.go index df48d9678..c5678e029 100644 --- a/kubetest2/internal/deployers/eksapi/cluster.go +++ b/kubetest2/internal/deployers/eksapi/cluster.go @@ -56,6 +56,25 @@ func (m *ClusterManager) getOrCreateCluster(infra *Infrastructure, opts *deploye }, Version: aws.String(opts.KubernetesVersion), } + if opts.AutoMode { + input.ComputeConfig = &ekstypes.ComputeConfigRequest{ + Enabled: aws.Bool(true), + NodePools: []string{"general-purpose", "system"}, + NodeRoleArn: &infra.nodeRole, + } + input.StorageConfig = &ekstypes.StorageConfigRequest{ + BlockStorage: &ekstypes.BlockStorage{ + Enabled: aws.Bool(true), + }, + } + input.KubernetesNetworkConfig.ElasticLoadBalancing = &ekstypes.ElasticLoadBalancing{ + Enabled: aws.Bool(true), + } + input.AccessConfig = &ekstypes.CreateAccessConfigRequest{ + AuthenticationMode: ekstypes.AuthenticationModeApi, + } + input.BootstrapSelfManagedAddons = aws.Bool(false) + } apiOpts, err := util.NewHTTPHeaderAPIOptions(opts.UpClusterHeaders) if err != nil { return nil, fmt.Errorf("failed to create API options: %v", err) diff --git a/kubetest2/internal/deployers/eksapi/deployer.go b/kubetest2/internal/deployers/eksapi/deployer.go index dac259f44..0b582b92a 100644 --- a/kubetest2/internal/deployers/eksapi/deployer.go +++ b/kubetest2/internal/deployers/eksapi/deployer.go @@ -59,6 +59,7 @@ type deployerOptions struct { Addons []string `flag:"addons" desc:"Managed addons (name:version pairs) to create in the cluster. Use 'latest' for the most recent version, or 'default' for the default version."` AMI string `flag:"ami" desc:"AMI for unmanaged nodes"` AMIType string `flag:"ami-type" desc:"AMI type for managed nodes"` + AutoMode bool `flag:"auto-mode" desc:"Enable EKS Auto Mode"` CapacityReservation bool `flag:"capacity-reservation" desc:"Use capacity reservation for the unmanaged nodegroup"` ClusterRoleServicePrincipal string `flag:"cluster-role-service-principal" desc:"Additional service principal that can assume the cluster role"` EFA bool `flag:"efa" desc:"Create EFA interfaces on the node of an unmanaged nodegroup. Requires --unmanaged-nodes."` @@ -188,7 +189,7 @@ func (d *deployer) Up() error { if err != nil { return err } - if d.deployerOptions.StaticClusterName != "" { + if d.deployerOptions.StaticClusterName != "" || d.deployerOptions.AutoMode { klog.Infof("inited k8sclient, skip the rest resource creation for static cluster") d.staticClusterManager.SetK8sClient(kubeconfig) if err := d.staticClusterManager.EnsureNodeForStaticCluster(); err != nil { diff --git a/kubetest2/internal/deployers/eksapi/templates/infra.yaml b/kubetest2/internal/deployers/eksapi/templates/infra.yaml index 6e70a3211..d7d504c1e 100644 --- a/kubetest2/internal/deployers/eksapi/templates/infra.yaml +++ b/kubetest2/internal/deployers/eksapi/templates/infra.yaml @@ -41,7 +41,7 @@ Parameters: Subnet01AZ: Type: String - + Subnet02AZ: Type: String @@ -196,7 +196,7 @@ Resources: Type: AWS::EC2::Route DependsOn: - InternetGateway - - VPCGatewayAttachment + - VPCGatewayAttachment Properties: DestinationIpv6CidrBlock: ::/0 GatewayId: @@ -401,7 +401,9 @@ Resources: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - - Action: "sts:AssumeRole" + - Action: + - "sts:AssumeRole" + - "sts:TagSession" Effect: Allow Principal: Service: @@ -416,6 +418,26 @@ Resources: - - "arn:" - !Ref "AWS::Partition" - ":iam::aws:policy/AmazonEKSClusterPolicy" + - !Join + - "" + - - "arn:" + - !Ref "AWS::Partition" + - ":iam::aws:policy/AmazonEKSBlockStoragePolicy" + - !Join + - "" + - - "arn:" + - !Ref "AWS::Partition" + - ":iam::aws:policy/AmazonEKSComputePolicy" + - !Join + - "" + - - "arn:" + - !Ref "AWS::Partition" + - ":iam::aws:policy/AmazonEKSLoadBalancingPolicy" + - !Join + - "" + - - "arn:" + - !Ref "AWS::Partition" + - ":iam::aws:policy/AmazonEKSNetworkingPolicy" NodeRole: Type: AWS::IAM::Role