Skip to content

Commit

Permalink
Fix/support coredns 1.11.3 (#1)
Browse files Browse the repository at this point in the history
* Support CoreDNS 1.11.3 version

Signed-off-by: Gleb Kogtev <[email protected]>
Signed-off-by: glebkin <[email protected]>
  • Loading branch information
glebkin committed Jul 23, 2024
1 parent ebe17d8 commit 49ca311
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/networkservicemesh/fanout

go 1.17
go 1.21

require (
github.com/coredns/caddy v1.1.1
Expand Down
29 changes: 22 additions & 7 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package fanout

import (
"io/ioutil"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -58,8 +59,8 @@ func setup(c *caddy.Controller) error {

c.OnStartup(func() error {
if taph := dnsserver.GetConfig(c).Handler("dnstap"); taph != nil {
if tapPlugin, ok := taph.(dnstap.Dnstap); ok {
f.tapPlugin = &tapPlugin
if tapPlugin, ok := taph.(*dnstap.Dnstap); ok {
f.tapPlugin = tapPlugin
}
}
return f.OnStartup()
Expand Down Expand Up @@ -104,7 +105,13 @@ func parsefanoutStanza(c *caddyfile.Dispenser) (*Fanout, error) {
if !c.Args(&f.from) {
return f, c.ArgErr()
}
f.from = plugin.Host(f.from).Normalize()

normalized := plugin.Host(f.from).NormalizeExact()
if len(normalized) == 0 {
return nil, fmt.Errorf("unable to normalize '%s'", f.from)
}

f.from = normalized[0]
to := c.RemainingArgs()
if len(to) == 0 {
return f, c.ArgErr()
Expand Down Expand Up @@ -199,13 +206,17 @@ func parseIgnoredFromFile(f *Fanout, c *caddyfile.Dispenser) error {
if len(args) != 1 {
return c.ArgErr()
}
b, err := ioutil.ReadFile(filepath.Clean(args[0]))
b, err := os.ReadFile(filepath.Clean(args[0]))
if err != nil {
return err
}
names := strings.Split(string(b), "\n")
for i := 0; i < len(names); i++ {
f.excludeDomains.AddString(plugin.Host(names[i]).Normalize())
normalized := plugin.Host(names[i]).NormalizeExact()
if len(normalized) == 0 {
return fmt.Errorf("unable to normalize '%s'", names[i])
}
f.excludeDomains.AddString(normalized[0])
}
return nil
}
Expand All @@ -216,7 +227,11 @@ func parseIgnored(f *Fanout, c *caddyfile.Dispenser) error {
return c.ArgErr()
}
for i := 0; i < len(ignore); i++ {
f.excludeDomains.AddString(plugin.Host(ignore[i]).Normalize())
normalized := plugin.Host(ignore[i]).NormalizeExact()
if len(normalized) == 0 {
return fmt.Errorf("unable to normalize '%s'", ignore[i])
}
f.excludeDomains.AddString(normalized[0])
}
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package fanout

import (
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -48,8 +47,10 @@ func TestSetup(t *testing.T) {

// negative
{input: "fanout . aaa", expectedErr: "not an IP address or file"},
{input: "fanout .: aaa", expectedErr: "unable to normalize '.:'"},
{input: "fanout . 127.0.0.1 {\nexcept a b\nworker-count 1\n}", expectedErr: "use Forward plugin"},
{input: "fanout . 127.0.0.1 {\nexcept a b\nworker-count ten\n}", expectedErr: "'ten'"},
{input: "fanout . 127.0.0.1 {\nexcept a:\nworker-count ten\n}", expectedErr: "unable to normalize 'a:'"},
{input: "fanout . 127.0.0.1 127.0.0.2 {\nnetwork XXX\n}", expectedErr: "unknown network protocol"},
}

Expand Down Expand Up @@ -102,7 +103,7 @@ func TestSetup(t *testing.T) {

func TestSetupResolvconf(t *testing.T) {
const resolv = "resolv.conf"
if err := ioutil.WriteFile(resolv,
if err := os.WriteFile(resolv,
[]byte(`nameserver 10.10.255.252
nameserver 10.10.255.253`), 0600); err != nil {
t.Fatalf("Failed to write resolv.conf file: %s", err)
Expand Down

0 comments on commit 49ca311

Please sign in to comment.