Share plugins among zones in the same server block (#4593)

* share plugins among zones in the same server block

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* update caddy dep

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* simp code

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* copy ListenHosts and Debug from first config

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* copy tls configs from first config

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* add test to validate debug setting is replicated to all configs in block

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>

* stop server

Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
Chris O'Haver 2021-07-09 11:12:06 -04:00 committed by GitHub
parent 2a61309cad
commit bdaa2a5527
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 3 deletions

View file

@ -1,7 +1,11 @@
package test
import (
"reflect"
"testing"
"unsafe"
"github.com/coredns/coredns/core/dnsserver"
"github.com/miekg/dns"
)
@ -107,3 +111,30 @@ func TestReverseExpansion(t *testing.T) {
t.Errorf("Expected 0 RRs in additional section, got %d", len(r.Extra))
}
}
func TestMultiZoneBlockConfigs(t *testing.T) {
corefile := `.:40000 .:40001 .:40002 {
debug
}`
server, err := CoreDNSServer(corefile)
defer server.Stop()
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
// unsafe reflection to read unexported fields "context" and "configs" within context
ctxVal := reflect.ValueOf(server).Elem().FieldByName("context")
ctxVal2 := reflect.NewAt(ctxVal.Type(), unsafe.Pointer(ctxVal.UnsafeAddr())).Elem()
configs := reflect.ValueOf(ctxVal2.Interface()).Elem().FieldByName("configs")
configs2 := reflect.NewAt(configs.Type(), unsafe.Pointer(configs.UnsafeAddr())).Elem()
for i := 0; i < 3; i++ {
v := configs2.Index(i)
config := v.Interface().(*dnsserver.Config)
if !config.Debug {
t.Fatalf("Debug was not set for %s://%s:%s", config.Transport, config.Zone, config.Port)
}
}
}