Enhancement of external plugin enabling (#1392)
This fix is an enhancement of external plugin enabling. Previously, it was already able to build a customerized coredns with plugins enabled selectively, without changing coredns source code. However, all default plugins are actually bundled because of the import rule: ``` "github.com/coredns/coredns/coremain" ``` The issue is best described with the following: ``` root@localhost:/go/src/github.com/coredns/coredns/sample# cat sample.go package main import ( _ "github.com/coredns/forward" "github.com/coredns/coredns/coremain" "github.com/coredns/coredns/core/dnsserver" ) var directives = []string{ "forward", "startup", "shutdown", } func init() { dnsserver.Directives = directives } func main() { coremain.Run() } root@localhost:/go/src/github.com/coredns/coredns/sample# root@localhost:/go/src/github.com/coredns/coredns/sample# go build -v sample.go root@localhost:/go/src/github.com/coredns/coredns/sample# ./sample -plugins root@localhost:/go/src/github.com/coredns/coredns/sample# ./sample -plugins Server types: dns Caddyfile loaders: flag default Other plugins: dns.auto dns.autopath dns.bind dns.cache dns.chaos dns.debug dns.dnssec dns.dnstap dns.erratic dns.errors dns.etcd dns.federation dns.file dns.forward dns.health dns.hosts dns.kubernetes dns.loadbalance dns.log dns.nsid dns.pprof dns.prometheus dns.proxy dns.reverse dns.rewrite dns.root dns.route53 dns.secondary dns.template .... ``` This fix moves zplugins.go to a different package/directory so that it is possible to "only import plugins as needed". The following is the new output after this fix: ``` root@localhost:/go/src/github.com/coredns/coredns/sample# ./sample -plugins Server types: dns Caddyfile loaders: flag default Other plugins: dns.forward dns.prometheus shutdown startup root@localhost:/go/src/github.com/coredns/coredns/sample# ``` Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
584dd87c70
commit
9d87b953a0
5 changed files with 11 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
// generated by directives_generate.go; DO NOT EDIT
|
// generated by directives_generate.go; DO NOT EDIT
|
||||||
|
|
||||||
package core
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// Include all plugins.
|
// Include all plugins.
|
|
@ -2,7 +2,12 @@ package main
|
||||||
|
|
||||||
//go:generate go run directives_generate.go
|
//go:generate go run directives_generate.go
|
||||||
|
|
||||||
import "github.com/coredns/coredns/coremain"
|
import (
|
||||||
|
"github.com/coredns/coredns/coremain"
|
||||||
|
|
||||||
|
// Plug in CoreDNS
|
||||||
|
_ "github.com/coredns/coredns/core/plugin"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
coremain.Run()
|
coremain.Run()
|
||||||
|
|
|
@ -15,9 +15,6 @@ import (
|
||||||
"github.com/mholt/caddy"
|
"github.com/mholt/caddy"
|
||||||
|
|
||||||
"github.com/coredns/coredns/core/dnsserver"
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
|
|
||||||
// Plug in CoreDNS
|
|
||||||
_ "github.com/coredns/coredns/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -48,7 +48,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
genImports("core/zplugin.go", "core", mi)
|
genImports("core/plugin/zplugin.go", "plugin", mi)
|
||||||
genDirectives("core/dnsserver/zdirectives.go", "dnsserver", md)
|
genDirectives("core/dnsserver/zdirectives.go", "dnsserver", md)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ import (
|
||||||
"github.com/coredns/coredns/plugin/test"
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
|
// Load all managed plugins in github.com/coredns/coredns
|
||||||
|
_ "github.com/coredns/coredns/core/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func benchmarkLookupBalanceRewriteCache(b *testing.B) {
|
func benchmarkLookupBalanceRewriteCache(b *testing.B) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue