Skip to content

Commit

Permalink
fix: empty loop (#3615)
Browse files Browse the repository at this point in the history
* fix: empty top loop

* fix: no need to compare gateway ip with pod ip


---------

Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 authored Jan 12, 2024
1 parent 2641a59 commit bafdeae
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2040,12 +2040,25 @@ func (c *Controller) calcDualSubnetStatusIP(subnet *kubeovnv1.Subnet) (*kubeovnv
var lenIP, lenVip, lenIptablesEip, lenOvnEip int
lenIP = len(podUsedIPs)
usingIPNums := lenIP

// TODO:// replace ExcludeIps with ip pool and gw to avoid later loop
noGWExcludeIPs := []string{}
v4gw, v6gw := util.SplitStringIP(subnet.Spec.Gateway)
for _, excludeIP := range subnet.Spec.ExcludeIps {
if v4gw == excludeIP || v6gw == excludeIP {
// no need to compair gateway ip with pod ip
continue
}
noGWExcludeIPs = append(noGWExcludeIPs, excludeIP)
}
if noGWExcludeIPs != nil {
for _, podUsedIP := range podUsedIPs {
if util.ContainsIPs(excludeIP, podUsedIP.Spec.V4IPAddress) || util.ContainsIPs(excludeIP, podUsedIP.Spec.V6IPAddress) {
// This ip cr is allocated from subnet.spec.excludeIPs, do not count it as usingIPNums
usingIPNums--
break
for _, excludeIP := range noGWExcludeIPs {
if util.ContainsIPs(excludeIP, podUsedIP.Spec.V4IPAddress) || util.ContainsIPs(excludeIP, podUsedIP.Spec.V6IPAddress) {
// This ip cr is allocated from subnet.spec.excludeIPs, do not count it as usingIPNums
usingIPNums--
break
}
}
}
}
Expand Down Expand Up @@ -2157,12 +2170,25 @@ func (c *Controller) calcSubnetStatusIP(subnet *kubeovnv1.Subnet) (*kubeovnv1.Su
}
lenIP = len(podUsedIPs)
usingIPNums := lenIP

// TODO:// replace ExcludeIps with ip pool and gw to avoid later loop
noGWExcludeIPs := []string{}
v4gw, v6gw := util.SplitStringIP(subnet.Spec.Gateway)
for _, excludeIP := range subnet.Spec.ExcludeIps {
if v4gw == excludeIP || v6gw == excludeIP {
// no need to compair gateway ip with pod ip
continue
}
noGWExcludeIPs = append(noGWExcludeIPs, excludeIP)
}
if noGWExcludeIPs != nil {
for _, podUsedIP := range podUsedIPs {
if util.ContainsIPs(excludeIP, podUsedIP.Spec.V4IPAddress) || util.ContainsIPs(excludeIP, podUsedIP.Spec.V6IPAddress) {
// This ip cr is allocated from subnet.spec.excludeIPs, do not count it as usingIPNums
usingIPNums--
break
for _, excludeIP := range noGWExcludeIPs {
if util.ContainsIPs(excludeIP, podUsedIP.Spec.V4IPAddress) || util.ContainsIPs(excludeIP, podUsedIP.Spec.V6IPAddress) {
// This ip cr is allocated from subnet.spec.excludeIPs, do not count it as usingIPNums
usingIPNums--
break
}
}
}
}
Expand Down

0 comments on commit bafdeae

Please sign in to comment.