Skip to content

Commit 1f8ff2e

Browse files
author
helen
authored
Merge pull request #53 from jwcesign/main
fix: fix the bugs of nodeclaim creation
2 parents d219919 + bddbd2a commit 1f8ff2e

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

examples/nodepool/ecsnodeclass.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ spec:
99
securityGroupSelectorTerms:
1010
- tags:
1111
karpenter.sh/discovery: "cluster-demonstration" # replace with your cluster name
12+
imageSelectorTerms:
13+
- alias: aliyun3@latest

pkg/providers/instancetype/instancetype.go

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)