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
This commit is contained in:
Dalton Hubble 2022-08-31 11:05:19 -07:00
parent d0e413e86d
commit 7850097fd0
2 changed files with 7 additions and 5 deletions

View File

@ -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" {

View File

@ -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},