@@ -41,18 +41,32 @@ func cidrListContains(cidrList []*net.IPNet, ipaddr net.IP) (*net.IPNet, bool) {
41
41
return nil , false
42
42
}
43
43
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
+
44
53
type NetworkInfo struct {
45
- ClusterNetwork []* net. IPNet
54
+ ClusterNetworks []ClusterNetwork
46
55
ServiceNetwork * net.IPNet
47
56
}
48
57
58
+ type ClusterNetwork struct {
59
+ ClusterCIDR * net.IPNet
60
+ HostSubnetLength uint32
61
+ }
62
+
49
63
//determine if two cidr addresses intersect
50
64
func intersect (cidr1 , cidr2 * net.IPNet ) bool {
51
65
return cidr2 .Contains (cidr1 .IP ) || cidr1 .Contains (cidr2 .IP )
52
66
}
53
67
54
68
func parseNetworkInfo (clusterNetwork []osapi.ClusterNetworkEntry , serviceNetwork string ) (* NetworkInfo , error ) {
55
- var cn []* net. IPNet
69
+ var cns []ClusterNetwork
56
70
57
71
for _ , entry := range clusterNetwork {
58
72
clusterAddress , err := netutils .ParseCIDRMask (entry .CIDR )
@@ -63,12 +77,12 @@ func parseNetworkInfo(clusterNetwork []osapi.ClusterNetworkEntry, serviceNetwork
63
77
}
64
78
glog .Errorf ("Configured clusterNetworkCIDR value %q is invalid; treating it as %q" , entry .CIDR , clusterAddress .String ())
65
79
}
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 ())
69
83
}
70
84
}
71
- cn = append (cn , clusterAddress )
85
+ cns = append (cns , ClusterNetwork { ClusterCIDR : clusterAddress , HostSubnetLength : entry . HostSubnetLength } )
72
86
}
73
87
74
88
sn , err := netutils .ParseCIDRMask (serviceNetwork )
@@ -81,7 +95,7 @@ func parseNetworkInfo(clusterNetwork []osapi.ClusterNetworkEntry, serviceNetwork
81
95
}
82
96
83
97
return & NetworkInfo {
84
- ClusterNetwork : cn ,
98
+ ClusterNetworks : cns ,
85
99
ServiceNetwork : sn ,
86
100
}, nil
87
101
}
@@ -98,9 +112,14 @@ func (ni *NetworkInfo) validateNodeIP(nodeIP string) error {
98
112
return fmt .Errorf ("failed to parse node IP %s" , nodeIP )
99
113
}
100
114
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
+ }
103
119
}
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
+ // }
104
123
if ni .ServiceNetwork .Contains (ipaddr ) {
105
124
return fmt .Errorf ("node IP %s conflicts with service network %s" , nodeIP , ni .ServiceNetwork .String ())
106
125
}
@@ -111,13 +130,14 @@ func (ni *NetworkInfo) validateNodeIP(nodeIP string) error {
111
130
func (ni * NetworkInfo ) checkHostNetworks (hostIPNets []* net.IPNet ) error {
112
131
errList := []error {}
113
132
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 ()))
117
140
}
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 ()))
121
141
}
122
142
if ipNet .Contains (ni .ServiceNetwork .IP ) {
123
143
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
136
156
subnetIP , _ , _ := net .ParseCIDR (subnet .Subnet )
137
157
if subnetIP == nil {
138
158
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 {
140
160
errList = append (errList , fmt .Errorf ("existing node subnet: %s in not part of any cluster network CIDR" , subnet .Subnet ))
141
161
}
142
162
if len (errList ) >= 10 {
@@ -147,7 +167,7 @@ func (ni *NetworkInfo) checkClusterObjects(subnets []osapi.HostSubnet, pods []ka
147
167
if pod .Spec .SecurityContext != nil && pod .Spec .SecurityContext .HostNetwork {
148
168
continue
149
169
}
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 != "" {
151
171
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 ))
152
172
if len (errList ) >= 10 {
153
173
break
0 commit comments