@@ -78,7 +78,8 @@ type DefaultProvider struct {
78
78
79
79
func NewDefaultProvider (ctx context.Context , region string , ecsClient * ecsclient.Client ,
80
80
imageFamilyResolver imagefamily.Resolver , vSwitchProvider vswitch.Provider ,
81
- ackProvider ack.Provider ) * DefaultProvider {
81
+ ackProvider ack.Provider ,
82
+ ) * DefaultProvider {
82
83
p := & DefaultProvider {
83
84
ecsClient : ecsClient ,
84
85
region : region ,
@@ -117,6 +118,7 @@ func (p *DefaultProvider) Create(ctx context.Context, nodeClass *v1alpha1.ECSNod
117
118
118
119
return NewInstanceFromProvisioningGroup (launchInstance , createAutoProvisioningGroupRequest , p .region ), nil
119
120
}
121
+
120
122
func (p * DefaultProvider ) Get (ctx context.Context , id string ) (* Instance , error ) {
121
123
if instance , ok := p .instanceCache .Get (id ); ok {
122
124
return instance .(* Instance ), nil
@@ -363,7 +365,8 @@ func getTags(ctx context.Context, nodeClass *v1alpha1.ECSNodeClass, nodeClaim *k
363
365
}
364
366
365
367
func (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 ) {
367
370
if err := p .checkODFallback (nodeClaim , instanceTypes ); err != nil {
368
371
log .FromContext (ctx ).Error (err , "failed while checking on-demand fallback" )
369
372
}
@@ -463,7 +466,8 @@ func resolveKubeletConfiguration(nodeClass *v1alpha1.ECSNodeClass) *v1alpha1.Kub
463
466
}
464
467
465
468
func (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 ) {
467
471
requirements := scheduling .NewNodeSelectorRequirementsWithMinValues (nodeClaim .Spec .Requirements ... )
468
472
469
473
instanceTypes = p .imageFamilyResolver .FilterInstanceTypesBySystemDisk (ctx , nodeClass , instanceTypes )
@@ -475,14 +479,14 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
475
479
476
480
requirements [karpv1 .CapacityTypeLabelKey ] = scheduling .NewRequirement (karpv1 .CapacityTypeLabelKey , corev1 .NodeSelectorOpIn , capacityType )
477
481
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 {
480
484
break
481
485
}
482
486
483
487
vSwitchID := p .getVSwitchID (instanceType , zonalVSwitchs , requirements , capacityType , nodeClass .Spec .VSwitchSelectionPolicy )
484
488
if vSwitchID == "" {
485
- return nil , errors . New ( "vSwitchID not found" )
489
+ continue
486
490
}
487
491
488
492
launchTemplateConfig := & ecsclient.CreateAutoProvisioningGroupRequestLaunchTemplateConfig {
@@ -494,6 +498,10 @@ func (p *DefaultProvider) getProvisioningGroup(ctx context.Context, nodeClass *v
494
498
launchTemplateConfigs = append (launchTemplateConfigs , launchTemplateConfig )
495
499
}
496
500
501
+ if len (launchTemplateConfigs ) == 0 {
502
+ return nil , errors .New ("no capacity offerings are currently available given the constraints" )
503
+ }
504
+
497
505
reqTags := make ([]* ecsclient.CreateAutoProvisioningGroupRequestLaunchConfigurationTag , 0 , len (tags ))
498
506
for k , v := range tags {
499
507
reqTags = append (reqTags , & ecsclient.CreateAutoProvisioningGroupRequestLaunchConfigurationTag {
@@ -580,7 +588,8 @@ func (p *DefaultProvider) checkODFallback(nodeClaim *karpv1.NodeClaim, instanceT
580
588
}
581
589
582
590
func (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 {
584
593
cheapestVSwitchID := ""
585
594
cheapestPrice := math .MaxFloat64
586
595
0 commit comments