Skip to content

Commit 8415278

Browse files
authored
fix: duplicate offerings on cache miss (#7845)
1 parent 05d086b commit 8415278

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pkg/providers/instancetype/offering/provider.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ func (p *DefaultProvider) createOfferings(
165165
offering.Requirements.Add(scheduling.NewRequirement(v1.LabelTopologyZoneID, corev1.NodeSelectorOpIn, id))
166166
}
167167
cachedOfferings = append(cachedOfferings, offering)
168-
offerings = append(cachedOfferings, offering)
169168
}
170169
}
171170
p.cache.SetDefault(p.cacheKeyFromInstanceType(it), cachedOfferings)

pkg/providers/instancetype/suite_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,33 @@ var _ = Describe("InstanceTypeProvider", func() {
23832383
})
23842384
})
23852385
})
2386+
Context("Offerings", func() {
2387+
It("should create a single offering per instance pool", func() {
2388+
ExpectApplied(ctx, env.Client, nodeClass)
2389+
// Test twice to ensure we get the same result for a cache miss and hit
2390+
for range 2 {
2391+
instanceTypes, err := cloudProvider.GetInstanceTypes(ctx, nodePool)
2392+
Expect(err).ToNot(HaveOccurred())
2393+
type instancePool struct {
2394+
instanceType string
2395+
zone string
2396+
capacityType string
2397+
}
2398+
pools := sets.New[instancePool]()
2399+
for _, it := range instanceTypes {
2400+
for _, o := range it.Offerings {
2401+
pool := instancePool{
2402+
instanceType: it.Name,
2403+
zone: o.Zone(),
2404+
capacityType: o.CapacityType(),
2405+
}
2406+
Expect(pools.Has(pool)).To(BeFalse())
2407+
pools.Insert(pool)
2408+
}
2409+
}
2410+
}
2411+
})
2412+
})
23862413
Context("Provider Cache", func() {
23872414
// Keeping the Cache testing in one IT block to validate the combinatorial expansion of instance types generated by different configs
23882415
It("changes to kubelet configuration fields should result in a different set of instances types", func() {

0 commit comments

Comments
 (0)