in pkg/ec2pricing/spotpricing.go [141:165]
func (c *SpotPricing) Get(ctx context.Context, instanceType ec2types.InstanceType, zone string, days int) (float64, error) {
entries, ok := c.cache.Get(string(instanceType))
if zone != "" && ok {
if !c.contains(zone, entries.([]*spotPricingEntry)) {
ok = false
}
}
if !ok {
c.RLock()
defer c.RUnlock()
zonalSpotPricing, err := c.fetchSpotPricingTimeSeries(ctx, instanceType, days)
if err != nil {
return -1, fmt.Errorf("there was a problem fetching spot instance type pricing for %s: %v", instanceType, err)
}
for instanceType, costs := range zonalSpotPricing {
c.cache.SetDefault(instanceType, costs)
}
}
entries, ok = c.cache.Get(string(instanceType))
if !ok {
return -1, fmt.Errorf("unable to get spot pricing for %s in zone %s for %d days back", instanceType, zone, days)
}
return c.calculateSpotAggregate(c.filterOn(zone, entries.([]*spotPricingEntry))), nil
}