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 Feb 18, 2020
1 parent 7eef000 commit 6e75adc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
44 changes: 23 additions & 21 deletions source/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,30 +234,32 @@ func (sc *serviceSource) extractHeadlessEndpoints(svc *v1.Service, hostname stri
}
for _, headlessDomain := range headlessDomains {
if sc.publishHostIP {
log.Debugf("Generating matching endpoint %s with HostIP %s", headlessDomain, v.Status.HostIP)
// To reduce traffic on the DNS API only add record for running Pods. Good Idea?
if v.Status.Phase == v1.PodRunning {
targetsByHeadlessDomain[headlessDomain] = append(targetsByHeadlessDomain[headlessDomain], v.Status.HostIP)
} else {
log.Debugf("Pod %s is not in running phase", v.Spec.Hostname)
}
} else if _, ok := svc.Annotations[externalIPAnnotationKey]; ok {
node, err := sc.nodeInformer.Lister().Get(v.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(v.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)
}
}
}

log.Debugf("Generating matching endpoint %s with Host ExternalIPs %v", headlessDomain, externalIPs)
if v.Status.Phase == v1.PodRunning {
targetsByHeadlessDomain[headlessDomain] = append(targetsByHeadlessDomain[headlessDomain], externalIPs...)
log.Debugf("Generating matching endpoint %s with Host ExternalIPs %v", headlessDomain, externalIPs)
if v.Status.Phase == v1.PodRunning {
targetsByHeadlessDomain[headlessDomain] = append(targetsByHeadlessDomain[headlessDomain], externalIPs...)
} else {
log.Debugf("Pod %s is not in running phase", v.Spec.Hostname)
}
} else {
log.Debugf("Pod %s is not in running phase", v.Spec.Hostname)
log.Debugf("Generating matching endpoint %s with HostIP %s", headlessDomain, v.Status.HostIP)
// To reduce traffic on the DNS API only add record for running Pods. Good Idea?
if v.Status.Phase == v1.PodRunning {
targetsByHeadlessDomain[headlessDomain] = append(targetsByHeadlessDomain[headlessDomain], v.Status.HostIP)
} else {
log.Debugf("Pod %s is not in running phase", v.Spec.Hostname)
}
}
} else {
log.Debugf("Generating matching endpoint %s with PodIP %s", headlessDomain, v.Status.PodIP)
Expand Down
2 changes: 1 addition & 1 deletion source/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,7 @@ func TestHeadlessServicesExternalHostIP(t *testing.T) {
false,
tc.compatibility,
true,
false,
true,
[]string{},
tc.ignoreHostnameAnnotation,
)
Expand Down

0 comments on commit 6e75adc

Please sign in to comment.