Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail early when instance selector returns too many instances #4139

Merged
merged 2 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/eks/nodegroup_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
"github.com/weaveworks/eksctl/pkg/vpc"
)

// MaxInstanceTypes is the maximum number of instance types you can specify in
// a CloudFormation template
const maxInstanceTypes = 40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyone know if there is a const in aws which already covers this?


//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate

//counterfeiter:generate -o fakes/fake_instance_selector.go . InstanceSelector
Expand Down Expand Up @@ -136,6 +140,10 @@ func (m *NodeGroupService) ExpandInstanceSelectorOptions(nodePools []api.NodePoo
return errors.Wrapf(err, "error expanding instance selector options for nodegroup %q", baseNG.Name)
}

if len(instanceTypes) > maxInstanceTypes {
return errors.Errorf("instance selector filters resulted in %d instance types, which is greater than the maximum of %d, please set more selector options", len(instanceTypes), maxInstanceTypes)
}

switch ng := np.(type) {
case *api.NodeGroup:
if ng.InstancesDistribution == nil {
Expand Down
24 changes: 24 additions & 0 deletions pkg/eks/nodegroup_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ var _ = Describe("Instance Selector", func() {
expectedErr: "instance selector criteria matched no instances",
}),

Entry("too many matching instances", instanceSelectorCase{
nodeGroups: []api.NodePool{
&api.NodeGroup{
NodeGroupBase: &api.NodeGroupBase{},
},
&api.ManagedNodeGroup{
NodeGroupBase: &api.NodeGroupBase{},
},
},
instanceSelectorValue: &api.InstanceSelector{
CPUArchitecture: "arm64",
},
createFakeInstanceSelector: makeInstanceSelector(tooManyTypes()...),
expectedErr: "instance selector filters resulted in 41 instance types, which is greater than the maximum of 40, please set more selector options",
}),

Entry("nodeGroup with instancesDistribution set", instanceSelectorCase{
nodeGroups: []api.NodePool{
&api.NodeGroup{
Expand Down Expand Up @@ -201,3 +217,11 @@ var _ = Describe("Instance Selector", func() {
}),
)
})

func tooManyTypes() []string {
instances := make([]string, 41)
for i := range instances {
instances[i] = "c3.large"
}
return instances
}