mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 00:04:15 -04:00
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:
@@ -50,6 +50,10 @@ type Config struct {
|
||||
// on them should register themselves here. The name should be the name as return by the
|
||||
// Handler's Name method.
|
||||
registry map[string]plugin.Handler
|
||||
|
||||
// firstConfigInBlock is used to reference the first config in a server block, for the
|
||||
// purpose of sharing single instance of each plugin among all zones in a server block.
|
||||
firstConfigInBlock *Config
|
||||
}
|
||||
|
||||
// keyForConfig builds a key for identifying the configs during setup time
|
||||
|
||||
@@ -108,6 +108,8 @@ func (h *dnsContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
|
||||
|
||||
serverBlocks[ib].Keys = s.Keys // important to save back the new keys that are potentially created here.
|
||||
|
||||
var firstConfigInBlock *Config
|
||||
|
||||
for ik := range s.Keys {
|
||||
za := zoneAddrs[ik]
|
||||
s.Keys[ik] = za.String()
|
||||
@@ -118,6 +120,15 @@ func (h *dnsContext) InspectServerBlocks(sourceFile string, serverBlocks []caddy
|
||||
Port: za.Port,
|
||||
Transport: za.Transport,
|
||||
}
|
||||
|
||||
// Set reference to the first config in the current block.
|
||||
// This is used later by MakeServers to share a single plugin list
|
||||
// for all zones in a server block.
|
||||
if ik == 0 {
|
||||
firstConfigInBlock = cfg
|
||||
}
|
||||
cfg.firstConfigInBlock = firstConfigInBlock
|
||||
|
||||
keyConfig := keyForConfig(ib, ik)
|
||||
h.saveConfig(keyConfig, cfg)
|
||||
}
|
||||
@@ -135,6 +146,17 @@ func (h *dnsContext) MakeServers() ([]caddy.Server, error) {
|
||||
return nil, errValid
|
||||
}
|
||||
|
||||
// Copy the Plugin, ListenHosts and Debug from first config in the block
|
||||
// to all other config in the same block . Doing this results in zones
|
||||
// sharing the same plugin instances and settings as other zones in
|
||||
// the same block.
|
||||
for _, c := range h.configs {
|
||||
c.Plugin = c.firstConfigInBlock.Plugin
|
||||
c.ListenHosts = c.firstConfigInBlock.ListenHosts
|
||||
c.Debug = c.firstConfigInBlock.Debug
|
||||
c.TLSConfig = c.firstConfigInBlock.TLSConfig
|
||||
}
|
||||
|
||||
// we must map (group) each config to a bind address
|
||||
groups, err := groupConfigsByListenAddr(h.configs)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user