aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/ns.go
diff options
context:
space:
mode:
authorGravatar TomasKohout <tomas.kohout1995@gmail.com> 2022-08-30 20:59:27 +0200
committerGravatar GitHub <noreply@github.com> 2022-08-30 14:59:27 -0400
commit6782b7fb42efc979ab2649228a83c0ac20d50d5e (patch)
tree465f49c700aebcfb825227a3a45dfd38daace374 /plugin/kubernetes/ns.go
parentb218b56063a965dceeda2835b020f8672ba7e27a (diff)
downloadcoredns-6782b7fb42efc979ab2649228a83c0ac20d50d5e.tar.gz
coredns-6782b7fb42efc979ab2649228a83c0ac20d50d5e.tar.zst
coredns-6782b7fb42efc979ab2649228a83c0ac20d50d5e.zip
plugin/k8s_external: Resolve headless services (#5505)
*add option for resolving headless Services without external IPs in k8s_external Signed-off-by: Tomas Kohout <tomas.kohout1995@gmail.com>
Diffstat (limited to 'plugin/kubernetes/ns.go')
-rw-r--r--plugin/kubernetes/ns.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/plugin/kubernetes/ns.go b/plugin/kubernetes/ns.go
index 3e6a30586..eb40c3488 100644
--- a/plugin/kubernetes/ns.go
+++ b/plugin/kubernetes/ns.go
@@ -13,7 +13,7 @@ func isDefaultNS(name, zone string) bool {
// nsAddrs returns the A or AAAA records for the CoreDNS service in the cluster. If the service cannot be found,
// it returns a record for the local address of the machine we're running on.
-func (k *Kubernetes) nsAddrs(external bool, zone string) []dns.RR {
+func (k *Kubernetes) nsAddrs(external, headless bool, zone string) []dns.RR {
var (
svcNames []string
svcIPs []net.IP
@@ -31,10 +31,21 @@ func (k *Kubernetes) nsAddrs(external bool, zone string) []dns.RR {
for _, svc := range svcs {
if external {
svcName := strings.Join([]string{svc.Name, svc.Namespace, zone}, ".")
- for _, exIP := range svc.ExternalIPs {
- svcNames = append(svcNames, svcName)
- svcIPs = append(svcIPs, net.ParseIP(exIP))
+
+ if headless && svc.Headless() {
+ for _, s := range endpoint.Subsets {
+ for _, a := range s.Addresses {
+ svcNames = append(svcNames, endpointHostname(a, k.endpointNameMode)+"."+svcName)
+ svcIPs = append(svcIPs, net.ParseIP(a.IP))
+ }
+ }
+ } else {
+ for _, exIP := range svc.ExternalIPs {
+ svcNames = append(svcNames, svcName)
+ svcIPs = append(svcIPs, net.ParseIP(exIP))
+ }
}
+
continue
}
svcName := strings.Join([]string{svc.Name, svc.Namespace, Svc, zone}, ".")