Skip to content

Commit 659a4ae

Browse files
fix github issue 17475
If there are multiple clusterNetworkCIDR values on startup when generating the SubnetAllocators for each range "Provided subnet doesn't belong to network" gets printed after each subnet that belongs to a different range. I sorted the list of subnets so that each call to NewSubnetAllocator has the list of subnets that are within the clusterNetworkCIDR's range
1 parent 607caee commit 659a4ae

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pkg/network/master/subnets.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,34 @@ import (
2222
)
2323

2424
func (master *OsdnMaster) SubnetStartMaster(clusterNetworks []common.ClusterNetwork) error {
25-
subrange := make([]string, 0)
25+
subrange := make(map[common.ClusterNetwork][]string)
2626
subnets, err := master.networkClient.Network().HostSubnets().List(metav1.ListOptions{})
2727
if err != nil {
2828
glog.Errorf("Error in initializing/fetching subnets: %v", err)
2929
return err
3030
}
3131
for _, sub := range subnets.Items {
32-
subrange = append(subrange, sub.Subnet)
3332
if err = master.networkInfo.ValidateNodeIP(sub.HostIP); err != nil {
3433
// Don't error out; just warn so the error can be corrected with 'oc'
3534
glog.Errorf("Failed to validate HostSubnet %s: %v", common.HostSubnetToString(&sub), err)
3635
} else {
3736
glog.Infof("Found existing HostSubnet %s", common.HostSubnetToString(&sub))
37+
_, subnetIP, err := net.ParseCIDR(sub.Subnet)
38+
if err != nil {
39+
return fmt.Errorf("Failed to parse network address: %q", sub.Subnet)
40+
}
41+
42+
for _, cn := range clusterNetworks {
43+
if cn.ClusterCIDR.Contains(subnetIP.IP) {
44+
subrange[cn] = append(subrange[cn], sub.Subnet)
45+
break
46+
}
47+
}
3848
}
3949
}
4050
var subnetAllocatorList []*netutils.SubnetAllocator
4151
for _, cn := range clusterNetworks {
42-
subnetAllocator, err := netutils.NewSubnetAllocator(cn.ClusterCIDR.String(), cn.HostSubnetLength, subrange)
52+
subnetAllocator, err := netutils.NewSubnetAllocator(cn.ClusterCIDR.String(), cn.HostSubnetLength, subrange[cn])
4353
if err != nil {
4454
return err
4555
}

0 commit comments

Comments
 (0)