Skip to content

Commit

Permalink
ipam update condition refactor (#2651)
Browse files Browse the repository at this point in the history
  • Loading branch information
changluyi committed Apr 18, 2023
1 parent 05e7251 commit 933d76e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 15 additions & 0 deletions pkg/ipam/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ func (iprl IPRangeList) Contains(ip IP) bool {
return false
}

func (iprl IPRangeList) Equal(iprl2 IPRangeList) bool {
if len(iprl) != len(iprl2) {
return false
}

for i, range1 := range iprl {
range2 := iprl2[i]
if !range1.Start.Equal(range2.Start) || !range1.End.Equal(range2.End) {
return false
}
}

return true
}

func (iprl IPRangeList) IpRangetoString() string {
var ipRangeString []string
for _, ipr := range iprl {
Expand Down
9 changes: 7 additions & 2 deletions pkg/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ func (ipam *IPAM) AddOrUpdateSubnet(name, cidrStr, gw string, excludeIps []strin

if subnet, ok := ipam.Subnets[name]; ok {
subnet.Protocol = protocol
if protocol == kubeovnv1.ProtocolDual || protocol == kubeovnv1.ProtocolIPv4 {
if protocol == kubeovnv1.ProtocolDual || protocol == kubeovnv1.ProtocolIPv4 &&
(subnet.V4CIDR.String() != v4cidrStr || subnet.V4Gw != v4Gw || !subnet.V4ReservedIPList.Equal(convertExcludeIps(v4ExcludeIps))) {
_, cidr, _ := net.ParseCIDR(v4cidrStr)
subnet.V4CIDR = cidr
subnet.V4ReservedIPList = convertExcludeIps(v4ExcludeIps)
Expand All @@ -164,6 +165,7 @@ func (ipam *IPAM) AddOrUpdateSubnet(name, cidrStr, gw string, excludeIps []strin
subnet.V4FreeIPList = IPRangeList{&IPRange{Start: IP(firstIP), End: IP(lastIP)}}
subnet.joinFreeWithReserve()
subnet.V4ReleasedIPList = IPRangeList{}
subnet.V4Gw = v4Gw
for nicName, ip := range subnet.V4NicToIP {
mac := subnet.NicToMac[nicName]
podName := subnet.V4IPToPod[ip]
Expand All @@ -172,7 +174,9 @@ func (ipam *IPAM) AddOrUpdateSubnet(name, cidrStr, gw string, excludeIps []strin
}
}
}
if protocol == kubeovnv1.ProtocolDual || protocol == kubeovnv1.ProtocolIPv6 {
if protocol == kubeovnv1.ProtocolDual || protocol == kubeovnv1.ProtocolIPv6 &&
(subnet.V6CIDR.String() != v6cidrStr || subnet.V6Gw != v6Gw || !subnet.V6ReservedIPList.Equal(convertExcludeIps(v6ExcludeIps))) {

_, cidr, _ := net.ParseCIDR(v6cidrStr)
subnet.V6CIDR = cidr
subnet.V6ReservedIPList = convertExcludeIps(v6ExcludeIps)
Expand All @@ -181,6 +185,7 @@ func (ipam *IPAM) AddOrUpdateSubnet(name, cidrStr, gw string, excludeIps []strin
subnet.V6FreeIPList = IPRangeList{&IPRange{Start: IP(firstIP), End: IP(lastIP)}}
subnet.joinFreeWithReserve()
subnet.V6ReleasedIPList = IPRangeList{}
subnet.V6Gw = v6Gw
for nicName, ip := range subnet.V6NicToIP {
mac := subnet.NicToMac[nicName]
podName := subnet.V6IPToPod[ip]
Expand Down

0 comments on commit 933d76e

Please sign in to comment.