kubernetes/migration: Add new default plugins/options (#155)

* add new defaults

* i think this works better
This commit is contained in:
Chris O'Haver 2019-04-26 10:32:53 -04:00 committed by GitHub
parent d26b5fbfcb
commit 2821bdd6c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 136 additions and 24 deletions

View file

@ -6,6 +6,7 @@ import (
type plugin struct {
status string
add serverActionFn
replacedBy string
additional string
action pluginActionFn
@ -14,6 +15,7 @@ type plugin struct {
type option struct {
status string
add pluginActionFn
replacedBy string
additional string
action optionActionFn
@ -34,6 +36,7 @@ type release struct {
defaultConf string
}
type serverActionFn func(server *corefile.Server) (*corefile.Server, error)
type pluginActionFn func(*corefile.Plugin) (*corefile.Plugin, error)
type optionActionFn func(*corefile.Option) (*corefile.Option, error)
@ -45,6 +48,36 @@ func renamePlugin(p *corefile.Plugin, to string) (*corefile.Plugin, error) {
return p, nil
}
func addToServerBlocksWithPlugins(sb *corefile.Server, newPlugin *corefile.Plugin, with []string) (*corefile.Server, error) {
if len(with) == 0 {
// add to all blocks
sb.Plugins = append(sb.Plugins, newPlugin)
return sb, nil
}
for _, p := range sb.Plugins {
for _, w := range with {
if w == p.Name {
// add to this block
sb.Plugins = append(sb.Plugins, newPlugin)
return sb, nil
}
}
}
return sb, nil
}
func addToKubernetesServerBlocks(sb *corefile.Server, newPlugin *corefile.Plugin) (*corefile.Server, error) {
return addToServerBlocksWithPlugins(sb, newPlugin, []string{"kubernetes"})
}
func addToForwardingServerBlocks(sb *corefile.Server, newPlugin *corefile.Plugin) (*corefile.Server, error) {
return addToServerBlocksWithPlugins(sb, newPlugin, []string{"forward", "proxy"})
}
func addToAllServerBlocks(sb *corefile.Server, newPlugin *corefile.Plugin) (*corefile.Server, error) {
return addToServerBlocksWithPlugins(sb, newPlugin, []string{})
}
var Versions = map[string]release{
"1.5.0": {
dockerImageID: "7987f0908caf",
@ -59,7 +92,13 @@ var Versions = map[string]release{
"class": {},
},
},
"health": {},
"health": {},
"ready": {
status: newdefault,
add: func(c *corefile.Server) (*corefile.Server, error) {
return addToKubernetesServerBlocks(c, &corefile.Plugin{Name: "ready"})
},
},
"autopath": {},
"kubernetes": {
options: map[string]option{
@ -808,7 +847,12 @@ var Versions = map[string]release{
"prefetch": {},
},
},
"loop": {},
"loop": {
status: newdefault,
add: func(s *corefile.Server) (*corefile.Server, error) {
return addToForwardingServerBlocks(s, &corefile.Plugin{Name: "loop"})
},
},
"reload": {},
"loadbalance": {},
},