Skip to content

Commit

Permalink
Revert "chore: don't panic for a nil instance type (aws#7144)" (aws#7222
Browse files Browse the repository at this point in the history
)
  • Loading branch information
njtran authored Oct 15, 2024
1 parent 1ac502d commit 400023a
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions pkg/providers/instancetype/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ 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 @@ -131,7 +130,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.FilterMap(p.instanceTypesInfo, func(i *ec2.InstanceTypeInfo, _ int) (*cloudprovider.InstanceType, bool) {
result := lo.Map(p.instanceTypesInfo, func(i *ec2.InstanceTypeInfo, _ int) *cloudprovider.InstanceType {
instanceTypeVCPU.With(prometheus.Labels{
instanceTypeLabel: *i.InstanceType,
}).Set(float64(lo.FromPtr(i.VCpuInfo.DefaultVCpus)))
Expand All @@ -153,11 +152,7 @@ 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 @@ -170,7 +165,7 @@ func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass)
zoneLabel: of.Requirements.Get(corev1.LabelTopologyZone).Any(),
}).Set(of.Price)
}
return it, true
return it
})
p.instanceTypesCache.SetDefault(key, result)
return result, nil
Expand Down

0 comments on commit 400023a

Please sign in to comment.