Skip to content

Commit

Permalink
re calculate subnet using ips while inconsistency detected (#3920)
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <zhangbingbing2_yewu@cmss.chinamobile.com>
  • Loading branch information
bobz965 committed Apr 16, 2024
1 parent 698c934 commit 5893292
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,11 @@ func calcDualSubnetStatusIP(subnet *kubeovnv1.Subnet, c *Controller) error {
subnet.Status.V4AvailableIPRange = v4AvailableIPStr
subnet.Status.V6AvailableIPRange = v6AvailableIPStr

if err := c.checkSubnetUsingIPs(subnet); err != nil {
klog.Errorf("inconsistency detected in status of subnet %s : %v", subnet.Name, err)
return nil, err

Check failure on line 2078 in pkg/controller/subnet.go

View workflow job for this annotation

GitHub Actions / Build arm64

too many return values

Check failure on line 2078 in pkg/controller/subnet.go

View workflow job for this annotation

GitHub Actions / Build kube-ovn

too many return values
}

bytes, err := subnet.Status.Bytes()
if err != nil {
klog.Error(err)
Expand Down Expand Up @@ -2183,6 +2188,11 @@ func calcSubnetStatusIP(subnet *kubeovnv1.Subnet, c *Controller) error {
return nil
}

if err := c.checkSubnetUsingIPs(subnet); err != nil {
klog.Errorf("inconsistency detected in status of subnet %s : %v", subnet.Name, err)
return nil, err

Check failure on line 2193 in pkg/controller/subnet.go

View workflow job for this annotation

GitHub Actions / Build arm64

too many return values

Check failure on line 2193 in pkg/controller/subnet.go

View workflow job for this annotation

GitHub Actions / Build kube-ovn

too many return values
}

bytes, err := subnet.Status.Bytes()
if err != nil {
klog.Error(err)
Expand All @@ -2192,6 +2202,20 @@ func calcSubnetStatusIP(subnet *kubeovnv1.Subnet, c *Controller) error {
return err
}

func (c *Controller) checkSubnetUsingIPs(subnet *kubeovnv1.Subnet) error {
if subnet.Status.V4UsingIPs != 0 && subnet.Status.V4UsingIPRange == "" {
err := fmt.Errorf("subnet %s has %.0f v4 ip in use, while the v4 using ip range is empty", subnet.Name, subnet.Status.V4UsingIPs)
klog.Error(err)
return err
}
if subnet.Status.V6UsingIPs != 0 && subnet.Status.V6UsingIPRange == "" {
err := fmt.Errorf("subnet %s has %.0f v6 ip in use, while the v6 using ip range is empty", subnet.Name, subnet.Status.V6UsingIPs)
klog.Error(err)
return err
}
return nil
}

func isOvnSubnet(subnet *kubeovnv1.Subnet) bool {
return subnet.Spec.Provider == "" || subnet.Spec.Provider == util.OvnProvider || strings.HasSuffix(subnet.Spec.Provider, "ovn")
}
Expand Down

0 comments on commit 5893292

Please sign in to comment.