diff --git a/pkg/kubelet/network/dns/dns.go b/pkg/kubelet/network/dns/dns.go index cff577bf936..308eb102ea6 100644 --- a/pkg/kubelet/network/dns/dns.go +++ b/pkg/kubelet/network/dns/dns.go @@ -267,7 +267,10 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string, // Normalise search fields so the same domain with and without trailing dot will only count once, to avoid hitting search validation limits. searches = []string{} for _, s := range fields[1:] { - searches = append(searches, strings.TrimSuffix(s, ".")) + if s != "." { + s = strings.TrimSuffix(s, ".") + } + searches = append(searches, s) } } if fields[0] == "options" { diff --git a/pkg/kubelet/network/dns/dns_test.go b/pkg/kubelet/network/dns/dns_test.go index bd634b02af1..261de55c9b4 100644 --- a/pkg/kubelet/network/dns/dns_test.go +++ b/pkg/kubelet/network/dns/dns_test.go @@ -78,6 +78,7 @@ func TestParseResolvConf(t *testing.T) { {"nameserver 1.2.3.4\nnameserver 5.6.7.8", []string{"1.2.3.4", "5.6.7.8"}, []string{}, []string{}, false}, {"nameserver 1.2.3.4 #comment", []string{"1.2.3.4"}, []string{}, []string{}, false}, {"search ", []string{}, []string{}, []string{}, false}, // search empty + {"search .", []string{}, []string{"."}, []string{}, false}, {"search foo", []string{}, []string{"foo"}, []string{}, false}, {"search foo bar", []string{}, []string{"foo", "bar"}, []string{}, false}, {"search foo. bar", []string{}, []string{"foo", "bar"}, []string{}, false},