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
4edd92f2
Commit
4edd92f2
authored
Aug 14, 2017
by
Ricky Pai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add HostAlias support for HostNetwork pods
parent
ceb33bde
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
8 deletions
+97
-8
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+8
-3
kubelet_pods_test.go
pkg/kubelet/kubelet_pods_test.go
+89
-5
No files found.
pkg/kubelet/kubelet_pods.go
View file @
4edd92f2
...
@@ -233,7 +233,7 @@ func ensureHostsFile(fileName, hostIP, hostName, hostDomainName string, hostAlia
...
@@ -233,7 +233,7 @@ func ensureHostsFile(fileName, hostIP, hostName, hostDomainName string, hostAlia
// if Pod is using host network, read hosts file from the node's filesystem.
// if Pod is using host network, read hosts file from the node's filesystem.
// `etcHostsPath` references the location of the hosts file on the node.
// `etcHostsPath` references the location of the hosts file on the node.
// `/etc/hosts` for *nix systems.
// `/etc/hosts` for *nix systems.
hostsFileContent
,
err
=
nodeHostsFileContent
(
etcHostsPath
)
hostsFileContent
,
err
=
nodeHostsFileContent
(
etcHostsPath
,
hostAliases
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -246,8 +246,13 @@ func ensureHostsFile(fileName, hostIP, hostName, hostDomainName string, hostAlia
...
@@ -246,8 +246,13 @@ func ensureHostsFile(fileName, hostIP, hostName, hostDomainName string, hostAlia
}
}
// nodeHostsFileContent reads the content of node's hosts file.
// nodeHostsFileContent reads the content of node's hosts file.
func
nodeHostsFileContent
(
hostsFilePath
string
)
([]
byte
,
error
)
{
func
nodeHostsFileContent
(
hostsFilePath
string
,
hostAliases
[]
v1
.
HostAlias
)
([]
byte
,
error
)
{
return
ioutil
.
ReadFile
(
hostsFilePath
)
hostsFileContent
,
err
:=
ioutil
.
ReadFile
(
hostsFilePath
)
if
err
!=
nil
{
return
nil
,
err
}
hostsFileContent
=
append
(
hostsFileContent
,
hostsEntriesFromHostAliases
(
hostAliases
)
...
)
return
hostsFileContent
,
nil
}
}
// managedHostsFileContent generates the content of the managed etc hosts based on Pod IP and other
// managedHostsFileContent generates the content of the managed etc hosts based on Pod IP and other
...
...
pkg/kubelet/kubelet_pods_test.go
View file @
4edd92f2
...
@@ -184,11 +184,23 @@ func TestMakeMounts(t *testing.T) {
...
@@ -184,11 +184,23 @@ func TestMakeMounts(t *testing.T) {
func
TestNodeHostsFileContent
(
t
*
testing
.
T
)
{
func
TestNodeHostsFileContent
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
hostsFileName
string
hostsFileName
string
expectedContent
string
hostAliases
[]
v1
.
HostAlias
rawHostsFileContent
string
expectedHostsFileContent
string
}{
}{
{
{
"hosts_test_file1"
,
"hosts_test_file1"
,
[]
v1
.
HostAlias
{},
`# hosts file for testing.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
123.45.67.89 some.domain
`
,
`# hosts file for testing.
`# hosts file for testing.
127.0.0.1 localhost
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
::1 localhost ip6-localhost ip6-loopback
...
@@ -201,6 +213,70 @@ fe00::2 ip6-allrouters
...
@@ -201,6 +213,70 @@ fe00::2 ip6-allrouters
},
},
{
{
"hosts_test_file2"
,
"hosts_test_file2"
,
[]
v1
.
HostAlias
{},
`# another hosts file for testing.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
12.34.56.78 another.domain
`
,
`# another hosts file for testing.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
12.34.56.78 another.domain
`
,
},
{
"hosts_test_file1_with_host_aliases"
,
[]
v1
.
HostAlias
{
{
IP
:
"123.45.67.89"
,
Hostnames
:
[]
string
{
"foo"
,
"bar"
,
"baz"
}},
},
`# hosts file for testing.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
123.45.67.89 some.domain
`
,
`# hosts file for testing.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
123.45.67.89 some.domain
# Entries added by HostAliases.
123.45.67.89 foo
123.45.67.89 bar
123.45.67.89 baz
`
,
},
{
"hosts_test_file2_with_host_aliases"
,
[]
v1
.
HostAlias
{
{
IP
:
"123.45.67.89"
,
Hostnames
:
[]
string
{
"foo"
,
"bar"
,
"baz"
}},
{
IP
:
"456.78.90.123"
,
Hostnames
:
[]
string
{
"park"
,
"doo"
,
"boo"
}},
},
`# another hosts file for testing.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
12.34.56.78 another.domain
`
,
`# another hosts file for testing.
`# another hosts file for testing.
127.0.0.1 localhost
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
::1 localhost ip6-localhost ip6-loopback
...
@@ -209,18 +285,26 @@ fe00::0 ip6-mcastprefix
...
@@ -209,18 +285,26 @@ fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
fe00::2 ip6-allrouters
12.34.56.78 another.domain
12.34.56.78 another.domain
# Entries added by HostAliases.
123.45.67.89 foo
123.45.67.89 bar
123.45.67.89 baz
456.78.90.123 park
456.78.90.123 doo
456.78.90.123 boo
`
,
`
,
},
},
}
}
for
_
,
testCase
:=
range
testCases
{
for
_
,
testCase
:=
range
testCases
{
tmpdir
,
err
:=
writeHostsFile
(
testCase
.
hostsFileName
,
testCase
.
expected
Content
)
tmpdir
,
err
:=
writeHostsFile
(
testCase
.
hostsFileName
,
testCase
.
rawHostsFile
Content
)
require
.
NoError
(
t
,
err
,
"could not create a temp hosts file"
)
require
.
NoError
(
t
,
err
,
"could not create a temp hosts file"
)
defer
os
.
RemoveAll
(
tmpdir
)
defer
os
.
RemoveAll
(
tmpdir
)
actualContent
,
fileReadErr
:=
nodeHostsFileContent
(
filepath
.
Join
(
tmpdir
,
testCase
.
hostsFileName
))
actualContent
,
fileReadErr
:=
nodeHostsFileContent
(
filepath
.
Join
(
tmpdir
,
testCase
.
hostsFileName
)
,
testCase
.
hostAliases
)
require
.
NoError
(
t
,
fileReadErr
,
"could not create read hosts file"
)
require
.
NoError
(
t
,
fileReadErr
,
"could not create read hosts file"
)
assert
.
Equal
(
t
,
testCase
.
expectedContent
,
string
(
actualContent
),
"hosts file content not expected"
)
assert
.
Equal
(
t
,
testCase
.
expected
HostsFile
Content
,
string
(
actualContent
),
"hosts file content not expected"
)
}
}
}
}
...
...
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