Skip to content

Commit

Permalink
move ipam.subnet.mutex to caller (#2571)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Mar 29, 2023
1 parent b366ee8 commit d698c73
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (ipam *IPAM) GetPodAddress(podName string) []*SubnetAddress {
defer ipam.mutex.RUnlock()
addresses := []*SubnetAddress{}
for _, subnet := range ipam.Subnets {
subnet.mutex.RLock()
for _, nicName := range subnet.PodToNicList[podName] {
v4IP, v6IP, mac, protocol := subnet.GetPodAddress(podName, nicName)
switch protocol {
Expand All @@ -219,6 +220,7 @@ func (ipam *IPAM) GetPodAddress(podName string) []*SubnetAddress {
addresses = append(addresses, &SubnetAddress{Subnet: subnet, Ip: string(v6IP), Mac: mac})
}
}
subnet.mutex.RUnlock()
}
return addresses
}
Expand Down
4 changes: 1 addition & 3 deletions pkg/ipam/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,8 @@ func (subnet *Subnet) joinFreeWithReserve() {
}
}

// This func is only called in ipam.GetPodAddress, move mutex to caller
func (subnet *Subnet) GetPodAddress(podName, nicName string) (IP, IP, string, string) {
subnet.mutex.RLock()
defer subnet.mutex.RUnlock()

if subnet.Protocol == kubeovnv1.ProtocolIPv4 {
ip, mac := subnet.V4NicToIP[nicName], subnet.NicToMac[nicName]
return ip, "", mac, kubeovnv1.ProtocolIPv4
Expand Down

0 comments on commit d698c73

Please sign in to comment.