Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a3e30269
Unverified
Commit
a3e30269
authored
Sep 25, 2018
by
k8s-ci-robot
Committed by
GitHub
Sep 25, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #68116 from krmayankk/read-dns-code
add validation for etc resolve parsing
parents
5401f945
ef976f1f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
33 deletions
+48
-33
BUILD
pkg/kubelet/network/dns/BUILD
+1
-0
dns.go
pkg/kubelet/network/dns/dns.go
+9
-3
dns_test.go
pkg/kubelet/network/dns/dns_test.go
+38
-30
No files found.
pkg/kubelet/network/dns/BUILD
View file @
a3e30269
...
@@ -12,6 +12,7 @@ go_library(
...
@@ -12,6 +12,7 @@ go_library(
"//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/container:go_default_library",
"//pkg/kubelet/util/format:go_default_library",
"//pkg/kubelet/util/format:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/client-go/tools/record:go_default_library",
"//staging/src/k8s.io/client-go/tools/record:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
...
...
pkg/kubelet/network/dns/dns.go
View file @
a3e30269
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"strings"
"strings"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
utilerrors
"k8s.io/apimachinery/pkg/util/errors"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/apis/core/validation"
"k8s.io/kubernetes/pkg/apis/core/validation"
...
@@ -209,6 +210,7 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
...
@@ -209,6 +210,7 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
// Each option is recorded as an element in the array.
// Each option is recorded as an element in the array.
options
=
[]
string
{}
options
=
[]
string
{}
var
allErrors
[]
error
lines
:=
strings
.
Split
(
string
(
file
),
"
\n
"
)
lines
:=
strings
.
Split
(
string
(
file
),
"
\n
"
)
for
l
:=
range
lines
{
for
l
:=
range
lines
{
trimmed
:=
strings
.
TrimSpace
(
lines
[
l
])
trimmed
:=
strings
.
TrimSpace
(
lines
[
l
])
...
@@ -219,8 +221,12 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
...
@@ -219,8 +221,12 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
if
len
(
fields
)
==
0
{
if
len
(
fields
)
==
0
{
continue
continue
}
}
if
fields
[
0
]
==
"nameserver"
&&
len
(
fields
)
>=
2
{
if
fields
[
0
]
==
"nameserver"
{
nameservers
=
append
(
nameservers
,
fields
[
1
])
if
len
(
fields
)
>=
2
{
nameservers
=
append
(
nameservers
,
fields
[
1
])
}
else
{
allErrors
=
append
(
allErrors
,
fmt
.
Errorf
(
"nameserver list is empty "
))
}
}
}
if
fields
[
0
]
==
"search"
{
if
fields
[
0
]
==
"search"
{
searches
=
fields
[
1
:
]
searches
=
fields
[
1
:
]
...
@@ -230,7 +236,7 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
...
@@ -230,7 +236,7 @@ func parseResolvConf(reader io.Reader) (nameservers []string, searches []string,
}
}
}
}
return
nameservers
,
searches
,
options
,
nil
return
nameservers
,
searches
,
options
,
utilerrors
.
NewAggregate
(
allErrors
)
}
}
func
(
c
*
Configurer
)
getHostDNSConfig
(
pod
*
v1
.
Pod
)
(
*
runtimeapi
.
DNSConfig
,
error
)
{
func
(
c
*
Configurer
)
getHostDNSConfig
(
pod
*
v1
.
Pod
)
(
*
runtimeapi
.
DNSConfig
,
error
)
{
...
...
pkg/kubelet/network/dns/dns_test.go
View file @
a3e30269
...
@@ -53,40 +53,48 @@ func TestParseResolvConf(t *testing.T) {
...
@@ -53,40 +53,48 @@ func TestParseResolvConf(t *testing.T) {
nameservers
[]
string
nameservers
[]
string
searches
[]
string
searches
[]
string
options
[]
string
options
[]
string
isErr
bool
}{
}{
{
""
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
""
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
{
" "
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
" "
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
{
"
\n
"
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
"
\n
"
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
{
"
\t\n\t
"
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
"
\t\n\t
"
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
{
"#comment
\n
"
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
"#comment
\n
"
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
{
" #comment
\n
"
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
" #comment
\n
"
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
{
"#comment
\n
#comment"
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
"#comment
\n
#comment"
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
{
"#comment
\n
nameserver"
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
"#comment
\n
nameserver"
,
[]
string
{},
[]
string
{},
[]
string
{},
true
},
// nameserver empty
{
"#comment
\n
nameserver
\n
search"
,
[]
string
{},
[]
string
{},
[]
string
{}},
{
"#comment
\n
nameserver
\n
search"
,
[]
string
{},
[]
string
{},
[]
string
{},
true
},
// nameserver and search empty
{
"nameserver 1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{}},
{
"#comment
\n
nameserver 1.2.3.4
\n
search"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{},
false
},
// nameserver specified and search empty
{
" nameserver 1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{}},
{
"nameserver 1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{},
false
},
{
"
\t
nameserver 1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{}},
{
" nameserver 1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{},
false
},
{
"nameserver
\t
1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{}},
{
"
\t
nameserver 1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{},
false
},
{
"nameserver
\t
1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{}},
{
"nameserver
\t
1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{},
false
},
{
"nameserver 1.2.3.4
\n
nameserver 5.6.7.8"
,
[]
string
{
"1.2.3.4"
,
"5.6.7.8"
},
[]
string
{},
[]
string
{}},
{
"nameserver
\t
1.2.3.4"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{},
false
},
{
"nameserver 1.2.3.4 #comment"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{}},
{
"nameserver 1.2.3.4
\n
nameserver 5.6.7.8"
,
[]
string
{
"1.2.3.4"
,
"5.6.7.8"
},
[]
string
{},
[]
string
{},
false
},
{
"search foo"
,
[]
string
{},
[]
string
{
"foo"
},
[]
string
{}},
{
"nameserver 1.2.3.4 #comment"
,
[]
string
{
"1.2.3.4"
},
[]
string
{},
[]
string
{},
false
},
{
"search foo bar"
,
[]
string
{},
[]
string
{
"foo"
,
"bar"
},
[]
string
{}},
{
"search "
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
// search empty
{
"search foo bar bat
\n
"
,
[]
string
{},
[]
string
{
"foo"
,
"bar"
,
"bat"
},
[]
string
{}},
{
"search foo"
,
[]
string
{},
[]
string
{
"foo"
},
[]
string
{},
false
},
{
"search foo
\n
search bar"
,
[]
string
{},
[]
string
{
"bar"
},
[]
string
{}},
{
"search foo bar"
,
[]
string
{},
[]
string
{
"foo"
,
"bar"
},
[]
string
{},
false
},
{
"nameserver 1.2.3.4
\n
search foo bar"
,
[]
string
{
"1.2.3.4"
},
[]
string
{
"foo"
,
"bar"
},
[]
string
{}},
{
"search foo bar bat
\n
"
,
[]
string
{},
[]
string
{
"foo"
,
"bar"
,
"bat"
},
[]
string
{},
false
},
{
"nameserver 1.2.3.4
\n
search foo
\n
nameserver 5.6.7.8
\n
search bar"
,
[]
string
{
"1.2.3.4"
,
"5.6.7.8"
},
[]
string
{
"bar"
},
[]
string
{}},
{
"search foo
\n
search bar"
,
[]
string
{},
[]
string
{
"bar"
},
[]
string
{},
false
},
{
"#comment
\n
nameserver 1.2.3.4
\n
#comment
\n
search foo
\n
comment"
,
[]
string
{
"1.2.3.4"
},
[]
string
{
"foo"
},
[]
string
{}},
{
"nameserver 1.2.3.4
\n
search foo bar"
,
[]
string
{
"1.2.3.4"
},
[]
string
{
"foo"
,
"bar"
},
[]
string
{},
false
},
{
"options ndots:5 attempts:2"
,
[]
string
{},
[]
string
{},
[]
string
{
"ndots:5"
,
"attempts:2"
}},
{
"nameserver 1.2.3.4
\n
search foo
\n
nameserver 5.6.7.8
\n
search bar"
,
[]
string
{
"1.2.3.4"
,
"5.6.7.8"
},
[]
string
{
"bar"
},
[]
string
{},
false
},
{
"options ndots:1
\n
options ndots:5 attempts:3"
,
[]
string
{},
[]
string
{},
[]
string
{
"ndots:5"
,
"attempts:3"
}},
{
"#comment
\n
nameserver 1.2.3.4
\n
#comment
\n
search foo
\n
comment"
,
[]
string
{
"1.2.3.4"
},
[]
string
{
"foo"
},
[]
string
{},
false
},
{
"nameserver 1.2.3.4
\n
search foo
\n
nameserver 5.6.7.8
\n
search bar
\n
options ndots:5 attempts:4"
,
[]
string
{
"1.2.3.4"
,
"5.6.7.8"
},
[]
string
{
"bar"
},
[]
string
{
"ndots:5"
,
"attempts:4"
}},
{
"options "
,
[]
string
{},
[]
string
{},
[]
string
{},
false
},
{
"options ndots:5 attempts:2"
,
[]
string
{},
[]
string
{},
[]
string
{
"ndots:5"
,
"attempts:2"
},
false
},
{
"options ndots:1
\n
options ndots:5 attempts:3"
,
[]
string
{},
[]
string
{},
[]
string
{
"ndots:5"
,
"attempts:3"
},
false
},
{
"nameserver 1.2.3.4
\n
search foo
\n
nameserver 5.6.7.8
\n
search bar
\n
options ndots:5 attempts:4"
,
[]
string
{
"1.2.3.4"
,
"5.6.7.8"
},
[]
string
{
"bar"
},
[]
string
{
"ndots:5"
,
"attempts:4"
},
false
},
}
}
for
i
,
tc
:=
range
testCases
{
for
i
,
tc
:=
range
testCases
{
ns
,
srch
,
opts
,
err
:=
parseResolvConf
(
strings
.
NewReader
(
tc
.
data
))
ns
,
srch
,
opts
,
err
:=
parseResolvConf
(
strings
.
NewReader
(
tc
.
data
))
require
.
NoError
(
t
,
err
)
if
!
tc
.
isErr
{
assert
.
EqualValues
(
t
,
tc
.
nameservers
,
ns
,
"test case [%d]: name servers"
,
i
)
require
.
NoError
(
t
,
err
)
assert
.
EqualValues
(
t
,
tc
.
searches
,
srch
,
"test case [%d] searches"
,
i
)
assert
.
EqualValues
(
t
,
tc
.
nameservers
,
ns
,
"test case [%d]: name servers"
,
i
)
assert
.
EqualValues
(
t
,
tc
.
options
,
opts
,
"test case [%d] options"
,
i
)
assert
.
EqualValues
(
t
,
tc
.
searches
,
srch
,
"test case [%d] searches"
,
i
)
assert
.
EqualValues
(
t
,
tc
.
options
,
opts
,
"test case [%d] options"
,
i
)
}
else
{
require
.
Error
(
t
,
err
,
"tc.searches %v"
,
tc
.
searches
)
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment