in internal/deployers/eksapi/node.go [96:151]
func (m *nodeManager) resolveInstanceTypes(opts *deployerOptions) (err error) {
instanceTypes := opts.InstanceTypes
if len(instanceTypes) == 0 {
if len(opts.InstanceTypeArchs) > 0 {
klog.Infof("choosing instance types based on architecture(s): %v", opts.InstanceTypeArchs)
for _, arch := range opts.InstanceTypeArchs {
var ec2Arch ec2types.ArchitectureValues
switch arch {
case "x86_64", "amd64":
ec2Arch = ec2types.ArchitectureValuesX8664
case "aarch64", "arm64":
ec2Arch = ec2types.ArchitectureValuesArm64
default:
return fmt.Errorf("unknown architecture: '%s'", arch)
}
instanceTypesForArch, ok := defaultInstanceTypesByEC2ArchitectureValues[ec2Arch]
if !ok {
return fmt.Errorf("no default instance types known for architecture: '%s'", arch)
}
instanceTypes = append(instanceTypes, instanceTypesForArch...)
}
} else if opts.UnmanagedNodes {
klog.Infof("choosing instance types based on AMI architecture...")
if out, err := m.clients.EC2().DescribeImages(context.TODO(), &ec2.DescribeImagesInput{
ImageIds: []string{opts.AMI},
}); err != nil {
return fmt.Errorf("failed to describe AMI: %s: %v", opts.AMI, err)
} else {
amiArch := out.Images[0].Architecture
instanceTypesForAMIArchitecture, ok := defaultInstanceTypesByEC2ArchitectureValues[amiArch]
if !ok {
return fmt.Errorf("no default instance types known for AMI architecture: %v", amiArch)
}
instanceTypes = instanceTypesForAMIArchitecture
}
} else {
// we don't rely on the service's default instance types, because they're a bit too small for the k8s e2e suite
klog.Infof("choosing instance types based on managed nodegroup's AMI type...")
instanceTypesForAMIType, ok := defaultInstanceTypesByEKSAMITypes[ekstypes.AMITypes(opts.AMIType)]
if !ok {
return fmt.Errorf("no default instance types known for AMI type: %v", opts.AMIType)
}
instanceTypes = instanceTypesForAMIType
}
}
validInstanceTypes, err := m.getValidInstanceTypes(instanceTypes)
if err != nil {
return err
}
if len(validInstanceTypes) == 0 {
return fmt.Errorf("none of the instance types %v were valid", instanceTypes)
}
opts.InstanceTypes = validInstanceTypes
klog.Infof("using instance types: %v", opts.InstanceTypes)
return nil
}