Skip to content

Commit

Permalink
ExternalIPAnnotation serves as an override/hint of publishHostIP flag
Browse files Browse the repository at this point in the history
  • Loading branch information
coufalja committed Mar 23, 2020
1 parent 1c27627 commit c90c70c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
29 changes: 15 additions & 14 deletions source/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions source/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,7 @@ func TestHeadlessServicesExternalHostIP(t *testing.T) {
false,
tc.compatibility,
true,
true,
false,
[]string{},
tc.ignoreHostnameAnnotation,
Expand Down

0 comments on commit c90c70c

Please sign in to comment.