From 7850097fd020cebb31e5e1e4feaf161254ec0379 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Wed, 31 Aug 2022 11:05:19 -0700 Subject: [PATCH] Avoid propagating `search .` into containers /etc/resolv.conf * Adapt https://github.com/kubernetes/kubernetes/pull/109441 but ensures that `search .` does not get propagated into containers' /etc/resolv.conf. There is no reason to put `.` in a container's search field and it causes issues for musl --- pkg/kubelet/network/dns/dns.go | 5 ++--- pkg/kubelet/network/dns/dns_test.go | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/kubelet/network/dns/dns.go b/pkg/kubelet/network/dns/dns.go index 308eb102ea6..6781db7a4fd 100644 --- a/pkg/kubelet/network/dns/dns.go +++ b/pkg/kubelet/network/dns/dns.go @@ -25,7 +25,7 @@ import ( "path/filepath" "strings" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" utilerrors "k8s.io/apimachinery/pkg/util/errors" utilvalidation "k8s.io/apimachinery/pkg/util/validation" utilfeature "k8s.io/apiserver/pkg/util/feature" @@ -268,9 +268,8 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string, searches = []string{} for _, s := range fields[1:] { if s != "." { - s = strings.TrimSuffix(s, ".") + searches = append(searches, 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 261de55c9b4..f4d0561d373 100644 --- a/pkg/kubelet/network/dns/dns_test.go +++ b/pkg/kubelet/network/dns/dns_test.go @@ -77,8 +77,11 @@ func TestParseResolvConf(t *testing.T) { {"nameserver \t 1.2.3.4", []string{"1.2.3.4"}, []string{}, []string{}, false}, {"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 ", []string{}, []string{}, []string{}, false}, // search empty + {"search .", []string{}, []string{}, []string{}, false}, // ignore lone dot + {"search . foo", []string{}, []string{"foo"}, []string{}, false}, + {"search foo .", []string{}, []string{"foo"}, []string{}, false}, + {"search foo . bar", []string{}, []string{"foo", "bar"}, []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},