diff --git a/source/service.go b/source/service.go index d60d62ed8c..131b8b0d13 100644 --- a/source/service.go +++ b/source/service.go @@ -277,22 +277,23 @@ func (sc *serviceSource) extractHeadlessEndpoints(svc *v1.Service, hostname stri for _, headlessDomain := range headlessDomains { var ep []string if sc.publishHostIP { - ep = append(ep, pod.Status.HostIP) - log.Debugf("Generating matching endpoint %s with HostIP %s", headlessDomain, ep) - - } else if _, ok := svc.Annotations[externalIPAnnotationKey]; ok { - node, err := sc.nodeInformer.Lister().Get(pod.Spec.NodeName) - if err != nil { - return nil - } - var externalIPs endpoint.Targets - for _, address := range node.Status.Addresses { - if address.Type == v1.NodeExternalIP { - externalIPs = append(externalIPs, address.Address) + if _, ok := svc.Annotations[externalIPAnnotationKey]; ok { + node, err := sc.nodeInformer.Lister().Get(pod.Spec.NodeName) + if err != nil { + return nil + } + var externalIPs endpoint.Targets + for _, address := range node.Status.Addresses { + if address.Type == v1.NodeExternalIP { + externalIPs = append(externalIPs, address.Address) + } } + ep = append(ep, externalIPs...) + log.Debugf("Generating matching endpoint %s with Host ExternalIPs %v", headlessDomain, externalIPs) + } else { + ep = append(ep, pod.Status.HostIP) + log.Debugf("Generating matching endpoint %s with HostIP %s", headlessDomain, ep) } - ep = append(ep, externalIPs...) - log.Debugf("Generating matching endpoint %s with Host ExternalIPs %v", headlessDomain, externalIPs) } else { ep = append(ep, address.IP) log.Debugf("Generating matching endpoint %s with EndpointAddress IP %s", headlessDomain, ep) diff --git a/source/service_test.go b/source/service_test.go index 7246ca4b9e..c81c68839e 100644 --- a/source/service_test.go +++ b/source/service_test.go @@ -2495,6 +2495,7 @@ func TestHeadlessServicesExternalHostIP(t *testing.T) { false, tc.compatibility, true, + true, false, []string{}, tc.ignoreHostnameAnnotation,