Skip to content

Commit eb629dc

Browse files
committed
fix: spurious logging when discovering capacity
1 parent a93f3ad commit eb629dc

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
@@ -297,11 +297,14 @@ func (p *DefaultProvider) UpdateInstanceTypeCapacityFromNode(ctx context.Context
297297
amiHash, _ := hashstructure.Hash(nodeClass.Status.AMIs, hashstructure.FormatV2, &hashstructure.HashOptions{SlicesAsSets: true})
298298
key := fmt.Sprintf("%s-%016x", instanceTypeName, amiHash)
299299

300-
// Update cache if non-existent or actual capacity is less than or equal to cached value
301300
actualCapacity := node.Status.Capacity.Memory()
302301
if cachedCapacity, ok := p.discoveredCapacityCache.Get(key); !ok || actualCapacity.Cmp(cachedCapacity.(resource.Quantity)) < 1 {
303-
log.FromContext(ctx).WithValues("memory-capacity", actualCapacity, "instance-type", instanceTypeName).V(1).Info("updating discovered capacity cache")
302+
// 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.
304303
p.discoveredCapacityCache.SetDefault(key, *actualCapacity)
304+
// Only log if we haven't discovered the capacity for the instance type yet or the discovered capacity is **less** than the cached capacity
305+
if !ok || actualCapacity.Cmp(cachedCapacity.(resource.Quantity)) < 0 {
306+
log.FromContext(ctx).WithValues("memory-capacity", actualCapacity, "instance-type", instanceTypeName).V(1).Info("updating discovered capacity cache")
307+
}
305308
}
306309
return nil
307310
}

0 commit comments

Comments
 (0)