Skip to content

Commit

Permalink
Merge pull request #354 from furkatgofurov7/add-arm64-ng
Browse files Browse the repository at this point in the history
🌱 Add Arm support for EKS NodeGroup
  • Loading branch information
furkatgofurov7 authored Feb 7, 2024
2 parents 1072bae + 4201801 commit 50af05d
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 2 deletions.
3 changes: 3 additions & 0 deletions charts/eks-operator-crd/templates/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ spec:
nodeGroups:
items:
properties:
arm:
nullable: true
type: boolean
desiredSize:
nullable: true
type: integer
Expand Down
5 changes: 5 additions & 0 deletions controller/eks-cluster-config-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ func (h *Handler) validateCreate(config *eksv1.EKSClusterConfig, awsSVCs *awsSer
if !aws.BoolValue(ng.RequestSpotInstances) && ng.InstanceType == nil {
return fmt.Errorf(cannotBeNilError, "instanceType", *ng.NodegroupName, config.Name)
}
if aws.BoolValue(ng.Arm) && ng.InstanceType == nil {
return fmt.Errorf(cannotBeNilError, "instanceType", *ng.NodegroupName, config.Name)
}
}
if ng.NodegroupName == nil {
return fmt.Errorf(cannotBeNilError, "name", *ng.NodegroupName, config.Name)
Expand Down Expand Up @@ -933,6 +936,8 @@ func BuildUpstreamClusterState(name, managedTemplateID string, clusterState *eks
ngToAdd.Gpu = aws.Bool(true)
} else if aws.StringValue(ng.Nodegroup.AmiType) == eks.AMITypesAl2X8664 {
ngToAdd.Gpu = aws.Bool(false)
} else if aws.StringValue(ng.Nodegroup.AmiType) == eks.AMITypesAl2Arm64 {
ngToAdd.Arm = aws.Bool(true)
}
upstreamSpec.NodeGroups = append(upstreamSpec.NodeGroups, ngToAdd)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/eks.cattle.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type EKSClusterConfigStatus struct {

type NodeGroup struct {
Gpu *bool `json:"gpu"`
Arm *bool `json:"arm"`
ImageID *string `json:"imageId" norman:"pointer"`
NodegroupName *string `json:"nodegroupName" norman:"required,pointer" wrangler:"required"`
DiskSize *int64 `json:"diskSize"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/eks.cattle.io/v1/zz_generated_deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/eks/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ func CreateNodeGroup(opts *CreateNodeGroupOptions) (string, string, error) {
if aws.StringValue(opts.NodeGroup.ImageID) == "" {
if opts.NodeGroup.LaunchTemplate != nil {
nodeGroupCreateInput.AmiType = aws.String(eks.AMITypesCustom)
} else if arm := opts.NodeGroup.Arm; aws.BoolValue(arm) {
nodeGroupCreateInput.AmiType = aws.String(eks.AMITypesAl2Arm64)
} else if gpu := opts.NodeGroup.Gpu; aws.BoolValue(gpu) {
nodeGroupCreateInput.AmiType = aws.String(eks.AMITypesAl2X8664Gpu)
} else {
Expand Down
56 changes: 56 additions & 0 deletions pkg/eks/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,62 @@ var _ = Describe("CreateNodeGroup", func() {
Expect(generatedNodeRole).To(Equal("test"))
})

It("set Arm ami type", func() {
createNodeGroupOpts.NodeGroup.Arm = aws.Bool(true)
createNodeGroupOpts.NodeGroup.ImageID = nil

ec2ServiceMock.EXPECT().CreateLaunchTemplateVersion(gomock.Any()).Return(&ec2.CreateLaunchTemplateVersionOutput{
LaunchTemplateVersion: &ec2.LaunchTemplateVersion{
LaunchTemplateName: aws.String("test"),
LaunchTemplateId: aws.String("test"),
VersionNumber: aws.Int64(1),
},
}, nil)

cloudFormationServiceMock.EXPECT().CreateStack(gomock.Any()).Return(nil, nil)

cloudFormationServiceMock.EXPECT().DescribeStacks(gomock.Any()).Return(
&cloudformation.DescribeStacksOutput{
Stacks: []*cloudformation.Stack{
{
StackStatus: aws.String(createCompleteStatus),
Outputs: []*cloudformation.Output{
{
OutputKey: aws.String("NodeInstanceRole"),
OutputValue: aws.String("test"),
},
},
},
},
}, nil)

eksServiceMock.EXPECT().CreateNodegroup(&eks.CreateNodegroupInput{
ClusterName: aws.String(createNodeGroupOpts.Config.Spec.DisplayName),
NodegroupName: createNodeGroupOpts.NodeGroup.NodegroupName,
Labels: createNodeGroupOpts.NodeGroup.Labels,
ScalingConfig: &eks.NodegroupScalingConfig{
DesiredSize: createNodeGroupOpts.NodeGroup.DesiredSize,
MaxSize: createNodeGroupOpts.NodeGroup.MaxSize,
MinSize: createNodeGroupOpts.NodeGroup.MinSize,
},
CapacityType: aws.String(eks.CapacityTypesSpot),
LaunchTemplate: &eks.LaunchTemplateSpecification{
Id: aws.String("test"),
Version: aws.String("1"),
},
InstanceTypes: createNodeGroupOpts.NodeGroup.SpotInstanceTypes,
Subnets: aws.StringSlice(createNodeGroupOpts.NodeGroup.Subnets),
NodeRole: aws.String("test"),
AmiType: aws.String(eks.AMITypesAl2Arm64),
}).Return(nil, nil)

launchTemplateVersion, generatedNodeRole, err := CreateNodeGroup(createNodeGroupOpts)
Expect(err).ToNot(HaveOccurred())

Expect(launchTemplateVersion).To(Equal("1"))
Expect(generatedNodeRole).To(Equal("test"))
})

It("set ami type if image id not set", func() {
createNodeGroupOpts.NodeGroup.ImageID = nil
ec2ServiceMock.EXPECT().CreateLaunchTemplateVersion(gomock.Any()).Return(&ec2.CreateLaunchTemplateVersionOutput{
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/basic_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ var _ = Describe("BasicCluster", func() {

nodeGroup := eksv1.NodeGroup{
NodegroupName: aws.String("ng1"),
Arm: aws.Bool(true),
DiskSize: aws.Int64(20),
InstanceType: aws.String("t3.medium"),
InstanceType: aws.String("a1.large"),
DesiredSize: aws.Int64(1),
MaxSize: aws.Int64(10),
MinSize: aws.Int64(1),
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ artifactsDir: ../../_artifacts
certManagerVersion: v1.11.1
certManagerChartURL: https://charts.jetstack.io/charts/cert-manager-${CERT_MANAGER_VERSION}.tgz

rancherVersion: 2.7.9
rancherVersion: 2.8.0
rancherChartURL: https://releases.rancher.com/server-charts/latest/rancher-${RANCHER_VERSION}.tgz

1 change: 1 addition & 0 deletions test/e2e/templates/basic-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spec:
diskSize: 20
ec2SshKey: ""
gpu: false
arm: false
imageId: ""
instanceType: t3.medium
labels: {}
Expand Down

0 comments on commit 50af05d

Please sign in to comment.