Skip to content

Commit f9e5d88

Browse files
authored
Merge pull request #203 from jwcesign/main
fix: resolve spot capacity correctly
2 parents c862433 + 78fe66f commit f9e5d88

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

pkg/providers/instancetype/instancetype.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,12 @@ func (p *DefaultProvider) List(ctx context.Context, kc *v1alpha1.KubeletConfigur
182182

183183
result := lo.Map(p.instanceTypesInfo, func(i *ecsclient.DescribeInstanceTypesResponseBodyInstanceTypesInstanceType, _ int) *cloudprovider.InstanceType {
184184
zoneData := lo.Map(allZones.UnsortedList(), func(zoneID string, _ int) ZoneData {
185+
ret := ZoneData{ID: zoneID, Available: true}
185186
if !p.instanceTypesOfferings[lo.FromPtr(i.InstanceTypeId)].Has(zoneID) || !vSwitchsZones.Has(zoneID) {
186-
return ZoneData{
187-
ID: zoneID,
188-
Available: false,
189-
SpotAvailable: false,
190-
}
191-
}
192-
return ZoneData{
193-
ID: zoneID,
194-
Available: true,
195-
SpotAvailable: p.spotInstanceTypesOfferings[lo.FromPtr(i.InstanceTypeId)].Has(zoneID),
187+
ret.Available = false
196188
}
189+
ret.SpotAvailable = p.spotInstanceTypesOfferings[lo.FromPtr(i.InstanceTypeId)].Has(zoneID)
190+
return ret
197191
})
198192

199193
// !!! Important !!!
@@ -402,10 +396,6 @@ func getAllInstanceTypes(client *ecsclient.Client) ([]*ecsclient.DescribeInstanc
402396
func (p *DefaultProvider) createOfferings(_ context.Context, instanceType string, zones []ZoneData) []cloudprovider.Offering {
403397
var offerings []cloudprovider.Offering
404398
for _, zone := range zones {
405-
if !zone.Available {
406-
continue
407-
}
408-
409399
odPrice, odOK := p.pricingProvider.OnDemandPrice(instanceType)
410400
spotPrice, spotOK := p.pricingProvider.SpotPrice(instanceType, zone.ID)
411401

@@ -416,9 +406,9 @@ func (p *DefaultProvider) createOfferings(_ context.Context, instanceType string
416406
offerings = append(offerings, p.createOffering(zone.ID, karpv1.CapacityTypeOnDemand, odPrice, offeringAvailable))
417407
}
418408

419-
if spotOK && zone.SpotAvailable {
409+
if spotOK {
420410
isUnavailable := p.unavailableOfferings.IsUnavailable(instanceType, zone.ID, karpv1.CapacityTypeSpot)
421-
offeringAvailable := !isUnavailable && zone.Available
411+
offeringAvailable := !isUnavailable && zone.SpotAvailable
422412

423413
offerings = append(offerings, p.createOffering(zone.ID, karpv1.CapacityTypeSpot, spotPrice, offeringAvailable))
424414
}

pkg/providers/instancetype/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ const (
5353
)
5454

5555
type ZoneData struct {
56-
ID string
57-
Available bool
56+
ID string
57+
// Available represents OnDemand capacity
58+
Available bool
59+
// SpotAvailable represents Spot capacity
5860
SpotAvailable bool
5961
}
6062

0 commit comments

Comments
 (0)