Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipam: add method to get IP owner per pool #24358

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/ipam/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (ipam *IPAM) Dump() (allocv4 map[string]string, allocv6 map[string]string,
st4 = "IPv4: " + st4
for ip := range allocv4 {
// XXX: only consider default pool for now
owner, _ := ipam.owner[PoolDefault][ip]
owner := ipam.getIPOwner(ip, PoolDefault)
// If owner is not available, report IP but leave owner empty
allocv4[ip] = owner
}
Expand All @@ -330,7 +330,7 @@ func (ipam *IPAM) Dump() (allocv4 map[string]string, allocv6 map[string]string,
st6 = "IPv6: " + st6
for ip := range allocv6 {
// XXX: only consider default pool for now
owner, _ := ipam.owner[PoolDefault][ip]
owner := ipam.getIPOwner(ip, PoolDefault)
// If owner is not available, report IP but leave owner empty
allocv6[ip] = owner
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ func NewIPAM(nodeAddressing types.NodeAddressing, c Configuration, owner Owner,
return ipam
}

// getIPOwner returns the owner for an IP in a particular pool or the empty
// string in case the pool or IP is not registered.
func (ipam *IPAM) getIPOwner(ip string, pool Pool) string {
if p, ok := ipam.owner[pool]; ok {
return p[ip]
}
return ""
}

// registerIPOwner registers a new owner for an IP in a particular pool.
func (ipam *IPAM) registerIPOwner(ip net.IP, owner string, pool Pool) {
if _, ok := ipam.owner[pool]; !ok {
Expand Down