Skip to content

Commit 94b161e

Browse files
committed
fix: resolve spot capacity correctly
Signed-off-by: jwcesign <[email protected]>
1 parent dde7dc7 commit 94b161e

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

pkg/providers/instancetype/instancetype.go

+6-16
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,12 @@ func (p *DefaultProvider) List(ctx context.Context, kc *v1alpha1.KubeletConfigur
185185

186186
result := lo.Map(p.instanceTypesInfo, func(i *ecsclient.DescribeInstanceTypesResponseBodyInstanceTypesInstanceType, _ int) *cloudprovider.InstanceType {
187187
zoneData := lo.Map(allZones.UnsortedList(), func(zoneID string, _ int) ZoneData {
188+
ret := ZoneData{ID: zoneID, Available: true}
188189
if !p.instanceTypesOfferings[lo.FromPtr(i.InstanceTypeId)].Has(zoneID) || !vSwitchsZones.Has(zoneID) {
189-
return ZoneData{
190-
ID: zoneID,
191-
Available: false,
192-
SpotAvailable: false,
193-
}
194-
}
195-
return ZoneData{
196-
ID: zoneID,
197-
Available: true,
198-
SpotAvailable: p.spotInstanceTypesOfferings[lo.FromPtr(i.InstanceTypeId)].Has(zoneID),
190+
ret.Available = false
199191
}
192+
ret.SpotAvailable = p.spotInstanceTypesOfferings[lo.FromPtr(i.InstanceTypeId)].Has(zoneID)
193+
return ret
200194
})
201195

202196
// !!! Important !!!
@@ -405,10 +399,6 @@ func getAllInstanceTypes(client *ecsclient.Client) ([]*ecsclient.DescribeInstanc
405399
func (p *DefaultProvider) createOfferings(_ context.Context, instanceType string, zones []ZoneData) []cloudprovider.Offering {
406400
var offerings []cloudprovider.Offering
407401
for _, zone := range zones {
408-
if !zone.Available {
409-
continue
410-
}
411-
412402
odPrice, odOK := p.pricingProvider.OnDemandPrice(instanceType)
413403
spotPrice, spotOK := p.pricingProvider.SpotPrice(instanceType, zone.ID)
414404

@@ -419,9 +409,9 @@ func (p *DefaultProvider) createOfferings(_ context.Context, instanceType string
419409
offerings = append(offerings, p.createOffering(zone.ID, karpv1.CapacityTypeOnDemand, odPrice, offeringAvailable))
420410
}
421411

422-
if spotOK && zone.SpotAvailable {
412+
if spotOK {
423413
isUnavailable := p.unavailableOfferings.IsUnavailable(instanceType, zone.ID, karpv1.CapacityTypeSpot)
424-
offeringAvailable := !isUnavailable && zone.Available
414+
offeringAvailable := !isUnavailable && zone.SpotAvailable
425415

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

pkg/providers/instancetype/types.go

+4-2
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)