Merge pull request #112157 from dghubble/master

Avoid propagating "search ." into containers /etc/resolv.conf
This commit is contained in:
Kubernetes Prow Robot 2022-09-02 05:48:05 -07:00 committed by GitHub
commit ca09ed0fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -25,7 +25,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
utilvalidation "k8s.io/apimachinery/pkg/util/validation" utilvalidation "k8s.io/apimachinery/pkg/util/validation"
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
@ -268,9 +268,8 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
searches = []string{} searches = []string{}
for _, s := range fields[1:] { for _, s := range fields[1:] {
if s != "." { if s != "." {
s = strings.TrimSuffix(s, ".") searches = append(searches, strings.TrimSuffix(s, "."))
} }
searches = append(searches, s)
} }
} }
if fields[0] == "options" { if fields[0] == "options" {

View File

@ -78,7 +78,10 @@ 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\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}, {"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 empty
{"search .", []string{}, []string{"."}, []string{}, false}, {"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", []string{}, []string{"foo"}, []string{}, false},
{"search foo bar", []string{}, []string{"foo", "bar"}, []string{}, false}, {"search foo bar", []string{}, []string{"foo", "bar"}, []string{}, false},
{"search foo. bar", []string{}, []string{"foo", "bar"}, []string{}, false}, {"search foo. bar", []string{}, []string{"foo", "bar"}, []string{}, false},