@@ -290,6 +290,24 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *v1.ServicePort, ser
290
290
return info
291
291
}
292
292
293
+ func (network hnsNetworkInfo ) findRemoteSubnetProviderAddress (ip string ) string {
294
+ var providerAddress string
295
+ for _ , rs := range network .remoteSubnets {
296
+ _ , ipNet , err := net .ParseCIDR (rs .destinationPrefix )
297
+ if err != nil {
298
+ klog .Fatalf ("%v" , err )
299
+ }
300
+ if ipNet .Contains (net .ParseIP (ip )) {
301
+ providerAddress = rs .providerAddress
302
+ }
303
+ if ip == rs .providerAddress {
304
+ providerAddress = rs .providerAddress
305
+ }
306
+ }
307
+
308
+ return providerAddress
309
+ }
310
+
293
311
type endpointsChange struct {
294
312
previous proxyEndpointsMap
295
313
current proxyEndpointsMap
@@ -1169,24 +1187,12 @@ func (proxier *Proxier) syncProxyRules() {
1169
1187
return
1170
1188
}
1171
1189
proxier .network = * updatedNetwork
1172
- var providerAddress string
1173
- for _ , rs := range proxier .network .remoteSubnets {
1174
- _ , ipNet , err := net .ParseCIDR (rs .destinationPrefix )
1175
- if err != nil {
1176
- klog .Fatalf ("%v" , err )
1177
- }
1178
- if ipNet .Contains (net .ParseIP (ep .ip )) {
1179
- providerAddress = rs .providerAddress
1180
- }
1181
- if ep .ip == rs .providerAddress {
1182
- providerAddress = rs .providerAddress
1183
- containsNodeIP = true
1184
- }
1185
- }
1190
+
1191
+ providerAddress := proxier .network .findRemoteSubnetProviderAddress (ep .ip )
1192
+
1186
1193
if len (providerAddress ) == 0 {
1187
1194
klog .Infof ("Could not find provider address for %s. Assuming it is a public IP" , ep .ip )
1188
1195
providerAddress = proxier .nodeIP .String ()
1189
- containsPublicIP = true
1190
1196
}
1191
1197
1192
1198
hnsEndpoint := & endpointsInfo {
@@ -1216,6 +1222,17 @@ func (proxier *Proxier) syncProxyRules() {
1216
1222
}
1217
1223
}
1218
1224
1225
+ if proxier .network .networkType == "Overlay" {
1226
+ providerAddress := proxier .network .findRemoteSubnetProviderAddress (ep .ip )
1227
+
1228
+ isNodeIP := (ep .ip == providerAddress )
1229
+ isPublicIP := (len (providerAddress ) == 0 )
1230
+ klog .Infof ("Endpoint %s on overlay network %s is classified as NodeIp: %v, Public Ip: %v" , ep .ip , hnsNetworkName , isNodeIP , isPublicIP )
1231
+
1232
+ containsNodeIP = containsNodeIP || isNodeIP
1233
+ containsPublicIP = containsPublicIP || isPublicIP
1234
+ }
1235
+
1219
1236
// Save the hnsId for reference
1220
1237
LogJson (newHnsEndpoint , "Hns Endpoint resource" , 1 )
1221
1238
hnsEndpoints = append (hnsEndpoints , * newHnsEndpoint )
0 commit comments