Skip to content

Commit

Permalink
plugin/route53: remove amazon intialization from init (coredns#3348)
Browse files Browse the repository at this point in the history
Don't perform this code in the init, this allocated 1 megabyte of memory
even if you don't use the plugin. Looks to be only there for testing,
adding a comment to reflect that.

Fixes coredns#3342

Signed-off-by: Miek Gieben <miek@miek.nl>
  • Loading branch information
miekg committed Oct 3, 2019
1 parent 8fde740 commit aa96d6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
18 changes: 6 additions & 12 deletions plugin/route53/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,14 @@ import (

var log = clog.NewWithPlugin("route53")

func init() {
plugin.Register("route53",
func(c *caddy.Controller) error {
f := func(credential *credentials.Credentials) route53iface.Route53API {
return route53.New(session.Must(session.NewSession(&aws.Config{
Credentials: credential,
})))
}
return setup(c, f)
},
)
func init() { plugin.Register("route53", setup) }

// exposed for testing
var f = func(credential *credentials.Credentials) route53iface.Route53API {
return route53.New(session.Must(session.NewSession(&aws.Config{Credentials: credential})))
}

func setup(c *caddy.Controller, f func(*credentials.Credentials) route53iface.Route53API) error {
func setup(c *caddy.Controller) error {
for c.Next() {
keyPairs := map[string]struct{}{}
keys := map[string][]string{}
Expand Down
4 changes: 2 additions & 2 deletions plugin/route53/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestSetupRoute53(t *testing.T) {
f := func(credential *credentials.Credentials) route53iface.Route53API {
f = func(credential *credentials.Credentials) route53iface.Route53API {
return fakeRoute53{}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func TestSetupRoute53(t *testing.T) {

for _, test := range tests {
c := caddy.NewTestController("dns", test.body)
if err := setup(c, f); (err == nil) == test.expectedError {
if err := setup(c); (err == nil) == test.expectedError {
t.Errorf("Unexpected errors: %v", err)
}
}
Expand Down

0 comments on commit aa96d6b

Please sign in to comment.