Skip to content

Commit 31a1f14

Browse files
human edited files for initial hostsubnetlength per cidr
1 parent 039d2e3 commit 31a1f14

File tree

13 files changed

+76
-44
lines changed

13 files changed

+76
-44
lines changed

pkg/cmd/server/api/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ type MasterNetworkConfig struct {
630630

631631
type ClusterNetworkEntry struct {
632632
CIDR string
633+
HostSubnetLength uint32
633634
}
634635

635636
type ImageConfig struct {

pkg/cmd/server/api/v1/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ type MasterNetworkConfig struct {
518518
// ClusterNetworkEntry defines an L3 space for the global overlay network
519519
type ClusterNetworkEntry struct {
520520
CIDR string `json:"cidr"`
521+
HostSubnetLength uint32 `json:"hostsubnetlength"`
521522
}
522523

523524
// ImageConfig holds the necessary configuration options for building image names for system components

pkg/cmd/server/start/master_args.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/url"
77
"path"
88
"strconv"
9-
"strings"
9+
// "strings"
1010

1111
"github.com/spf13/pflag"
1212

@@ -189,14 +189,21 @@ func (args MasterArgs) BuildSerializeableMasterConfig() (*configapi.MasterConfig
189189

190190
dnsServingInfo := servingInfoForAddr(&dnsBindAddr)
191191

192-
var clusterNetworkConfig []configapi.ClusterNetworkEntry
193192

194-
for _, cidr := range strings.Split(args.NetworkArgs.ClusterNetworkCIDR, ",") {
195-
clusterNetworkEntry := configapi.ClusterNetworkEntry{
196-
CIDR: cidr,
197-
}
198-
clusterNetworkConfig = append(clusterNetworkConfig, clusterNetworkEntry)
199-
}
193+
clusterNetworkConfig := []configapi.ClusterNetworkEntry{
194+
configapi.ClusterNetworkEntry{
195+
CIDR:args.NetworkArgs.ClusterNetworkCIDR,
196+
HostSubnetLength: args.NetworkArgs.HostSubnetLength,
197+
},
198+
}
199+
// var clusterNetworkConfig []configapi.ClusterNetworkEntry
200+
201+
// for _, cidr := range strings.Split(args.NetworkArgs.ClusterNetworkCIDR, ",") {
202+
// clusterNetworkEntry := configapi.ClusterNetworkEntry{
203+
// CIDR: cidr,
204+
// }
205+
// clusterNetworkConfig = append(clusterNetworkConfig, clusterNetworkEntry)
206+
// }
200207

201208
config := &configapi.MasterConfig{
202209
ServingInfo: configapi.HTTPServingInfo{

pkg/sdn/apis/network/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type ClusterNetwork struct {
2424

2525
type ClusterNetworkEntry struct {
2626
CIDR string
27+
HostSubnetLength uint32
2728
}
2829

2930
type ClusterNetworkList struct {

pkg/sdn/apis/network/v1/types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ type ClusterNetwork struct {
3232

3333
// PLACEHOLDER
3434
type ClusterNetworkEntry struct {
35-
CIDR string `json:"CIDR" protobuf:"bytes,1,opt,name=CIDR"`
35+
CIDR string `json:"CIDR" protobuf:"bytes,1,opt,name=CIDR"`
36+
HostSubnetLength uint32 `json:"hostsubnetlength" protobuf:"varint,2,opt,name=hostsubnetlength"`
3637
}
3738

3839
// ClusterNetworkList is a collection of ClusterNetworks

pkg/sdn/plugin/common.go

+37-17
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,32 @@ func cidrListContains(cidrList []*net.IPNet, ipaddr net.IP) (*net.IPNet, bool) {
4141
return nil, false
4242
}
4343

44+
func clusterNetworkListContains(clusterNetworks []ClusterNetwork, ipaddr net.IP) (*net.IPNet, bool) {
45+
for _, cn := range clusterNetworks {
46+
if cn.ClusterCIDR.Contains(ipaddr) {
47+
return cn.ClusterCIDR, true
48+
}
49+
}
50+
return nil, false
51+
}
52+
4453
type NetworkInfo struct {
45-
ClusterNetwork []*net.IPNet
54+
ClusterNetworks []ClusterNetwork
4655
ServiceNetwork *net.IPNet
4756
}
4857

58+
type ClusterNetwork struct {
59+
ClusterCIDR *net.IPNet
60+
HostSubnetLength uint32
61+
}
62+
4963
//determine if two cidr addresses intersect
5064
func intersect(cidr1, cidr2 *net.IPNet) bool {
5165
return cidr2.Contains(cidr1.IP) || cidr1.Contains(cidr2.IP)
5266
}
5367

5468
func parseNetworkInfo(clusterNetwork []osapi.ClusterNetworkEntry, serviceNetwork string) (*NetworkInfo, error) {
55-
var cn []*net.IPNet
69+
var cns []ClusterNetwork
5670

5771
for _, entry := range clusterNetwork {
5872
clusterAddress, err := netutils.ParseCIDRMask(entry.CIDR)
@@ -63,12 +77,12 @@ func parseNetworkInfo(clusterNetwork []osapi.ClusterNetworkEntry, serviceNetwork
6377
}
6478
glog.Errorf("Configured clusterNetworkCIDR value %q is invalid; treating it as %q", entry.CIDR, clusterAddress.String())
6579
}
66-
for _, cidr := range cn {
67-
if intersect(cidr, clusterAddress) {
68-
return nil, fmt.Errorf("Two of the cidr addresses overlap: %s, %s", cidr.String(), clusterAddress.String())
80+
for _, cn := range cns {
81+
if intersect(cn.ClusterCIDR, clusterAddress) {
82+
return nil, fmt.Errorf("Two of the cidr addresses overlap: %s, %s", cn.ClusterCIDR.String(), clusterAddress.String())
6983
}
7084
}
71-
cn = append(cn, clusterAddress)
85+
cns = append(cns, ClusterNetwork{ClusterCIDR: clusterAddress, HostSubnetLength: entry.HostSubnetLength})
7286
}
7387

7488
sn, err := netutils.ParseCIDRMask(serviceNetwork)
@@ -81,7 +95,7 @@ func parseNetworkInfo(clusterNetwork []osapi.ClusterNetworkEntry, serviceNetwork
8195
}
8296

8397
return &NetworkInfo{
84-
ClusterNetwork: cn,
98+
ClusterNetworks: cns,
8599
ServiceNetwork: sn,
86100
}, nil
87101
}
@@ -98,9 +112,14 @@ func (ni *NetworkInfo) validateNodeIP(nodeIP string) error {
98112
return fmt.Errorf("failed to parse node IP %s", nodeIP)
99113
}
100114

101-
if clusterIP, contains := cidrListContains(ni.ClusterNetwork, ipaddr); contains {
102-
return fmt.Errorf("node IP %s conflicts with cluster network address %s", nodeIP, clusterIP.String())
115+
for _, clusterNetwork := range ni.ClusterNetworks {
116+
if clusterNetwork.ClusterCIDR.Contains(ipaddr){
117+
return fmt.Errorf("node IP %s conflicts with cluster network address %s", nodeIP, clusterNetwork.ClusterCIDR.String())
118+
}
103119
}
120+
// if clusterIP, contains := cidrListContains(ni.ClusterNetwork, ipaddr); contains {
121+
// return fmt.Errorf("node IP %s conflicts with cluster network address %s", nodeIP, clusterIP.String())
122+
// }
104123
if ni.ServiceNetwork.Contains(ipaddr) {
105124
return fmt.Errorf("node IP %s conflicts with service network %s", nodeIP, ni.ServiceNetwork.String())
106125
}
@@ -111,13 +130,14 @@ func (ni *NetworkInfo) validateNodeIP(nodeIP string) error {
111130
func (ni *NetworkInfo) checkHostNetworks(hostIPNets []*net.IPNet) error {
112131
errList := []error{}
113132
for _, ipNet := range hostIPNets {
114-
for _, clusterCIDR := range ni.ClusterNetwork {
115-
if ipNet.Contains(clusterCIDR.IP) {
116-
errList = append(errList, fmt.Errorf("cluster IP: %s conflicts with host network: %s", clusterCIDR.IP.String(), ipNet.String()))
133+
for _, clusterNetwork := range ni.ClusterNetworks {
134+
if ipNet.Contains(clusterNetwork.ClusterCIDR.IP) {
135+
errList = append(errList, fmt.Errorf("cluster IP: %s conflicts with host network: %s", clusterNetwork.ClusterCIDR.IP.String(), ipNet.String()))
136+
}
137+
if clusterNetwork.ClusterCIDR.Contains(ipNet.IP) {
138+
139+
errList = append(errList, fmt.Errorf("host network with IP: %s conflicts with cluster network address: %s", ipNet.IP.String(), clusterNetwork.ClusterCIDR.String()))
117140
}
118-
}
119-
if clusterCIDR, contains := cidrListContains(ni.ClusterNetwork, ipNet.IP); contains {
120-
errList = append(errList, fmt.Errorf("host network with IP: %s conflicts with cluster network address: %s", ipNet.IP.String(), clusterCIDR.String()))
121141
}
122142
if ipNet.Contains(ni.ServiceNetwork.IP) {
123143
errList = append(errList, fmt.Errorf("service IP: %s conflicts with host network: %s", ni.ServiceNetwork.String(), ipNet.String()))
@@ -136,7 +156,7 @@ func (ni *NetworkInfo) checkClusterObjects(subnets []osapi.HostSubnet, pods []ka
136156
subnetIP, _, _ := net.ParseCIDR(subnet.Subnet)
137157
if subnetIP == nil {
138158
errList = append(errList, fmt.Errorf("failed to parse network address: %s", subnet.Subnet))
139-
} else if _, contains := cidrListContains(ni.ClusterNetwork, subnetIP); !contains {
159+
} else if _, contains := clusterNetworkListContains(ni.ClusterNetworks, subnetIP); !contains {
140160
errList = append(errList, fmt.Errorf("existing node subnet: %s in not part of any cluster network CIDR", subnet.Subnet))
141161
}
142162
if len(errList) >= 10 {
@@ -147,7 +167,7 @@ func (ni *NetworkInfo) checkClusterObjects(subnets []osapi.HostSubnet, pods []ka
147167
if pod.Spec.SecurityContext != nil && pod.Spec.SecurityContext.HostNetwork {
148168
continue
149169
}
150-
if _, contains := cidrListContains(ni.ClusterNetwork, net.ParseIP(pod.Status.PodIP)); !contains && pod.Status.PodIP != "" {
170+
if _, contains := clusterNetworkListContains(ni.ClusterNetworks, net.ParseIP(pod.Status.PodIP)); !contains && pod.Status.PodIP != "" {
151171
errList = append(errList, fmt.Errorf("existing pod %s:%s with IP %s is not part of cluster network", pod.Namespace, pod.Name, pod.Status.PodIP))
152172
if len(errList) >= 10 {
153173
break

pkg/sdn/plugin/master.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func StartMaster(networkConfig osconfigapi.MasterNetworkConfig, osClient *osclie
5050
var err error
5151
var clusterNetworkEntries []osapi.ClusterNetworkEntry
5252
for _, cidr := range networkConfig.ClusterNetworks {
53-
clusterNetworkEntries = append(clusterNetworkEntries, osapi.ClusterNetworkEntry{CIDR: cidr.CIDR})
53+
clusterNetworkEntries = append(clusterNetworkEntries, osapi.ClusterNetworkEntry{CIDR: cidr.CIDR, HostSubnetLength: cidr.HostSubnetLength})
5454
}
5555
master.networkInfo, err = parseNetworkInfo(clusterNetworkEntries, networkConfig.ServiceNetworkCIDR)
5656
if err != nil {
@@ -119,7 +119,7 @@ func StartMaster(networkConfig osconfigapi.MasterNetworkConfig, osClient *osclie
119119
return err
120120
}
121121

122-
if err = master.SubnetStartMaster(master.networkInfo.ClusterNetwork, networkConfig.HostSubnetLength); err != nil {
122+
if err = master.SubnetStartMaster(master.networkInfo.ClusterNetworks); err != nil {
123123
return err
124124
}
125125

pkg/sdn/plugin/networkpolicy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func (np *networkPolicyPlugin) Start(node *OsdnNode) error {
7777
}
7878

7979
otx := node.oc.NewTransaction()
80-
for _, cidr := range np.node.networkInfo.ClusterNetwork {
81-
otx.AddFlow("table=21, priority=200, ip, nw_dst=%s, actions=ct(commit,table=30)", cidr.String())
80+
for _, cn := range np.node.networkInfo.ClusterNetworks {
81+
otx.AddFlow("table=21, priority=200, ip, nw_dst=%s, actions=ct(commit,table=30)", cn.ClusterCIDR.String())
8282
}
8383
otx.AddFlow("table=80, priority=200, ip, ct_state=+rpl, actions=output:NXM_NX_REG2[]")
8484
if err := otx.EndTransaction(); err != nil {

pkg/sdn/plugin/node.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ func (node *OsdnNode) Start() error {
268268
}
269269

270270
var cidrList []string
271-
for _, cidr := range node.networkInfo.ClusterNetwork {
272-
cidrList = append(cidrList, cidr.String())
271+
for _, cn := range node.networkInfo.ClusterNetworks {
272+
cidrList = append(cidrList, cn.ClusterCIDR.String())
273273
}
274274
nodeIPTables := newNodeIPTables(cidrList, node.iptablesSyncPeriod, !node.useConnTrack)
275275

@@ -295,7 +295,7 @@ func (node *OsdnNode) Start() error {
295295
}
296296

297297
log.V(5).Infof("Starting openshift-sdn pod manager")
298-
if err := node.podManager.Start(cniserver.CNIServerSocketPath, node.localSubnetCIDR, node.networkInfo.ClusterNetwork); err != nil {
298+
if err := node.podManager.Start(cniserver.CNIServerSocketPath, node.localSubnetCIDR, node.networkInfo.ClusterNetworks); err != nil {
299299
return err
300300
}
301301

pkg/sdn/plugin/pod.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func newDefaultPodManager() *podManager {
7373
// Generates a CNI IPAM config from a given node cluster and local subnet that
7474
// CNI 'host-local' IPAM plugin will use to create an IP address lease for the
7575
// container
76-
func getIPAMConfig(clusterNetwork []*net.IPNet, localSubnet string) ([]byte, error) {
76+
func getIPAMConfig(clusterNetworks []ClusterNetwork, localSubnet string) ([]byte, error) {
7777
nodeNet, err := cnitypes.ParseCIDR(localSubnet)
7878
if err != nil {
7979
return nil, fmt.Errorf("error parsing node network '%s': %v", localSubnet, err)
@@ -108,8 +108,8 @@ func getIPAMConfig(clusterNetwork []*net.IPNet, localSubnet string) ([]byte, err
108108
},
109109
}
110110

111-
for _, cidr := range clusterNetwork {
112-
routes = append(routes, cnitypes.Route{Dst: *cidr})
111+
for _, cn := range clusterNetworks {
112+
routes = append(routes, cnitypes.Route{Dst: *cn.ClusterCIDR})
113113
}
114114

115115
return json.Marshal(&cniNetworkConfig{
@@ -127,11 +127,11 @@ func getIPAMConfig(clusterNetwork []*net.IPNet, localSubnet string) ([]byte, err
127127
}
128128

129129
// Start the CNI server and start processing requests from it
130-
func (m *podManager) Start(socketPath string, localSubnetCIDR string, clusterNetwork []*net.IPNet) error {
130+
func (m *podManager) Start(socketPath string, localSubnetCIDR string, clusterNetworks []ClusterNetwork) error {
131131
m.hostportSyncer = kubehostport.NewHostportSyncer()
132132

133133
var err error
134-
if m.ipamConfig, err = getIPAMConfig(clusterNetwork, localSubnetCIDR); err != nil {
134+
if m.ipamConfig, err = getIPAMConfig(clusterNetworks, localSubnetCIDR); err != nil {
135135
return err
136136
}
137137

pkg/sdn/plugin/proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ EndpointLoop:
252252
for _, ss := range ep.Subsets {
253253
for _, addr := range ss.Addresses {
254254
IP := net.ParseIP(addr.IP)
255-
if _, contains := cidrListContains(proxy.networkInfo.ClusterNetwork, IP); !contains && !proxy.networkInfo.ServiceNetwork.Contains(IP) {
255+
if _, contains := clusterNetworkListContains(proxy.networkInfo.ClusterNetworks, IP); !contains && !proxy.networkInfo.ServiceNetwork.Contains(IP) {
256256
if proxy.firewallBlocksIP(ns, IP) {
257257
glog.Warningf("Service '%s' in namespace '%s' has an Endpoint pointing to firewalled destination (%s)", ep.ObjectMeta.Name, ns, addr.IP)
258258
continue EndpointLoop

pkg/sdn/plugin/sdn_controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ func deleteLocalSubnetRoute(device, localSubnetCIDR string) {
131131

132132
func (plugin *OsdnNode) SetupSDN() (bool, error) {
133133
var clusterNetworkCIDRs []string
134-
for _, cidr := range plugin.networkInfo.ClusterNetwork {
135-
clusterNetworkCIDRs = append(clusterNetworkCIDRs, cidr.String())
134+
for _, cn := range plugin.networkInfo.ClusterNetworks {
135+
clusterNetworkCIDRs = append(clusterNetworkCIDRs, cn.ClusterCIDR.String())
136136
}
137137

138138
serviceNetworkCIDR := plugin.networkInfo.ServiceNetwork.String()

pkg/sdn/plugin/subnets.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/openshift/origin/pkg/util/netutils"
2020
)
2121

22-
func (master *OsdnMaster) SubnetStartMaster(clusterNetwork []*net.IPNet, hostSubnetLength uint32) error {
22+
func (master *OsdnMaster) SubnetStartMaster(clusterNetworks []ClusterNetwork) error {
2323
subrange := make([]string, 0)
2424
subnets, err := master.osClient.HostSubnets().List(metav1.ListOptions{})
2525
if err != nil {
@@ -36,8 +36,9 @@ func (master *OsdnMaster) SubnetStartMaster(clusterNetwork []*net.IPNet, hostSub
3636
}
3737
}
3838
var subnetAllocatorList []*netutils.SubnetAllocator
39-
for _, cidr := range clusterNetwork {
40-
subnetAllocator, err := netutils.NewSubnetAllocator(cidr.String(), hostSubnetLength, subrange)
39+
for _, cn := range clusterNetworks {
40+
log.Infof("KEYWORD: ClusterCIDR: %s, HostSubnetLength: %d",cn.ClusterCIDR.String(), cn.HostSubnetLength)
41+
subnetAllocator, err := netutils.NewSubnetAllocator(cn.ClusterCIDR.String(), cn.HostSubnetLength, subrange)
4142
if err != nil {
4243
return err
4344
}

0 commit comments

Comments
 (0)