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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move lowest-n instance type options to generic packing pkg #456

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions pkg/cloudprovider/aws/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ import (
v1 "k8s.io/api/core/v1"
)

const (
// maxInstanceTypes defines the number of instance type options to pass to fleet
maxInstanceTypes = 20
)

type InstanceProvider struct {
ec2api ec2iface.EC2API
}
Expand All @@ -48,17 +43,7 @@ func (p *InstanceProvider) Create(ctx context.Context,
zonalSubnetOptions map[string][]*ec2.Subnet,
capacityType string,
) (*string, error) {
// 1. Trim the instanceTypeOptions so that the fleet request doesn't get too large
// If ~130 instance types are passed into fleet, the request can exceed the EC2 request size limit (145kb)
// due to the overrides expansion for subnetId (depends on number of AZs), Instance Type, and Priority.
// For spot capacity-optimized-prioritized, the request should be smaller to prevent using
// excessively large instance types that are more plentiful in capacity which the algorithm will bias towards.
// packing.InstanceTypes is sorted by vcpus and memory ascending so it's safe to trim the end of the list
// to remove excessively large instance types
if len(instanceTypeOptions) > maxInstanceTypes {
instanceTypeOptions = instanceTypeOptions[:maxInstanceTypes]
}
// 2. Construct override options.
// 1. Construct override options.
var overrides []*ec2.FleetLaunchTemplateOverridesRequest
for i, instanceType := range instanceTypeOptions {
for _, zone := range instanceType.Zones() {
Expand All @@ -80,7 +65,7 @@ func (p *InstanceProvider) Create(ctx context.Context,
overrides = append(overrides, override)
}
}
// 3. Create fleet
// 2. Create fleet
createFleetOutput, err := p.ec2api.CreateFleetWithContext(ctx, &ec2.CreateFleetInput{
Type: aws.String(ec2.FleetTypeInstant),
TargetCapacitySpecification: &ec2.TargetCapacitySpecificationRequest{
Expand Down
10 changes: 10 additions & 0 deletions pkg/packing/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
)

var (
// MaxInstanceTypes defines the number of instance type options to return to the cloud provider
MaxInstanceTypes = 20
)

// Constraints for an efficient binpacking solution of pods onto nodes, given
// overhead and node constraints.
type Constraints struct {
Expand Down Expand Up @@ -103,6 +108,11 @@ func (p *packer) packWithLargestPod(unpackedPods []*v1.Pod, constraints *Constra
}
}
sortByResources(bestInstances)
// Trim the bestInstances so that provisioning APIs in cloud providers are not overwhelmed by the number of instance type options
// For example, the AWS EC2 Fleet API only allows the request to be 145kb which equates to about 130 instance type options.
if len(bestInstances) > MaxInstanceTypes {
bestInstances = bestInstances[:MaxInstanceTypes]
}
return &cloudprovider.Packing{Pods: bestPackedPods, Constraints: constraints.Constraints, InstanceTypeOptions: bestInstances}, remainingPods
}

Expand Down