backend.Records make it take request.Request (#943)

This is more general and aligns well with the other methods.
Also allows the kubernetes middleware to use it.

Fixes #940
This commit is contained in:
Miek Gieben 2017-08-19 14:03:03 +01:00 committed by GitHub
parent 627687b11f
commit 7c343982a6
4 changed files with 14 additions and 12 deletions

View file

@ -28,7 +28,7 @@ type ServiceBackend interface {
// Returns _all_ services that matches a certain name. // Returns _all_ services that matches a certain name.
// Note: it does not implement a specific service. // Note: it does not implement a specific service.
Records(name string, exact bool) ([]msg.Service, error) Records(state request.Request, exact bool) ([]msg.Service, error)
} }
// Options are extra options that can be specified for a lookup. // Options are extra options that can be specified for a lookup.

View file

@ -37,7 +37,7 @@ type Etcd struct {
// Services implements the ServiceBackend interface. // Services implements the ServiceBackend interface.
func (e *Etcd) Services(state request.Request, exact bool, opt middleware.Options) (services, debug []msg.Service, err error) { func (e *Etcd) Services(state request.Request, exact bool, opt middleware.Options) (services, debug []msg.Service, err error) {
services, err = e.Records(state.Name(), exact) services, err = e.Records(state, exact)
if err != nil { if err != nil {
return return
} }
@ -73,7 +73,9 @@ func (e *Etcd) Debug() string {
// Records looks up records in etcd. If exact is true, it will lookup just this // Records looks up records in etcd. If exact is true, it will lookup just this
// name. This is used when find matches when completing SRV lookups for instance. // name. This is used when find matches when completing SRV lookups for instance.
func (e *Etcd) Records(name string, exact bool) ([]msg.Service, error) { func (e *Etcd) Records(state request.Request, exact bool) ([]msg.Service, error) {
name := state.Name()
path, star := msg.PathWithWildcard(name, e.PathPrefix) path, star := msg.PathWithWildcard(name, e.PathPrefix)
r, err := e.get(path, true) r, err := e.get(path, true)
if err != nil { if err != nil {

View file

@ -9,6 +9,7 @@ import (
"github.com/coredns/coredns/middleware/etcd/msg" "github.com/coredns/coredns/middleware/etcd/msg"
"github.com/coredns/coredns/middleware/proxy" "github.com/coredns/coredns/middleware/proxy"
"github.com/coredns/coredns/request"
"github.com/miekg/dns" "github.com/miekg/dns"
) )
@ -29,7 +30,11 @@ func (e *Etcd) UpdateStubZones() {
// Only the first zone configured on e is used for the lookup. // Only the first zone configured on e is used for the lookup.
func (e *Etcd) updateStubZones() { func (e *Etcd) updateStubZones() {
zone := e.Zones[0] zone := e.Zones[0]
services, err := e.Records(stubDomain+"."+zone, false)
fakeState := request.Request{W: nil, Req: new(dns.Msg)}
fakeState.Req.SetQuestion(stubDomain+"."+zone, dns.TypeA)
services, err := e.Records(fakeState, false)
if err != nil { if err != nil {
return return
} }

View file

@ -136,7 +136,7 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
return []msg.Service{svc}, nil, nil return []msg.Service{svc}, nil, nil
} }
s, e := k.Entries(state) s, e := k.Records(state, false)
// SRV for external services is not yet implemented, so remove those records. // SRV for external services is not yet implemented, so remove those records.
@ -291,13 +291,8 @@ func (k *Kubernetes) InitKubeCache() (err error) {
return err return err
} }
// Records is not implemented. // Records looks up services in kubernetes.
func (k *Kubernetes) Records(name string, exact bool) ([]msg.Service, error) { func (k *Kubernetes) Records(state request.Request, exact bool) ([]msg.Service, error) {
return nil, fmt.Errorf("not implemented")
}
// Entries looks up services in kubernetes.
func (k *Kubernetes) Entries(state request.Request) ([]msg.Service, error) {
r, e := k.parseRequest(state) r, e := k.parseRequest(state)
if e != nil { if e != nil {
return nil, e return nil, e