Skip to content

Commit 9c01b1b

Browse files
committed
move ipam.subnet.mutex to caller (#2571)
1 parent fb70f93 commit 9c01b1b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pkg/ipam/ipam.go

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func (ipam *IPAM) GetPodAddress(podName string) []*SubnetAddress {
215215
defer ipam.mutex.RUnlock()
216216
addresses := []*SubnetAddress{}
217217
for _, subnet := range ipam.Subnets {
218+
subnet.mutex.RLock()
218219
for _, nicName := range subnet.PodToNicList[podName] {
219220
v4IP, v6IP, mac, protocol := subnet.GetPodAddress(podName, nicName)
220221
switch protocol {
@@ -227,6 +228,7 @@ func (ipam *IPAM) GetPodAddress(podName string) []*SubnetAddress {
227228
addresses = append(addresses, &SubnetAddress{Subnet: subnet, Ip: string(v6IP), Mac: mac})
228229
}
229230
}
231+
subnet.mutex.RUnlock()
230232
}
231233
return addresses
232234
}

pkg/ipam/subnet.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,8 @@ func (subnet *Subnet) joinFreeWithReserve() {
543543
}
544544
}
545545

546+
// This func is only called in ipam.GetPodAddress, move mutex to caller
546547
func (subnet *Subnet) GetPodAddress(podName, nicName string) (IP, IP, string, string) {
547-
subnet.mutex.RLock()
548-
defer subnet.mutex.RUnlock()
549-
550548
if subnet.Protocol == kubeovnv1.ProtocolIPv4 {
551549
ip, mac := subnet.V4NicToIP[nicName], subnet.NicToMac[nicName]
552550
return ip, "", mac, kubeovnv1.ProtocolIPv4

0 commit comments

Comments
 (0)