Skip to content

Commit

Permalink
Support custom Ubuntu AMIs for EKS-managed nodegroups (#6850)
Browse files Browse the repository at this point in the history
* Add support for managed nodegroups with custom Ubuntu AMIs

* update docs
  • Loading branch information
TiberiuGC authored Jul 27, 2023
1 parent 8287e6a commit 406d431
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/eksctl.io/v1alpha5/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,8 @@ func ValidateManagedNodeGroup(index int, ng *ManagedNodeGroup) error {
if ng.AMIFamily == "" {
return errors.Errorf("when using a custom AMI, amiFamily needs to be explicitly set via config file or via --node-ami-family flag")
}
if ng.AMIFamily != NodeImageFamilyAmazonLinux2 {
return errors.Errorf("cannot set amiFamily to %s when using a custom AMI for managed nodes, only %s is supported", ng.AMIFamily, NodeImageFamilyAmazonLinux2)
if ng.AMIFamily != NodeImageFamilyAmazonLinux2 && ng.AMIFamily != NodeImageFamilyUbuntu1804 && ng.AMIFamily != NodeImageFamilyUbuntu2004 {
return errors.Errorf("cannot set amiFamily to %s when using a custom AMI for managed nodes, only %s, %s and %s are supported", ng.AMIFamily, NodeImageFamilyAmazonLinux2, NodeImageFamilyUbuntu1804, NodeImageFamilyUbuntu2004)
}
if ng.OverrideBootstrapCommand == nil {
return errors.Errorf("%s.overrideBootstrapCommand is required when using a custom AMI (%s.ami)", path, path)
Expand Down
24 changes: 24 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,30 @@ var _ = Describe("ClusterConfig validation", func() {
Expect(err).To(MatchError("AMI Family SomeTrash is not supported - use one of: AmazonLinux2, Ubuntu2004, Ubuntu1804, Bottlerocket, WindowsServer2019CoreContainer, WindowsServer2019FullContainer, WindowsServer2022CoreContainer, WindowsServer2022FullContainer"))
})

It("fails when the AmiFamily is not supported for managed nodes with custom AMI", func() {
mng := api.NewManagedNodeGroup()
mng.AMI = "ami-1234"
mng.OverrideBootstrapCommand = aws.String("bootstrap command")

mng.AMIFamily = api.NodeImageFamilyAmazonLinux2
err := api.ValidateManagedNodeGroup(0, mng)
Expect(err).NotTo(HaveOccurred())

mng.AMIFamily = api.NodeImageFamilyUbuntu1804
err = api.ValidateManagedNodeGroup(0, mng)
Expect(err).NotTo(HaveOccurred())

mng.AMIFamily = api.NodeImageFamilyUbuntu2004
err = api.ValidateManagedNodeGroup(0, mng)
Expect(err).NotTo(HaveOccurred())

mng.AMIFamily = api.NodeImageFamilyBottlerocket
mng.OverrideBootstrapCommand = nil
err = api.ValidateManagedNodeGroup(0, mng)
errorMsg := fmt.Sprintf("cannot set amiFamily to %s when using a custom AMI for managed nodes, only %s, %s and %s are supported", mng.AMIFamily, api.NodeImageFamilyAmazonLinux2, api.NodeImageFamilyUbuntu1804, api.NodeImageFamilyUbuntu2004)
Expect(err).To(MatchError(errorMsg))
})

It("fails when the AMIFamily is WindowsServer2004CoreContainer", func() {
ng.AMIFamily = api.NodeImageFamilyWindowsServer2004CoreContainer
err := api.ValidateNodeGroup(0, ng, cfg)
Expand Down
6 changes: 6 additions & 0 deletions userdocs/src/usage/custom-ami-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ Config file example:
nodeGroups:
- name: ng1
instanceType: p2.xlarge
amiFamily: AmazonLinux2
ami: auto
- name: ng2
instanceType: m5.large
amiFamily: AmazonLinux2
ami: ami-custom1234
managedNodeGroups:
- name: m-ng-2
amiFamily: AmazonLinux2
ami: ami-custom1234
instanceType: m5.large
overrideBootstrapCommand: |
Expand Down Expand Up @@ -79,6 +82,9 @@ managedNodeGroups:

The `--node-ami-family` flag can also be used with `eksctl create nodegroup`. `eksctl` requires AMI Family to be explicitly set via config file or via `--node-ami-family` CLI flag, whenever working with a custom AMI.

???+ note
At the moment, EKS managed nodegroups only support the following AMI Families when working with custom AMIs: `AmazonLinux2`, `Ubuntu1804` and `Ubuntu2004`

## Windows custom AMI support
Only self-managed Windows nodegroups can specify a custom AMI. `amiFamily` should be set to a valid Windows AMI family.

Expand Down

0 comments on commit 406d431

Please sign in to comment.