@@ -78,7 +78,8 @@ type DefaultProvider struct {
7878
7979func NewDefaultProvider (ctx context.Context , region string , ecsClient * ecsclient.Client ,
8080 imageFamilyResolver imagefamily.Resolver , vSwitchProvider vswitch.Provider ,
81- ackProvider ack.Provider ) * DefaultProvider {
81+ ackProvider ack.Provider ,
82+ ) * DefaultProvider {
8283 p := & DefaultProvider {
8384 ecsClient : ecsClient ,
8485 region : region ,
@@ -117,6 +118,7 @@ func (p *DefaultProvider) Create(ctx context.Context, nodeClass *v1alpha1.ECSNod
117118
118119 return NewInstanceFromProvisioningGroup (launchInstance , createAutoProvisioningGroupRequest , p .region ), nil
119120}
121+
120122func (p * DefaultProvider ) Get (ctx context.Context , id string ) (* Instance , error ) {
121123 if instance , ok := p .instanceCache .Get (id ); ok {
122124 return instance .(* Instance ), nil
@@ -363,7 +365,8 @@ func getTags(ctx context.Context, nodeClass *v1alpha1.ECSNodeClass, nodeClaim *k
363365}
364366
365367func (p * DefaultProvider ) launchInstance (ctx context.Context , nodeClass * v1alpha1.ECSNodeClass , nodeClaim * karpv1.NodeClaim , instanceTypes []* cloudprovider.InstanceType ,
366- tags map [string ]string ) (* ecsclient.CreateAutoProvisioningGroupResponseBodyLaunchResultsLaunchResult , * ecsclient.CreateAutoProvisioningGroupRequest , error ) {
368+ tags map [string ]string ,
369+ ) (* ecsclient.CreateAutoProvisioningGroupResponseBodyLaunchResultsLaunchResult , * ecsclient.CreateAutoProvisioningGroupRequest , error ) {
367370 if err := p .checkODFallback (nodeClaim , instanceTypes ); err != nil {
368371 log .FromContext (ctx ).Error (err , "failed while checking on-demand fallback" )
369372 }
@@ -463,7 +466,8 @@ func resolveKubeletConfiguration(nodeClass *v1alpha1.ECSNodeClass) *v1alpha1.Kub
463466}
464467
465468func (p * DefaultProvider ) getProvisioningGroup (ctx context.Context , nodeClass * v1alpha1.ECSNodeClass , nodeClaim * karpv1.NodeClaim ,
466- instanceTypes []* cloudprovider.InstanceType , zonalVSwitchs map [string ]* vswitch.VSwitch , capacityType string , tags map [string ]string ) (* ecsclient.CreateAutoProvisioningGroupRequest , error ) {
469+ instanceTypes []* cloudprovider.InstanceType , zonalVSwitchs map [string ]* vswitch.VSwitch , capacityType string , tags map [string ]string ,
470+ ) (* ecsclient.CreateAutoProvisioningGroupRequest , error ) {
467471 requirements := scheduling .NewNodeSelectorRequirementsWithMinValues (nodeClaim .Spec .Requirements ... )
468472
469473 instanceTypes = p .imageFamilyResolver .FilterInstanceTypesBySystemDisk (ctx , nodeClass , instanceTypes )
@@ -475,14 +479,14 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
475479
476480 requirements [karpv1 .CapacityTypeLabelKey ] = scheduling .NewRequirement (karpv1 .CapacityTypeLabelKey , corev1 .NodeSelectorOpIn , capacityType )
477481 var launchTemplateConfigs []* ecsclient.CreateAutoProvisioningGroupRequestLaunchTemplateConfig
478- for index , instanceType := range instanceTypes {
479- if index > maxInstanceTypes - 1 {
482+ for _ , instanceType := range instanceTypes {
483+ if len ( launchTemplateConfigs ) > maxInstanceTypes - 1 {
480484 break
481485 }
482486
483487 vSwitchID := p .getVSwitchID (instanceType , zonalVSwitchs , requirements , capacityType , nodeClass .Spec .VSwitchSelectionPolicy )
484488 if vSwitchID == "" {
485- return nil , errors . New ( "vSwitchID not found" )
489+ continue
486490 }
487491
488492 launchTemplateConfig := & ecsclient.CreateAutoProvisioningGroupRequestLaunchTemplateConfig {
@@ -494,6 +498,10 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
494498 launchTemplateConfigs = append (launchTemplateConfigs , launchTemplateConfig )
495499 }
496500
501+ if len (launchTemplateConfigs ) == 0 {
502+ return nil , errors .New ("no capacity offerings are currently available given the constraints" )
503+ }
504+
497505 reqTags := make ([]* ecsclient.CreateAutoProvisioningGroupRequestLaunchConfigurationTag , 0 , len (tags ))
498506 for k , v := range tags {
499507 reqTags = append (reqTags , & ecsclient.CreateAutoProvisioningGroupRequestLaunchConfigurationTag {
@@ -580,7 +588,8 @@ func (p *DefaultProvider) checkODFallback(nodeClaim *karpv1.NodeClaim, instanceT
580588}
581589
582590func (p * DefaultProvider ) getVSwitchID (instanceType * cloudprovider.InstanceType ,
583- zonalVSwitchs map [string ]* vswitch.VSwitch , reqs scheduling.Requirements , capacityType string , vSwitchSelectionPolicy string ) string {
591+ zonalVSwitchs map [string ]* vswitch.VSwitch , reqs scheduling.Requirements , capacityType string , vSwitchSelectionPolicy string ,
592+ ) string {
584593 cheapestVSwitchID := ""
585594 cheapestPrice := math .MaxFloat64
586595
0 commit comments