@@ -19,7 +19,6 @@ package endpoint
19
19
import (
20
20
"context"
21
21
"fmt"
22
- "reflect"
23
22
"strconv"
24
23
"time"
25
24
@@ -213,64 +212,43 @@ func (e *EndpointController) addPod(obj interface{}) {
213
212
}
214
213
215
214
func podToEndpointAddressForService (svc * v1.Service , pod * v1.Pod ) (* v1.EndpointAddress , error ) {
215
+ var endpointIP string
216
+
216
217
if ! utilfeature .DefaultFeatureGate .Enabled (features .IPv6DualStack ) {
217
- return podToEndpointAddress (pod ), nil
218
- }
219
-
220
- // api-server service controller ensured that the service got the correct IP Family
221
- // according to user setup, here we only need to match EndPoint IPs' family to service
222
- // actual IP family. as in, we don't need to check service.IPFamily
223
-
224
- ipv6ClusterIP := utilnet .IsIPv6String (svc .Spec .ClusterIP )
225
- for _ , podIP := range pod .Status .PodIPs {
226
- ipv6PodIP := utilnet .IsIPv6String (podIP .IP )
227
- // same family?
228
- // TODO (khenidak) when we remove the max of 2 PodIP limit from pods
229
- // we will have to return multiple endpoint addresses
230
- if ipv6ClusterIP == ipv6PodIP {
231
- return & v1.EndpointAddress {
232
- IP : podIP .IP ,
233
- NodeName : & pod .Spec .NodeName ,
234
- TargetRef : & v1.ObjectReference {
235
- Kind : "Pod" ,
236
- Namespace : pod .ObjectMeta .Namespace ,
237
- Name : pod .ObjectMeta .Name ,
238
- UID : pod .ObjectMeta .UID ,
239
- ResourceVersion : pod .ObjectMeta .ResourceVersion ,
240
- }}, nil
218
+ // In a legacy cluster, the pod IP is guaranteed to be usable
219
+ endpointIP = pod .Status .PodIP
220
+ } else {
221
+ ipv6Service := endpointutil .IsIPv6Service (svc )
222
+ for _ , podIP := range pod .Status .PodIPs {
223
+ ipv6PodIP := utilnet .IsIPv6String (podIP .IP )
224
+ if ipv6Service == ipv6PodIP {
225
+ endpointIP = podIP .IP
226
+ break
227
+ }
228
+ }
229
+ if endpointIP == "" {
230
+ return nil , fmt .Errorf ("failed to find a matching endpoint for service %v" , svc .Name )
241
231
}
242
232
}
243
- return nil , fmt .Errorf ("failed to find a matching endpoint for service %v" , svc .Name )
244
- }
245
233
246
- func podToEndpointAddress (pod * v1.Pod ) * v1.EndpointAddress {
247
234
return & v1.EndpointAddress {
248
- IP : pod . Status . PodIP ,
235
+ IP : endpointIP ,
249
236
NodeName : & pod .Spec .NodeName ,
250
237
TargetRef : & v1.ObjectReference {
251
238
Kind : "Pod" ,
252
239
Namespace : pod .ObjectMeta .Namespace ,
253
240
Name : pod .ObjectMeta .Name ,
254
241
UID : pod .ObjectMeta .UID ,
255
242
ResourceVersion : pod .ObjectMeta .ResourceVersion ,
256
- }}
257
- }
258
-
259
- func endpointChanged (pod1 , pod2 * v1.Pod ) bool {
260
- endpointAddress1 := podToEndpointAddress (pod1 )
261
- endpointAddress2 := podToEndpointAddress (pod2 )
262
-
263
- endpointAddress1 .TargetRef .ResourceVersion = ""
264
- endpointAddress2 .TargetRef .ResourceVersion = ""
265
-
266
- return ! reflect .DeepEqual (endpointAddress1 , endpointAddress2 )
243
+ },
244
+ }, nil
267
245
}
268
246
269
247
// When a pod is updated, figure out what services it used to be a member of
270
248
// and what services it will be a member of, and enqueue the union of these.
271
249
// old and cur must be *v1.Pod types.
272
250
func (e * EndpointController ) updatePod (old , cur interface {}) {
273
- services := endpointutil .GetServicesToUpdateOnPodChange (e .serviceLister , e .serviceSelectorCache , old , cur , endpointChanged )
251
+ services := endpointutil .GetServicesToUpdateOnPodChange (e .serviceLister , e .serviceSelectorCache , old , cur )
274
252
for key := range services {
275
253
e .queue .AddAfter (key , e .endpointUpdatesBatchPeriod )
276
254
}
0 commit comments