Skip to content

Commit

Permalink
Improve error message when overrideBootstrapCommand is required for…
Browse files Browse the repository at this point in the history
… `customAMIs` (eksctl-io#6897)

* Improve error message when overrideBootstrap command is required for customAMIs

* rephrase message
  • Loading branch information
TiberiuGC authored Aug 7, 2023
1 parent 481b674 commit f07490e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkg/apis/eksctl.io/v1alpha5/managed_nodegroup_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1alpha5

import (
"fmt"

"github.com/aws/aws-sdk-go-v2/aws"
. "github.com/onsi/ginkgo/v2"

Expand Down Expand Up @@ -63,7 +65,7 @@ var _ = Describe("Managed Nodegroup Validation", func() {
AMIFamily: DefaultNodeImageFamily,
},
},
errMsg: "overrideBootstrapCommand is required when using a custom AMI",
errMsg: fmt.Sprintf("overrideBootstrapCommand is required when using a custom AMI based on %s", DefaultNodeImageFamily),
}),
Entry("Custom AMI with Windows AMI family without overrideBootstrapCommand", &nodeGroupCase{
ng: &ManagedNodeGroup{
Expand Down
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 @@ -790,7 +790,7 @@ func ValidateNodeGroup(i int, ng *NodeGroup, cfg *ClusterConfig) error {
}

if ng.AMI != "" && ng.OverrideBootstrapCommand == nil && ng.AMIFamily != NodeImageFamilyBottlerocket && !IsWindowsImage(ng.AMIFamily) {
return errors.Errorf("%[1]s.overrideBootstrapCommand is required when using a custom AMI (%[1]s.ami)", path)
return errors.Errorf("%[1]s.overrideBootstrapCommand is required when using a custom AMI based on %s (%[1]s.ami)", path, ng.AMIFamily)
}

if err := validateTaints(ng.Taints); err != nil {
Expand Down Expand Up @@ -1211,7 +1211,7 @@ func ValidateManagedNodeGroup(index int, ng *ManagedNodeGroup) error {
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)
return errors.Errorf("%[1]s.overrideBootstrapCommand is required when using a custom AMI based on %s (%[1]s.ami)", path, ng.AMIFamily)
}
notSupportedWithCustomAMIErr := func(field string) error {
return errors.Errorf("%s.%s is not supported when using a custom AMI (%s.ami)", path, field, path)
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/eksctl.io/v1alpha5/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ var _ = Describe("ClusterConfig validation", func() {
ng0.Name = "node-group"
ng0.AMI = "ami-1234"
ng0.AMIFamily = api.NodeImageFamilyAmazonLinux2
Expect(api.ValidateNodeGroup(0, ng0, cfg)).To(MatchError(ContainSubstring("overrideBootstrapCommand is required when using a custom AMI ")))
errMsg := fmt.Sprintf("overrideBootstrapCommand is required when using a custom AMI based on %s", ng0.AMIFamily)
Expect(api.ValidateNodeGroup(0, ng0, cfg)).To(MatchError(ContainSubstring(errMsg)))
})
It("should not require overrideBootstrapCommand if ami is set and type is Bottlerocket", func() {
cfg := api.NewClusterConfig()
Expand Down

0 comments on commit f07490e

Please sign in to comment.