Skip to content

Commit

Permalink
Add --no-resolv when upstream nameservers are specified
Browse files Browse the repository at this point in the history
  • Loading branch information
bowei committed Feb 17, 2017
1 parent 6fa0e65 commit f7c5537
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pkg/dnsmasq/nanny.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ func (n *Nanny) Configure(args []string, config *config.Config) {
server = munge(server)
n.args = append(n.args, "--server", server)
}

// If upstream nameservers are explicitly specified, then do not look
// at /etc/resolv.conf.
if len(config.UpstreamNameservers) > 0 {
n.args = append(n.args, "--no-resolv")
}
}

// Start the nanny.
Expand Down
9 changes: 5 additions & 4 deletions pkg/dnsmasq/nanny_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ func TestNannyConfig(t *testing.T) {
e []string
sort bool
}{
{c: &config.Config{}, e: []string{"--no-resolv"}},
{c: &config.Config{}, e: []string{"--abc"}},
{
c: &config.Config{
StubDomains: map[string][]string{
"acme.local": []string{"1.1.1.1"},
"widget.local": []string{"2.2.2.2:10053", "3.3.3.3"},
}},
e: []string{
"--no-resolv",
"--abc",
"--server",
"--server",
"--server",
Expand All @@ -84,16 +84,17 @@ func TestNannyConfig(t *testing.T) {
c: &config.Config{
UpstreamNameservers: []string{"2.2.2.2:10053", "3.3.3.3"}},
e: []string{
"--no-resolv",
"--abc",
"--server",
"2.2.2.2#10053",
"--server",
"3.3.3.3",
"--no-resolv",
},
},
} {
nanny := &Nanny{Exec: "dnsmasq"}
nanny.Configure([]string{"--no-resolv"}, testCase.c)
nanny.Configure([]string{"--abc"}, testCase.c)
if testCase.sort {
sort.Sort(sort.StringSlice(nanny.args))
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/dnsmasq/nanny.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var _ = Describe("dnsmasq-nanny", func() {

By("Updating dnsmasq via a configuration change 2")
harness.Configure(``, `["5.6.7.8"]`)
harness.WaitForArgs(prefix + " --server 5.6.7.8")
harness.WaitForArgs(prefix + " --server 5.6.7.8 --no-resolv")

By("Updating dnsmasq to invalid change (ignored)")
harness.Configure(`$$$$asdf`, ``)
Expand Down

0 comments on commit f7c5537

Please sign in to comment.