Skip to content

Commit 79eeadc

Browse files
authored
fix: spurious logging when discovering capacity (#8143)
1 parent 3f5da40 commit 79eeadc

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pkg/providers/instancetype/instancetype.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,14 @@ func (p *DefaultProvider) UpdateInstanceTypeCapacityFromNode(ctx context.Context
334334
amiHash, _ := hashstructure.Hash(nodeClass.Status.AMIs, hashstructure.FormatV2, &hashstructure.HashOptions{SlicesAsSets: true})
335335
key := fmt.Sprintf("%s-%016x", instanceTypeName, amiHash)
336336

337-
// Update cache if non-existent or actual capacity is less than or equal to cached value
338337
actualCapacity := node.Status.Capacity.Memory()
339338
if cachedCapacity, ok := p.discoveredCapacityCache.Get(key); !ok || actualCapacity.Cmp(cachedCapacity.(resource.Quantity)) < 1 {
340-
log.FromContext(ctx).WithValues("memory-capacity", actualCapacity, "instance-type", instanceTypeName).V(1).Info("updating discovered capacity cache")
339+
// Update the capacity in the cache if it is less than or equal to the current cached capacity. We update when it's equal to refresh the TTL.
341340
p.discoveredCapacityCache.SetDefault(key, *actualCapacity)
341+
// Only log if we haven't discovered the capacity for the instance type yet or the discovered capacity is **less** than the cached capacity
342+
if !ok || actualCapacity.Cmp(cachedCapacity.(resource.Quantity)) < 0 {
343+
log.FromContext(ctx).WithValues("memory-capacity", actualCapacity, "instance-type", instanceTypeName).V(1).Info("updating discovered capacity cache")
344+
}
342345
}
343346
return nil
344347
}

0 commit comments

Comments
 (0)