diff options
author | 2018-10-15 12:43:03 -0400 | |
---|---|---|
committer | 2018-10-15 12:43:03 -0400 | |
commit | 6beeabc47ccebd77de2a41192e1cca3a882127a3 (patch) | |
tree | b77b0a4492edf2786b52bdaf5604047b9602ceba /plugin | |
parent | 1847ef6bd31ecd38fe5d19e54c47a812cb2ed303 (diff) | |
download | coredns-6beeabc47ccebd77de2a41192e1cca3a882127a3.tar.gz coredns-6beeabc47ccebd77de2a41192e1cca3a882127a3.tar.zst coredns-6beeabc47ccebd77de2a41192e1cca3a882127a3.zip |
plugin/federation: Add upstream option to federation (#2177)
* add upstream
* add upstream
* debug ci
* debug ci
* set context
* update readme
* update readme
* remove empty if
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/federation/README.md | 7 | ||||
-rw-r--r-- | plugin/federation/federation.go | 16 | ||||
-rw-r--r-- | plugin/federation/setup.go | 8 |
3 files changed, 28 insertions, 3 deletions
diff --git a/plugin/federation/README.md b/plugin/federation/README.md index 021921cb2..1bcd23af6 100644 --- a/plugin/federation/README.md +++ b/plugin/federation/README.md @@ -17,11 +17,16 @@ Enabling *federation* without also having *kubernetes* is a noop. ~~~ federation [ZONES...] { NAME DOMAIN + upstream [ADDRESS...] } ~~~ * Each **NAME** and **DOMAIN** defines federation membership. One entry for each. A duplicate **NAME** will silently overwrite any previous value. +* `upstream` [**ADDRESS**...] defines the upstream resolvers used for resolving the `CNAME` target + produced by this plugin. If no **ADDRESS** is given, CoreDNS + will resolve External Services against itself. **ADDRESS** can be an IP, an IP:port, or a path + to a file structured like resolv.conf. ## Examples @@ -33,6 +38,7 @@ Here we handle all service requests in the `prod` and `stage` federations. federation cluster.local { prod prod.feddomain.com staging staging.feddomain.com + upstream } } ~~~ @@ -45,6 +51,7 @@ cluster.local { federation { prod prod.feddomain.com staging staging.feddomain.com + upstream } } ~~~ 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 } diff --git a/plugin/federation/setup.go b/plugin/federation/setup.go index 06daaf4e1..84e9aba16 100644 --- a/plugin/federation/setup.go +++ b/plugin/federation/setup.go @@ -6,6 +6,7 @@ import ( "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin/kubernetes" + "github.com/coredns/coredns/plugin/pkg/upstream" "github.com/miekg/dns" "github.com/mholt/caddy" @@ -62,6 +63,13 @@ func federationParse(c *caddy.Controller) (*Federation, error) { for c.NextBlock() { x := c.Val() switch x { + case "upstream": + args := c.RemainingArgs() + u, err := upstream.New(args) + if err != nil { + return nil, err + } + fed.Upstream = &u default: args := c.RemainingArgs() if x := len(args); x != 1 { |