Skip to content

Commit

Permalink
chore(go/eks): refresh sample code and set Amazon EKS version as 1.31 (
Browse files Browse the repository at this point in the history
  • Loading branch information
guessi authored Jan 13, 2025
1 parent 1f66975 commit 7bdc840
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 126 deletions.
47 changes: 23 additions & 24 deletions go/eks/cluster-graviton/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/aws/aws-cdk-go/awscdk/v2/awseks"
"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
kubectlv28 "github.com/cdklabs/awscdk-kubectl-go/kubectlv28/v2"
kubectl "github.com/cdklabs/awscdk-kubectl-go/kubectlv31/v2"
)

type ClusterStackProps struct {
Expand All @@ -27,10 +27,10 @@ func NewClusterStack(scope constructs.Construct, id string, props *ClusterStackP
eksCluster := awseks.NewCluster(stack, jsii.String("Cluster"), &awseks.ClusterProps{
Vpc: vpc,
DefaultCapacity: jsii.Number(0), // manage capacity with managed nodegroups later since we want to customize nodegroup
KubectlLayer: kubectlv28.NewKubectlV28Layer(stack, jsii.String("kubectl128layer")),
Version: awseks.KubernetesVersion_V1_28(),
KubectlLayer: kubectl.NewKubectlV31Layer(stack, jsii.String("kubectl131layer")),
Version: awseks.KubernetesVersion_V1_31(),
AlbController: &awseks.AlbControllerOptions{
Version: awseks.AlbControllerVersion_V2_6_2(),
Version: awseks.AlbControllerVersion_V2_8_2(),
},
})

Expand All @@ -40,38 +40,37 @@ func NewClusterStack(scope constructs.Construct, id string, props *ClusterStackP
InstanceTypes: &[]awsec2.InstanceType{
awsec2.NewInstanceType(jsii.String("t4g.medium")),
},
MinSize: jsii.Number(2),
DiskSize: jsii.Number(100),
AmiType: awseks.NodegroupAmiType_AL2_ARM_64,
DesiredSize: jsii.Number(2),
MinSize: jsii.Number(2),
MaxSize: jsii.Number(5),
DiskSize: jsii.Number(100),
AmiType: awseks.NodegroupAmiType_AL2023_ARM_64_STANDARD,
})

// Fargate Profile
awseks.NewFargateProfile(stack, jsii.String("MyProfile"), &awseks.FargateProfileProps{
Cluster: eksCluster,
Selectors: &[]*awseks.Selector{
&awseks.Selector{
{
Namespace: jsii.String("default"),
},
},
})

// Managed Addon: kube-proxy
awseks.NewCfnAddon(stack, jsii.String("CfnAddonKubeProxy"), &awseks.CfnAddonProps{
AddonName: jsii.String("kube-proxy"),
ClusterName: eksCluster.ClusterName(),
})

// Managed Addon: vpc-cni
awseks.NewCfnAddon(stack, jsii.String("CfnAddonVpcCni"), &awseks.CfnAddonProps{
AddonName: jsii.String("vpc-cni"),
ClusterName: eksCluster.ClusterName(),
})
// Create common addon configuration function to reduce code duplication
addManagedAddon := func(name string, id string) {
awseks.NewCfnAddon(stack, jsii.String(id), &awseks.CfnAddonProps{
AddonName: jsii.String(name),
ClusterName: eksCluster.ClusterName(),
})
}

// Managed Addon: coredns
awseks.NewCfnAddon(stack, jsii.String("CfnAddonCoreDns"), &awseks.CfnAddonProps{
AddonName: jsii.String("coredns"),
ClusterName: eksCluster.ClusterName(),
})
// Create required addons using the helper function
addManagedAddon("kube-proxy", "CfnAddonKubeProxy")
addManagedAddon("vpc-cni", "CfnAddonVpcCni")
addManagedAddon("coredns", "CfnAddonCoreDns")
addManagedAddon("eks-pod-identity-agent", "CfnAddonEksPodIdentityAgent")
addManagedAddon("metrics-server", "CfnAddonMetricsServer")

return stack
}
Expand Down
12 changes: 9 additions & 3 deletions go/eks/cluster-graviton/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func TestClusterStack(t *testing.T) {

// Cluster
clusterVersion := template.Get("Resources.Cluster9EE0221C.Properties.Config.version").String()
assert.Equal(t, "1.28", clusterVersion)
assert.Equal(t, "1.31", clusterVersion)

ipFamily := template.Get("Resources.Cluster9EE0221C.Properties.Config.kubernetesNetworkConfig.ipFamily").String()
assert.Equal(t, "ipv4", ipFamily)

// Managed Node Group
maxSize := template.Get("Resources.ClusterNodegroupcustomnodegroupF798ADA7.Properties.ScalingConfig.MaxSize").Int()
assert.Equal(t, int64(2), maxSize)
assert.Equal(t, int64(5), maxSize)

minSize := template.Get("Resources.ClusterNodegroupcustomnodegroupF798ADA7.Properties.ScalingConfig.MinSize").Int()
assert.Equal(t, int64(2), minSize)
Expand All @@ -46,7 +46,7 @@ func TestClusterStack(t *testing.T) {
assert.Equal(t, int64(100), diskSize)

amiType := template.Get("Resources.ClusterNodegroupcustomnodegroupF798ADA7.Properties.AmiType").String()
assert.Equal(t, "AL2_ARM_64", amiType)
assert.Equal(t, "AL2023_ARM_64_STANDARD", amiType)

// Fargate
fargateProfileNamespace := template.Get("Resources.MyProfileC56205EE.Properties.Config.selectors.0.namespace").String()
Expand All @@ -62,6 +62,12 @@ func TestClusterStack(t *testing.T) {
addonNameCoreDns := template.Get("Resources.CfnAddonCoreDns.Properties.AddonName").String()
assert.Equal(t, "coredns", addonNameCoreDns)

addonNameEksPodIdentityAgent := template.Get("Resources.CfnAddonEksPodIdentityAgent.Properties.AddonName").String()
assert.Equal(t, "eks-pod-identity-agent", addonNameEksPodIdentityAgent)

addonNameMetricsServer := template.Get("Resources.CfnAddonMetricsServer.Properties.AddonName").String()
assert.Equal(t, "metrics-server", addonNameMetricsServer)

// AWS Load Balancer Controller
albRelease := template.Get("Resources.TestStackCluster8E857178AlbController95870509.Properties.Release").String()
assert.Equal(t, "aws-load-balancer-controller", albRelease)
Expand Down
32 changes: 17 additions & 15 deletions go/eks/cluster-graviton/go.mod
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
module cluster

go 1.21
go 1.23

require (
github.com/aws/aws-cdk-go/awscdk/v2 v2.130.0
github.com/aws/constructs-go/constructs/v10 v10.3.0
github.com/aws/jsii-runtime-go v1.94.0
github.com/cdklabs/awscdk-kubectl-go/kubectlv28/v2 v2.2.0
github.com/stretchr/testify v1.8.4
github.com/aws/aws-cdk-go/awscdk/v2 v2.175.1
github.com/aws/constructs-go/constructs/v10 v10.4.2
github.com/aws/jsii-runtime-go v1.106.0
github.com/cdklabs/awscdk-kubectl-go/kubectlv31/v2 v2.0.0
github.com/stretchr/testify v1.10.0

// for testing
github.com/tidwall/gjson v1.17.1
github.com/tidwall/gjson v1.18.0
)

require (
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.202 // indirect
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.2 // indirect
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.0.1 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.208 // indirect
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.3 // indirect
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.1.0 // indirect
github.com/cdklabs/cloud-assembly-schema-go/awscdkcloudassemblyschema/v39 v39.1.34 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/yuin/goldmark v1.7.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/tools v0.18.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/tools v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
64 changes: 34 additions & 30 deletions go/eks/cluster-graviton/go.sum
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/aws/aws-cdk-go/awscdk/v2 v2.130.0 h1:89c3plfxwtxV+GaY1nMjhWOFsUrufEpykrVRTa/rVYk=
github.com/aws/aws-cdk-go/awscdk/v2 v2.130.0/go.mod h1:TpmJwOnoajvRtwnLlJoxEoppb9sVoCLfPGLdgoTDH7o=
github.com/aws/constructs-go/constructs/v10 v10.3.0 h1:LsjBIMiaDX/vqrXWhzTquBJ9pPdi02/H+z1DCwg0PEM=
github.com/aws/constructs-go/constructs/v10 v10.3.0/go.mod h1:GgzwIwoRJ2UYsr3SU+JhAl+gq5j39bEMYf8ev3J+s9s=
github.com/aws/jsii-runtime-go v1.94.0 h1:VuVDx0xL2gbsJthUMfP+SwAXGkSEQd0GKm0ydZ8xga8=
github.com/aws/jsii-runtime-go v1.94.0/go.mod h1:tQOz8aAMzM2XsRUDsnUgPvGcHNAzR/xtH0OgeM0lTWo=
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.202 h1:VixXB9DnHN8oP7pXipq8GVFPjWCOdeNxIaS/ZyUwTkI=
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.202/go.mod h1:iPUti/SWjA3XAS3CpnLciFjS8TN9Y+8mdZgDfSgcyus=
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.2 h1:k+WD+6cERd59Mao84v0QtRrcdZuuSMfzlEmuIypKnVs=
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.2/go.mod h1:CvFHBo0qcg8LUkJqIxQtP1rD/sNGv9bX3L2vHT2FUAo=
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.0.1 h1:MBBQNKKPJ5GArbctgwpiCy7KmwGjHDjUUH5wEzwIq8w=
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.0.1/go.mod h1:/2WiXEft9s8ViJjD01CJqDuyJ8HXBjhBLtK5OvJfdSc=
github.com/cdklabs/awscdk-kubectl-go/kubectlv28/v2 v2.2.0 h1:KfBHrHpbF8XbPZPZTSfBEhmPv+k0MKXOxY7t0Sfpbjo=
github.com/cdklabs/awscdk-kubectl-go/kubectlv28/v2 v2.2.0/go.mod h1:G6HdIkMWjg9UL1Cgjd4bMMKFqp8I1eClgLY+IMRjnlE=
github.com/Masterminds/semver/v3 v3.3.1 h1:QtNSWtVZ3nBfk8mAOu/B6v7FMJ+NHTIgUPi7rj+4nv4=
github.com/Masterminds/semver/v3 v3.3.1/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/aws/aws-cdk-go/awscdk/v2 v2.175.1 h1:LRocYTYhy3b2xE743X7QW1zDdK/csSBj0mgKna99A1A=
github.com/aws/aws-cdk-go/awscdk/v2 v2.175.1/go.mod h1:XmbvfJtG3yL0j7qyO/5VmkzR6aVcnMM2esXp0VxKuqY=
github.com/aws/constructs-go/constructs/v10 v10.4.2 h1:+hDLTsFGLJmKIn0Dg20vWpKBrVnFrEWYgTEY5UiTEG8=
github.com/aws/constructs-go/constructs/v10 v10.4.2/go.mod h1:cXsNCKDV+9eR9zYYfwy6QuE4uPFp6jsq6TtH1MwBx9w=
github.com/aws/jsii-runtime-go v1.106.0 h1:wClD7enF+FOGR6l2TQ6STcE1nEIVKdODbipl5ZrbyC8=
github.com/aws/jsii-runtime-go v1.106.0/go.mod h1:HMdZwwcI8gpwetrneEa/RUkefS194IeCeh8eJQP3xSk=
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.208 h1:paqCb41y89OFA3+APC7buPjM6Izq8Q0yMgkGSGf/QJI=
github.com/cdklabs/awscdk-asset-awscli-go/awscliv1/v2 v2.2.208/go.mod h1:zydxApP2CyfXc3jMpJdyb1ERPNVXaCH/LJTKfWfzUBA=
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.3 h1:u63i5K09xASBNGEM0hpD2z0JwO+iNLVzG74VG85OjDo=
github.com/cdklabs/awscdk-asset-kubectl-go/kubectlv20/v2 v2.1.3/go.mod h1:0xP6iiSIKPKsShb6T2kadnTq61wL+kwmHTHnEjkFZFI=
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.1.0 h1:kElXjprC8wkpJu58vp+WFH6z0AJw4zitg5iSKJPKe3c=
github.com/cdklabs/awscdk-asset-node-proxy-agent-go/nodeproxyagentv6/v2 v2.1.0/go.mod h1:JY4UnvNa1YDGQ4H5wohXTHl6YVY3uCDUWl4JYUrQfb8=
github.com/cdklabs/awscdk-kubectl-go/kubectlv31/v2 v2.0.0 h1:avgwIb4IdgapdRMVMxj9jFm6Ndkl+bGOopi14xajaQ0=
github.com/cdklabs/awscdk-kubectl-go/kubectlv31/v2 v2.0.0/go.mod h1:FpH7j7GvSAvweZeIvSdPDEWe8/s/Lzco5GHcl+mAyQ0=
github.com/cdklabs/cloud-assembly-schema-go/awscdkcloudassemblyschema/v39 v39.1.34 h1:ObFlfGCEAIUWHZnExynucV/1pegE1mTolBpd3J9kgIk=
github.com/cdklabs/cloud-assembly-schema-go/awscdkcloudassemblyschema/v39 v39.1.34/go.mod h1:9QiFxM66GW99YsAIO06RSB2xge7wUs97jNzMOevksc0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
Expand All @@ -41,23 +45,23 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
16 changes: 10 additions & 6 deletions go/eks/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/aws/aws-cdk-go/awscdk/v2/awseks"
"github.com/aws/constructs-go/constructs/v10"
"github.com/aws/jsii-runtime-go"
kubectlv28 "github.com/cdklabs/awscdk-kubectl-go/kubectlv28/v2"
kubectl "github.com/cdklabs/awscdk-kubectl-go/kubectlv31/v2"
)

type ClusterStackProps struct {
Expand All @@ -20,25 +20,29 @@ func NewClusterStack(scope constructs.Construct, id string, props *ClusterStackP
}
stack := awscdk.NewStack(scope, &id, &sprops)

// VPC
vpc := awsec2.NewVpc(stack, jsii.String("EKSVpc"), nil) // Create a new VPC for our cluster

// Cluster
eksCluster := awseks.NewCluster(stack, jsii.String("EKSCluster"), &awseks.ClusterProps{
Vpc: vpc,
DefaultCapacity: jsii.Number(0), // manage capacity with managed nodegroups later since we want to customize nodegroup
KubectlLayer: kubectlv28.NewKubectlV28Layer(stack, jsii.String("kubectl128layer")),
Version: awseks.KubernetesVersion_V1_28(),
KubectlLayer: kubectl.NewKubectlV31Layer(stack, jsii.String("kubectl131layer")),
Version: awseks.KubernetesVersion_V1_31(),
})

// Managed Node Group
eksCluster.AddNodegroupCapacity(
jsii.String("custom-node-group"), &awseks.NodegroupOptions{
InstanceTypes: &[]awsec2.InstanceType{
awsec2.NewInstanceType(jsii.String("t3.medium")),
awsec2.NewInstanceType(jsii.String("t3a.medium")),
},
MinSize: jsii.Number(2),
DiskSize: jsii.Number(100),
AmiType: awseks.NodegroupAmiType_AL2_X86_64,
DesiredSize: jsii.Number(2),
MinSize: jsii.Number(2),
MaxSize: jsii.Number(5),
DiskSize: jsii.Number(100),
AmiType: awseks.NodegroupAmiType_AL2023_X86_64_STANDARD,
})

// Fargate Profile
Expand Down
6 changes: 3 additions & 3 deletions go/eks/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ func TestClusterStack(t *testing.T) {

// Cluster
clusterVersion := template.Get("Resources.EKSClusterE11008B6.Properties.Config.version").String()
assert.Equal(t, "1.28", clusterVersion)
assert.Equal(t, "1.31", clusterVersion)

ipFamily := template.Get("Resources.EKSClusterE11008B6.Properties.Config.kubernetesNetworkConfig.ipFamily").String()
assert.Equal(t, "ipv4", ipFamily)

// Managed Node Group
maxSize := template.Get("Resources.EKSClusterNodegroupcustomnodegroup2F3798CA.Properties.ScalingConfig.MaxSize").Int()
assert.Equal(t, int64(2), maxSize)
assert.Equal(t, int64(5), maxSize)

minSize := template.Get("Resources.EKSClusterNodegroupcustomnodegroup2F3798CA.Properties.ScalingConfig.MinSize").Int()
assert.Equal(t, int64(2), minSize)
Expand All @@ -46,7 +46,7 @@ func TestClusterStack(t *testing.T) {
assert.Equal(t, int64(100), diskSize)

amiType := template.Get("Resources.EKSClusterNodegroupcustomnodegroup2F3798CA.Properties.AmiType").String()
assert.Equal(t, "AL2_x86_64", amiType)
assert.Equal(t, "AL2023_x86_64_STANDARD", amiType)

// Fargate
fargateProfileNamespace := template.Get("Resources.MyProfileC56205EE.Properties.Config.selectors.0.namespace").String()
Expand Down
Loading

0 comments on commit 7bdc840

Please sign in to comment.