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 f536d48 commit 23c8df4
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 @@ -2080,6 +2080,11 @@ func (c *Controller) calcDualSubnetStatusIP(subnet *kubeovnv1.Subnet) (*kubeovnv
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
}

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

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

bytes, err := subnet.Status.Bytes()
if err != nil {
klog.Error(err)
Expand All @@ -2219,6 +2229,20 @@ func (c *Controller) calcSubnetStatusIP(subnet *kubeovnv1.Subnet) (*kubeovnv1.Su
return newSubnet, 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 util.IsOvnProvider(subnet.Spec.Provider)
}
Expand Down

0 comments on commit 23c8df4

Please sign in to comment.