feat: enable plugins via environment during build (#7310)

* feat: enable plugins via environment during build

Signed-off-by: Colden Cullen <colden@coldencullen.com>

* doc: add note about COREDNS_PLUGINS

Signed-off-by: Colden Cullen <colden@coldencullen.com>

---------

Signed-off-by: Colden Cullen <colden@coldencullen.com>
This commit is contained in:
Colden Cullen 2025-05-20 21:02:52 -07:00 committed by GitHub
parent 1de92ec9dc
commit 82323554ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 16 deletions

View File

@ -67,6 +67,8 @@ $ cd coredns
$ make
~~~
> **_NOTE:_** extra plugins may be enabled when building by setting the `COREDNS_PLUGINS` environment variable with comma separate list of plugins in the same format as plugin.cfg
This should yield a `coredns` binary.
## Compilation with Docker

View File

@ -14,6 +14,26 @@ func main() {
mi := make(map[string]string, 0)
md := []string{}
parsePlugin := func(element string) {
items := strings.Split(element, ":")
if len(items) != 2 {
// ignore empty lines
return
}
name, repo := items[0], items[1]
if _, ok := mi[name]; ok {
log.Fatalf("Duplicate entry %q", name)
}
md = append(md, name)
mi[name] = pluginPath + repo // Default, unless overridden by 3rd arg
if _, err := os.Stat(pluginFSPath + repo); err != nil { // External package has been given
mi[name] = repo
}
}
file, err := os.Open(pluginFile)
if err != nil {
log.Fatalf("Failed to open %s: %q", pluginFile, err)
@ -28,23 +48,11 @@ func main() {
continue
}
items := strings.Split(line, ":")
if len(items) != 2 {
// ignore empty lines
continue
}
name, repo := items[0], items[1]
if _, ok := mi[name]; ok {
log.Fatalf("Duplicate entry %q", name)
parsePlugin(line)
}
md = append(md, name)
mi[name] = pluginPath + repo // Default, unless overridden by 3rd arg
if _, err := os.Stat(pluginFSPath + repo); err != nil { // External package has been given
mi[name] = repo
}
for _, element := range strings.Split(os.Getenv("COREDNS_PLUGINS"), ",") {
parsePlugin(element)
}
genImports("core/plugin/zplugin.go", "plugin", mi)