Dedup policy implement between grpc and proxy plugin (#3537)

Signed-off-by: zouyee <zounengren@cmss.chinamobile.com>
This commit is contained in:
Zou Nengren
2019-12-17 16:15:31 +08:00
committed by Miek Gieben
parent acb75ea904
commit 5e04c27238
7 changed files with 104 additions and 142 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/debug"
"github.com/coredns/coredns/plugin/pkg/policy"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
@@ -17,7 +18,7 @@ import (
// It has a list of proxies each representing one upstream proxy.
type GRPC struct {
proxies []*Proxy
p Policy
p policy.Policy
from string
ignored []string
@@ -93,7 +94,7 @@ func (g *GRPC) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
// NewGRPC returns a new GRPC.
func newGRPC() *GRPC {
g := &GRPC{
p: new(random),
p: new(policy.Random),
}
return g
}
@@ -126,6 +127,11 @@ func (g *GRPC) isAllowedDomain(name string) bool {
}
// List returns a set of proxies to be used for this client depending on the policy in p.
func (g *GRPC) list() []*Proxy { return g.p.List(g.proxies) }
func (g *GRPC) list() []*Proxy {
if len(g.p.List(g.proxies)) == 1 {
return g.p.List(g.proxies)[0].([]*Proxy)
}
return nil
}
const defaultTimeout = 5 * time.Second