@@ -170,16 +170,12 @@ func (p *DefaultProvider) List(ctx context.Context, kc *v1alpha1.KubeletConfigur
170170 }
171171 })
172172
173- // TODO: wait createOfferings ready
174- _ = zoneData
175-
176173 // !!! Important !!!
177174 // Any changes to the values passed into the NewInstanceType method will require making updates to the cache key
178175 // so that Karpenter is able to cache the set of InstanceTypes based on values that alter the set of instance types
179176 // !!! Important !!!
180177 return NewInstanceType (ctx , i , kc , p .region ,
181- p .createOfferings (ctx , * i .InstanceTypeId , allZones ,
182- p .instanceTypesOfferings [* i .InstanceTypeId ], nodeClass .Status .VSwitches ))
178+ p .createOfferings (ctx , * i .InstanceTypeId , zoneData ))
183179 })
184180
185181 p .instanceTypesCache .SetDefault (key , result )
@@ -320,51 +316,39 @@ func getAllInstanceTypes(client *ecsclient.Client) ([]*ecsclient.DescribeInstanc
320316// offering, you can do the following thanks to this invariant:
321317//
322318// offering.Requirements.Get(v1.TopologyLabelZone).Any()
323- func (p * DefaultProvider ) createOfferings (_ context.Context , instanceType string , zones , instanceTypeZones sets.Set [string ],
324- vswitchs []v1alpha1.VSwitch ) []cloudprovider.Offering {
325-
319+ func (p * DefaultProvider ) createOfferings (_ context.Context , instanceType string , zones []ZoneData ) []cloudprovider.Offering {
326320 var offerings []cloudprovider.Offering
327- for zone := range zones {
321+ for _ , zone := range zones {
328322 odPrice , odOK := p .pricingProvider .OnDemandPrice (instanceType )
329- spotPrice , spotOK := p .pricingProvider .SpotPrice (instanceType , zone )
330-
331- vswitch , hasVSwitch := lo .Find (vswitchs , func (s v1alpha1.VSwitch ) bool {
332- return s .ZoneID == zone
333- })
323+ spotPrice , spotOK := p .pricingProvider .SpotPrice (instanceType , zone .ID )
334324
335325 if odOK {
336- // TODO: fix here
337- isUnavailable := p .unavailableOfferings .IsUnavailable (instanceType , zone , v1beta1 .CapacityTypeOnDemand )
338- _ = ! isUnavailable && odOK && instanceTypeZones .Has (zone ) && hasVSwitch
326+ isUnavailable := p .unavailableOfferings .IsUnavailable (instanceType , zone .ID , v1beta1 .CapacityTypeOnDemand )
327+ offeringAvailable := ! isUnavailable && odOK && zone .Available
339328
340- offerings = append (offerings , p .createOffering (zone , v1beta1 .CapacityTypeOnDemand , & vswitch , odPrice , true ))
329+ offerings = append (offerings , p .createOffering (zone . ID , v1beta1 .CapacityTypeOnDemand , odPrice , offeringAvailable ))
341330 }
342331
343332 if spotOK {
344- // TODO: fix here
345- isUnavailable := p .unavailableOfferings .IsUnavailable (instanceType , zone , v1beta1 .CapacityTypeSpot )
346- _ = ! isUnavailable && spotOK && instanceTypeZones .Has (zone ) && hasVSwitch
333+ isUnavailable := p .unavailableOfferings .IsUnavailable (instanceType , zone .ID , v1beta1 .CapacityTypeSpot )
334+ offeringAvailable := ! isUnavailable && spotOK && zone .Available
347335
348- offerings = append (offerings , p .createOffering (zone , v1beta1 .CapacityTypeSpot , & vswitch , spotPrice , true ))
336+ offerings = append (offerings , p .createOffering (zone . ID , v1beta1 .CapacityTypeSpot , spotPrice , offeringAvailable ))
349337 }
350338 }
351339 return offerings
352340}
353341
354- func (p * DefaultProvider ) createOffering (zone , capacityType string , vswitch * v1alpha1.VSwitch ,
355- price float64 , available bool ) cloudprovider.Offering {
356-
342+ func (p * DefaultProvider ) createOffering (zone , capacityType string , price float64 , available bool ) cloudprovider.Offering {
357343 offering := cloudprovider.Offering {
358344 Requirements : scheduling .NewRequirements (
359345 scheduling .NewRequirement (karpv1 .CapacityTypeLabelKey , corev1 .NodeSelectorOpIn , capacityType ),
360346 scheduling .NewRequirement (corev1 .LabelTopologyZone , corev1 .NodeSelectorOpIn , zone ),
347+ scheduling .NewRequirement (v1alpha1 .LabelTopologyZoneID , corev1 .NodeSelectorOpIn , zone ),
361348 ),
362349 Price : price ,
363350 Available : available ,
364351 }
365- if vswitch .ZoneID != "" {
366- offering .Requirements .Add (scheduling .NewRequirement (v1alpha1 .LabelTopologyZoneID , corev1 .NodeSelectorOpIn , vswitch .ZoneID ))
367- }
368352
369353 return offering
370354}
0 commit comments