@@ -278,6 +278,24 @@ func newServiceInfo(svcPortName proxy.ServicePortName, port *v1.ServicePort, ser
278
278
return info
279
279
}
280
280
281
+ func (network hnsNetworkInfo ) findRemoteSubnetProviderAddress (ip string ) string {
282
+ var providerAddress string
283
+ for _ , rs := range network .remoteSubnets {
284
+ _ , ipNet , err := net .ParseCIDR (rs .destinationPrefix )
285
+ if err != nil {
286
+ klog .Fatalf ("%v" , err )
287
+ }
288
+ if ipNet .Contains (net .ParseIP (ip )) {
289
+ providerAddress = rs .providerAddress
290
+ }
291
+ if ip == rs .providerAddress {
292
+ providerAddress = rs .providerAddress
293
+ }
294
+ }
295
+
296
+ return providerAddress
297
+ }
298
+
281
299
type endpointsChange struct {
282
300
previous proxyEndpointsMap
283
301
current proxyEndpointsMap
@@ -1153,24 +1171,12 @@ func (proxier *Proxier) syncProxyRules() {
1153
1171
return
1154
1172
}
1155
1173
proxier .network = * updatedNetwork
1156
- var providerAddress string
1157
- for _ , rs := range proxier .network .remoteSubnets {
1158
- _ , ipNet , err := net .ParseCIDR (rs .destinationPrefix )
1159
- if err != nil {
1160
- klog .Fatalf ("%v" , err )
1161
- }
1162
- if ipNet .Contains (net .ParseIP (ep .ip )) {
1163
- providerAddress = rs .providerAddress
1164
- }
1165
- if ep .ip == rs .providerAddress {
1166
- providerAddress = rs .providerAddress
1167
- containsNodeIP = true
1168
- }
1169
- }
1174
+
1175
+ providerAddress := proxier .network .findRemoteSubnetProviderAddress (ep .ip )
1176
+
1170
1177
if len (providerAddress ) == 0 {
1171
1178
klog .Infof ("Could not find provider address for %s. Assuming it is a public IP" , ep .ip )
1172
1179
providerAddress = proxier .nodeIP .String ()
1173
- containsPublicIP = true
1174
1180
}
1175
1181
1176
1182
hnsEndpoint := & endpointsInfo {
@@ -1200,6 +1206,17 @@ func (proxier *Proxier) syncProxyRules() {
1200
1206
}
1201
1207
}
1202
1208
1209
+ if proxier .network .networkType == "Overlay" {
1210
+ providerAddress := proxier .network .findRemoteSubnetProviderAddress (ep .ip )
1211
+
1212
+ isNodeIP := (ep .ip == providerAddress )
1213
+ isPublicIP := (len (providerAddress ) == 0 )
1214
+ klog .Infof ("Endpoint %s on overlay network %s is classified as NodeIp: %v, Public Ip: %v" , ep .ip , hnsNetworkName , isNodeIP , isPublicIP )
1215
+
1216
+ containsNodeIP = containsNodeIP || isNodeIP
1217
+ containsPublicIP = containsPublicIP || isPublicIP
1218
+ }
1219
+
1203
1220
// Save the hnsId for reference
1204
1221
LogJson (newHnsEndpoint , "Hns Endpoint resource" , 1 )
1205
1222
hnsEndpoints = append (hnsEndpoints , * newHnsEndpoint )
0 commit comments