Skip to content

Commit

Permalink
Fix increase
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam committed Dec 13, 2023
1 parent 48bb15f commit a6fec62
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ const (
const (
// DefaultCleanupInterval triggers cache cleanup (lazy eviction) at this interval.
DefaultCleanupInterval = 10 * time.Minute
// InstanceTypesAndZonesCleanupInterval is the time before we refresh instance types and zones at EC2
InstanceTypesAndZonesCleanupInterval = 6 * time.Minute
)
2 changes: 1 addition & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func NewOperator(ctx context.Context, operator *operator.Operator) (context.Cont
)
instanceTypeProvider := instancetype.NewProvider(
*sess.Config.Region,
cache.New(awscache.InstanceTypesAndZonesTTL, awscache.DefaultCleanupInterval),
cache.New(awscache.InstanceTypesAndZonesTTL, awscache.InstanceTypesAndZonesCleanupInterval),
ec2api,
subnetProvider,
unavailableOfferingsCache,
Expand Down
11 changes: 4 additions & 7 deletions pkg/providers/instancetype/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func NewProvider(region string, cache *cache.Cache, ec2api ec2iface.EC2API, subn
}

func (p *Provider) List(ctx context.Context, kc *corev1beta1.KubeletConfiguration, nodeClass *v1beta1.EC2NodeClass) ([]*cloudprovider.InstanceType, error) {
p.cache.DeleteExpired()
// Get InstanceTypes from EC2
instanceTypes, err := p.GetInstanceTypes(ctx)
if err != nil {
Expand Down Expand Up @@ -115,11 +116,7 @@ func (p *Provider) List(ctx context.Context, kc *corev1beta1.KubeletConfiguratio
// Compute fully initialized instance types hash key
subnetHash, _ := hashstructure.Hash(subnets, hashstructure.FormatV2, &hashstructure.HashOptions{SlicesAsSets: true})
kcHash, _ := hashstructure.Hash(kc, hashstructure.FormatV2, &hashstructure.HashOptions{SlicesAsSets: true})
key := fmt.Sprintf("%d-%d-%d-%s-%016x-%016x", p.instanceTypesSeqNum, p.instanceTypeOfferingsSeqNum, p.unavailableOfferings.SeqNum, nodeClass.UID, subnetHash, kcHash)

if item, ok := p.cache.Get(key); ok {
return item.([]*cloudprovider.InstanceType), nil
}
key := fmt.Sprintf("%d-%d-%d-%016x-%016x", p.instanceTypesSeqNum, p.instanceTypeOfferingsSeqNum, p.unavailableOfferings.SeqNum, subnetHash, kcHash)
result := lo.Map(instanceTypes, func(i *ec2.InstanceTypeInfo, _ int) *cloudprovider.InstanceType {
return NewInstanceType(ctx, i, kc, p.region, nodeClass, p.createOfferings(ctx, i, instanceTypeOfferings[aws.StringValue(i.InstanceType)], availabilityZones, subnetZones))
})
Expand Down Expand Up @@ -231,9 +228,9 @@ func (p *Provider) getInstanceTypeOfferings(ctx context.Context) (map[string]set
return nil, fmt.Errorf("describing instance type zone offerings, %w", err)
}
if p.cm.HasChanged("instance-type-count", len(instanceTypeOfferings)) {
atomic.AddUint64(&p.instanceTypeOfferingsSeqNum, 1)
logging.FromContext(ctx).With("instance-type-count", len(instanceTypeOfferings)).Debugf("discovered offerings for instance types")
}
atomic.AddUint64(&p.instanceTypeOfferingsSeqNum, 1)
p.cache.SetDefault(InstanceTypeOfferingsCacheKey, instanceTypeOfferings)
return instanceTypeOfferings, nil
}
Expand Down Expand Up @@ -270,10 +267,10 @@ func (p *Provider) GetInstanceTypes(ctx context.Context) ([]*ec2.InstanceTypeInf
return nil, fmt.Errorf("fetching instance types using ec2.DescribeInstanceTypes, %w", err)
}
if p.cm.HasChanged("instance-types", instanceTypes) {
atomic.AddUint64(&p.instanceTypesSeqNum, 1)
logging.FromContext(ctx).With(
"count", len(instanceTypes)).Debugf("discovered instance types")
}
atomic.AddUint64(&p.instanceTypesSeqNum, 1)
p.cache.SetDefault(InstanceTypesCacheKey, instanceTypes)
return instanceTypes, nil
}

0 comments on commit a6fec62

Please sign in to comment.