aboutsummaryrefslogtreecommitdiff
path: root/plugin/federation/federation.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/federation/federation.go')
-rw-r--r--plugin/federation/federation.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/plugin/federation/federation.go b/plugin/federation/federation.go
index 779636b6a..daf470891 100644
--- a/plugin/federation/federation.go
+++ b/plugin/federation/federation.go
@@ -20,6 +20,7 @@ import (
"github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/plugin/pkg/dnsutil"
"github.com/coredns/coredns/plugin/pkg/nonwriter"
+ "github.com/coredns/coredns/plugin/pkg/upstream"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
@@ -27,8 +28,9 @@ import (
// Federation contains the name to zone mapping used for federation in kubernetes.
type Federation struct {
- f map[string]string
- zones []string
+ f map[string]string
+ zones []string
+ Upstream *upstream.Upstream
Next plugin.Handler
Federations Func
@@ -49,7 +51,8 @@ func (f *Federation) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.
return plugin.NextOrFailure(f.Name(), f.Next, ctx, w, r)
}
- state := request.Request{W: w, Req: r}
+ state := request.Request{W: w, Req: r, Context: ctx}
+
zone := plugin.Zones(f.zones).Matches(state.Name())
if zone == "" {
return plugin.NextOrFailure(f.Name(), f.Next, ctx, w, r)
@@ -105,6 +108,13 @@ func (f *Federation) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.
m.Answer = []dns.RR{service.NewCNAME(state.QName(), service.Host)}
+ if f.Upstream != nil {
+ aRecord, err := f.Upstream.Lookup(state, service.Host, state.QType())
+ if err == nil && aRecord != nil && len(aRecord.Answer) > 0 {
+ m.Answer = append(m.Answer, aRecord.Answer...)
+ }
+ }
+
w.WriteMsg(m)
return dns.RcodeSuccess, nil
}