Skip to content

Commit

Permalink
fix: duplicate offerings on cache miss (#7845)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdeal authored Mar 5, 2025
1 parent 05d086b commit 8415278
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion pkg/providers/instancetype/offering/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func (p *DefaultProvider) createOfferings(
offering.Requirements.Add(scheduling.NewRequirement(v1.LabelTopologyZoneID, corev1.NodeSelectorOpIn, id))
}
cachedOfferings = append(cachedOfferings, offering)
offerings = append(cachedOfferings, offering)
}
}
p.cache.SetDefault(p.cacheKeyFromInstanceType(it), cachedOfferings)
Expand Down
27 changes: 27 additions & 0 deletions pkg/providers/instancetype/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,33 @@ var _ = Describe("InstanceTypeProvider", func() {
})
})
})
Context("Offerings", func() {
It("should create a single offering per instance pool", func() {
ExpectApplied(ctx, env.Client, nodeClass)
// Test twice to ensure we get the same result for a cache miss and hit
for range 2 {
instanceTypes, err := cloudProvider.GetInstanceTypes(ctx, nodePool)
Expect(err).ToNot(HaveOccurred())
type instancePool struct {
instanceType string
zone string
capacityType string
}
pools := sets.New[instancePool]()
for _, it := range instanceTypes {
for _, o := range it.Offerings {
pool := instancePool{
instanceType: it.Name,
zone: o.Zone(),
capacityType: o.CapacityType(),
}
Expect(pools.Has(pool)).To(BeFalse())
pools.Insert(pool)
}
}
}
})
})
Context("Provider Cache", func() {
// Keeping the Cache testing in one IT block to validate the combinatorial expansion of instance types generated by different configs
It("changes to kubelet configuration fields should result in a different set of instances types", func() {
Expand Down

0 comments on commit 8415278

Please sign in to comment.