Added CoreDNS plugin setup and replaced forward

This commit is contained in:
Andrey Meshkov
2018-11-05 23:49:31 +03:00
parent 9bc4bf66ed
commit efdd1c1ff2
8 changed files with 137 additions and 25 deletions

View File

@@ -5,8 +5,6 @@ import (
"github.com/miekg/dns"
"github.com/pkg/errors"
"golang.org/x/net/context"
"log"
"runtime"
"time"
)
@@ -14,8 +12,6 @@ const (
defaultTimeout = 5 * time.Second
)
// TODO: Add a helper method for health-checking an upstream (see health.go in coredns)
// Upstream is a simplified interface for proxy destination
type Upstream interface {
Exchange(ctx context.Context, query *dns.Msg) (*dns.Msg, error)
@@ -30,10 +26,10 @@ type UpstreamPlugin struct {
// Initialize the upstream plugin
func New() *UpstreamPlugin {
p := &UpstreamPlugin{}
p := &UpstreamPlugin{
Upstreams: []Upstream{},
}
// Make sure all resources are cleaned up
runtime.SetFinalizer(p, (*UpstreamPlugin).finalizer)
return p
}
@@ -56,15 +52,3 @@ func (p *UpstreamPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *
// Name implements interface for CoreDNS plugin
func (p *UpstreamPlugin) Name() string { return "upstream" }
func (p *UpstreamPlugin) finalizer() {
for i := range p.Upstreams {
u := p.Upstreams[i]
err := u.Close()
if err != nil {
log.Printf("Error while closing the upstream: %s", err)
}
}
}