Skip to content

Commit

Permalink
fix: if cidr block not ends with zero, reformat it
Browse files Browse the repository at this point in the history
(cherry picked from commit f8248ce)
  • Loading branch information
oilbeater committed Jan 2, 2020
1 parent 1f5df24 commit 8435a33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ func (c *Controller) processNextDeleteSubnetWorkItem() bool {
func formatSubnet(subnet *kubeovnv1.Subnet, c *Controller) error {
var err error
changed := false
_, ipNet, err := net.ParseCIDR(subnet.Spec.CIDRBlock)
if err != nil {
return fmt.Errorf("subnet %s cidr %s is not a valid cidrblock", subnet.Name, subnet.Spec.CIDRBlock )
}
if ipNet.String() != subnet.Spec.CIDRBlock {
subnet.Spec.CIDRBlock = ipNet.String()
changed = true
}
if subnet.Spec.Protocol == "" || subnet.Spec.Protocol != util.CheckProtocol(subnet.Spec.CIDRBlock) {
subnet.Spec.Protocol = util.CheckProtocol(subnet.Spec.CIDRBlock)
changed = true
Expand Down
7 changes: 6 additions & 1 deletion pkg/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ func (c *Controller) reconcileRouters() error {
}
cidrs := []string{}
for _, subnet := range subnets {
cidrs = append(cidrs, subnet.Spec.CIDRBlock)
_, ipNet, err := net.ParseCIDR(subnet.Spec.CIDRBlock)
if err != nil {
klog.Errorf("%s is not a valid cidr block", subnet.Spec.CIDRBlock)
} else {
cidrs = append(cidrs, ipNet.String())
}
}
node, err := c.config.KubeClient.CoreV1().Nodes().Get(c.config.NodeName, metav1.GetOptions{})
if err != nil {
Expand Down

0 comments on commit 8435a33

Please sign in to comment.