in pkg/providers/instance/instance.go [370:417]
func (p *DefaultProvider) getOverrides(
instanceTypes []*cloudprovider.InstanceType,
zonalSubnets map[string]*subnet.Subnet,
reqs scheduling.Requirements,
image, capacityReservationID string,
) []ec2types.FleetLaunchTemplateOverridesRequest {
// Unwrap all the offerings to a flat slice that includes a pointer
// to the parent instance type name
type offeringWithParentName struct {
*cloudprovider.Offering
parentInstanceTypeName ec2types.InstanceType
}
var filteredOfferings []offeringWithParentName
for _, it := range instanceTypes {
ofs := it.Offerings.Available().Compatible(reqs)
// If we are generating a launch template for a specific capacity reservation, we only want to include the offering
// for that capacity reservation when generating overrides.
if capacityReservationID != "" {
ofs = ofs.Compatible(scheduling.NewRequirements(scheduling.NewRequirement(
cloudprovider.ReservationIDLabel,
corev1.NodeSelectorOpIn,
capacityReservationID,
)))
}
for _, o := range ofs {
filteredOfferings = append(filteredOfferings, offeringWithParentName{
Offering: o,
parentInstanceTypeName: ec2types.InstanceType(it.Name),
})
}
}
var overrides []ec2types.FleetLaunchTemplateOverridesRequest
for _, offering := range filteredOfferings {
subnet, ok := zonalSubnets[offering.Zone()]
if !ok {
continue
}
overrides = append(overrides, ec2types.FleetLaunchTemplateOverridesRequest{
InstanceType: offering.parentInstanceTypeName,
SubnetId: lo.ToPtr(subnet.ID),
ImageId: lo.ToPtr(image),
// 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: lo.ToPtr(subnet.Zone),
})
}
return overrides
}