Skip to content

Commit

Permalink
Move each search dns to its own line
Browse files Browse the repository at this point in the history
Alpine does not seem to use search correctly when there are multiple
search domains on the same line. It only uses the first with the advent.
When podman runs within a separate network we are appending on
dns.podman as a search, if you add a search domain, then this causes the
local search on network to fail.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Feb 2, 2022
1 parent 4ddc4e7 commit a1bc8cb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
10 changes: 4 additions & 6 deletions cmd/podman/common/netflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
opts = &entities.NetOptions{}
}

if flags.Changed("add-hosts") {
if flags.Changed("add-host") {
opts.AddHosts, err = flags.GetStringSlice("add-host")
if err != nil {
return nil, err
Expand Down Expand Up @@ -178,11 +178,9 @@ func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*enti
}
}

if flags.Changed("no-host") {
opts.NoHosts, err = flags.GetBool("no-hosts")
if err != nil {
return nil, err
}
opts.NoHosts, err = flags.GetBool("no-hosts")
if err != nil {
return nil, err
}

// parse the network only when network was changed
Expand Down
8 changes: 3 additions & 5 deletions pkg/resolvconf/resolvconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,9 @@ func GetOptions(resolvConf []byte) []string {
// dnsSearch, and an "options" entry for every element in dnsOptions.
func Build(path string, dns, dnsSearch, dnsOptions []string) (*File, error) {
content := bytes.NewBuffer(nil)
if len(dnsSearch) > 0 {
if searchString := strings.Join(dnsSearch, " "); strings.Trim(searchString, " ") != "." {
if _, err := content.WriteString("search " + searchString + "\n"); err != nil {
return nil, err
}
for _, search := range dnsSearch {
if _, err := content.WriteString("search " + search + "\n"); err != nil {
return nil, err
}
}
for _, dns := range dns {
Expand Down
7 changes: 6 additions & 1 deletion test/system/500-networking.bats
Original file line number Diff line number Diff line change
Expand Up @@ -597,17 +597,22 @@ load helpers
searchIP="100.100.100.100"
cat >$containersconf <<EOF
[containers]
dns_searches = [ "example.com"]
dns_searches = [ "example.com", "test1.com"]
dns_servers = [
"1.1.1.1",
"$searchIP",
"1.0.0.1",
"8.8.8.8",
]
EOF
export searchDNS="search example.com
search test1.com
search a.b"
CONTAINERS_CONF=$containersconf run_podman run --rm $IMAGE grep "example.com" /etc/resolv.conf
CONTAINERS_CONF=$containersconf run_podman run --rm $IMAGE grep $searchIP /etc/resolv.conf
is "$output" "nameserver $searchIP" "Should only be one $searchIP not multiple"
CONTAINERS_CONF=$containersconf run_podman run --dns-search a.b --rm $IMAGE grep search /etc/resolv.conf
is "$output" "$searchDNS" "Searches should be on different lines"
}

# vim: filetype=sh

0 comments on commit a1bc8cb

Please sign in to comment.