Skip to content

Commit a374b95

Browse files
authored
Enhance logging in ipamd (#3561)
1 parent cdfc4c5 commit a374b95

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/ipamd/datastore/data_store.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ func (ds *DataStore) AssignPodIPv4Address(ipamKey IPAMKey, ipamMetadata IPAMMeta
720720
// addr is nil when we are using a new IP from prefix or SIP pool
721721
// if addr is out of cooldown or not assigned, we can reuse addr
722722
addr = &AddressInfo{Address: strPrivateIPv4}
723+
ds.log.Debugf("Allocating new IP %s from CIDR %s for pod", strPrivateIPv4, availableCidr.Cidr.String())
724+
} else if !addr.UnassignedTime.IsZero() {
725+
// IP was previously used and is being reassigned
726+
timeSinceFree := time.Since(addr.UnassignedTime)
727+
ds.log.Debugf("Reassigning IP %s (was free for %v)", addr.Address, timeSinceFree.Round(time.Second))
723728
}
724729

725730
availableCidr.IPAddresses[strPrivateIPv4] = addr
@@ -1133,6 +1138,11 @@ func (ds *DataStore) UnassignPodIPAddress(ipamKey IPAMKey) (e *ENI, ip string, d
11331138
}
11341139
addr.UnassignedTime = time.Now()
11351140

1141+
// Debug log for IP entering cooldown
1142+
cooldownExpiry := addr.UnassignedTime.Add(ds.ipCooldownPeriod)
1143+
ds.log.Debugf("IP %s entering cooldown period of %v (available after %v)",
1144+
addr.Address, ds.ipCooldownPeriod, cooldownExpiry.Format(time.RFC3339))
1145+
11361146
// Interfaces Count 0 means this property did not exist in the datastore when we restored. A Pod entry always have atleast one interface
11371147
if originalIPAMMetadata.InterfacesCount == 0 {
11381148
originalIPAMMetadata.InterfacesCount += 1
@@ -1348,6 +1358,10 @@ func (ds *DataStore) getUnusedIP(availableCidr *CidrInfo) (string, error) {
13481358
//continue cleaning up the DB, this is to avoid stale entries and a new thread :)
13491359
if cachedIP == "" {
13501360
cachedIP = addr.Address
1361+
// Debug log for IP released from cooldown
1362+
timeSinceUnassigned := time.Since(addr.UnassignedTime)
1363+
ds.log.Debugf("IP %s released from cooldown after %v, available for reassignment in CIDR %s",
1364+
addr.Address, timeSinceUnassigned.Round(time.Second), availableCidr.Cidr.String())
13511365
}
13521366
//availableCidr.IPAddresses[addr.Address] = nil //Avoid mem leak - TODO
13531367
delete(availableCidr.IPAddresses, addr.Address)

0 commit comments

Comments
 (0)