Skip to content

Commit

Permalink
chore: don't panic for a nil instance type (#7144)
Browse files Browse the repository at this point in the history
  • Loading branch information
njtran authored Oct 2, 2024
1 parent 3913523 commit e07b37d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/providers/instancetype/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func NewDefaultProvider(instanceTypesCache *cache.Cache, ec2api ec2iface.EC2API,
}
}

// nolint:gocyclo
func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass) ([]*cloudprovider.InstanceType, error) {
p.muInstanceTypesInfo.RLock()
p.muInstanceTypesOfferings.RLock()
Expand Down Expand Up @@ -130,7 +131,7 @@ func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass)
subnetZoneToID := lo.SliceToMap(nodeClass.Status.Subnets, func(s v1.Subnet) (string, string) {
return s.Zone, s.ZoneID
})
result := lo.Map(p.instanceTypesInfo, func(i *ec2.InstanceTypeInfo, _ int) *cloudprovider.InstanceType {
result := lo.FilterMap(p.instanceTypesInfo, func(i *ec2.InstanceTypeInfo, _ int) (*cloudprovider.InstanceType, bool) {
instanceTypeVCPU.With(prometheus.Labels{
instanceTypeLabel: *i.InstanceType,
}).Set(float64(lo.FromPtr(i.VCpuInfo.DefaultVCpus)))
Expand All @@ -152,7 +153,11 @@ func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass)
}
})

// If the resolver returned nil, it means that the instance type shouldn't be considered
it := p.instanceTypesResolver.Resolve(ctx, i, zoneData, nodeClass)
if it == nil {
return nil, false
}
for _, of := range it.Offerings {
instanceTypeOfferingAvailable.With(prometheus.Labels{
instanceTypeLabel: it.Name,
Expand All @@ -165,7 +170,7 @@ func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass)
zoneLabel: of.Requirements.Get(corev1.LabelTopologyZone).Any(),
}).Set(of.Price)
}
return it
return it, true
})
p.instanceTypesCache.SetDefault(key, result)
return result, nil
Expand Down

0 comments on commit e07b37d

Please sign in to comment.