@@ -214,39 +214,15 @@ func (e *Controller) addPod(obj interface{}) {
214
214
215
215
func podToEndpointAddressForService (svc * v1.Service , pod * v1.Pod ) (* v1.EndpointAddress , error ) {
216
216
var endpointIP string
217
- ipFamily := v1 .IPv4Protocol
218
217
219
- if len (svc .Spec .IPFamilies ) > 0 {
220
- // controller is connected to an api-server that correctly sets IPFamilies
221
- ipFamily = svc .Spec .IPFamilies [0 ] // this works for headful and headless
222
- } else {
223
- // controller is connected to an api server that does not correctly
224
- // set IPFamilies (e.g. old api-server during an upgrade)
225
- // TODO (khenidak): remove by when the possibility of upgrading
226
- // from a cluster that does not support dual stack is nil
227
- if len (svc .Spec .ClusterIP ) > 0 && svc .Spec .ClusterIP != v1 .ClusterIPNone {
228
- // headful service. detect via service clusterIP
229
- if utilnet .IsIPv6String (svc .Spec .ClusterIP ) {
230
- ipFamily = v1 .IPv6Protocol
231
- }
232
- } else {
233
- // Since this is a headless service we use podIP to identify the family.
234
- // This assumes that status.PodIP is assigned correctly (follows pod cidr and
235
- // pod cidr list order is same as service cidr list order). The expectation is
236
- // this is *most probably* the case.
237
-
238
- // if the family was incorrectly identified then this will be corrected once the
239
- // upgrade is completed (controller connects to api-server that correctly defaults services)
240
- if utilnet .IsIPv6String (pod .Status .PodIP ) {
241
- ipFamily = v1 .IPv6Protocol
242
- }
243
- }
244
- }
218
+ wantIPv6 := svc .Spec .IPFamilies [0 ] == v1 .IPv6Protocol
245
219
246
- // find an ip that matches the family
220
+ // Find an IP that matches the family. We parse and restringify the IP in case the
221
+ // value on the Pod is in an irregular format.
247
222
for _ , podIP := range pod .Status .PodIPs {
248
- if (ipFamily == v1 .IPv6Protocol ) == utilnet .IsIPv6String (podIP .IP ) {
249
- endpointIP = podIP .IP
223
+ ip := utilnet .ParseIPSloppy (podIP .IP )
224
+ if wantIPv6 == utilnet .IsIPv6 (ip ) {
225
+ endpointIP = ip .String ()
250
226
break
251
227
}
252
228
}
0 commit comments