in pkg/cloudprovider/aws/instance.go [182:216]
func (p *InstanceProvider) getOverrides(instanceTypeOptions []cloudprovider.InstanceType, subnets []*ec2.Subnet, zones sets.String, capacityType string) []*ec2.FleetLaunchTemplateOverridesRequest {
var overrides []*ec2.FleetLaunchTemplateOverridesRequest
for i, instanceType := range instanceTypeOptions {
for _, offering := range instanceType.Offerings() {
if capacityType != offering.CapacityType {
continue
}
if !zones.Has(offering.Zone) {
continue
}
for _, subnet := range subnets {
if aws.StringValue(subnet.AvailabilityZone) != offering.Zone {
continue
}
override := &ec2.FleetLaunchTemplateOverridesRequest{
InstanceType: aws.String(instanceType.Name()),
SubnetId: subnet.SubnetId,
// This is technically redundant, but is useful if we have to parse insufficient capacity errors from
// CreateFleet so that we can figure out the zone rather than additional API calls to look up the subnet
AvailabilityZone: subnet.AvailabilityZone,
}
// Add a priority for spot requests since we are using the capacity-optimized-prioritized spot allocation strategy
// to reduce the likelihood of getting an excessively large instance type.
// instanceTypeOptions are sorted by vcpus and memory so this prioritizes smaller instance types.
if capacityType == v1alpha1.CapacityTypeSpot {
override.Priority = aws.Float64(float64(i))
}
overrides = append(overrides, override)
// FleetAPI cannot span subnets from the same AZ, so break after the first one.
break
}
}
}
return overrides
}