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
25786aca
Commit
25786aca
authored
Sep 06, 2016
by
Yifan Gu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rkt: Refactor host file mounts for host network.
Do not mount /etc/hosts/ /etc/resolv.conf if they are already mounted.
parent
9dfe8df7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
17 deletions
+38
-17
pod
examples/pod
+3
-0
rkt.go
pkg/kubelet/rkt/rkt.go
+35
-17
No files found.
examples/pod
View file @
25786aca
...
@@ -6,6 +6,9 @@ metadata:
...
@@ -6,6 +6,9 @@ metadata:
labels:
labels:
name: nginx
name: nginx
spec:
spec:
initcontainers:
name: busybox
image: busybox
containers:
containers:
- name: nginx
- name: nginx
image: nginx
image: nginx
...
...
pkg/kubelet/rkt/rkt.go
View file @
25786aca
...
@@ -133,6 +133,9 @@ const (
...
@@ -133,6 +133,9 @@ const (
// defaultRequestTimeout is the default timeout of rkt requests.
// defaultRequestTimeout is the default timeout of rkt requests.
defaultRequestTimeout
=
2
*
time
.
Minute
defaultRequestTimeout
=
2
*
time
.
Minute
etcHostsPath
=
"/etc/hosts"
etcResolvConfPath
=
"/etc/resolv.conf"
)
)
// Runtime implements the Containerruntime for rkt. The implementation
// Runtime implements the Containerruntime for rkt. The implementation
...
@@ -657,27 +660,42 @@ func copyfile(src, dst string) error {
...
@@ -657,27 +660,42 @@ func copyfile(src, dst string) error {
// TODO(yifan): Can make rkt handle this when '--net=host'. See https://github.com/coreos/rkt/issues/2430.
// TODO(yifan): Can make rkt handle this when '--net=host'. See https://github.com/coreos/rkt/issues/2430.
func
makeHostNetworkMount
(
opts
*
kubecontainer
.
RunContainerOptions
)
(
*
kubecontainer
.
Mount
,
*
kubecontainer
.
Mount
,
error
)
{
func
makeHostNetworkMount
(
opts
*
kubecontainer
.
RunContainerOptions
)
(
*
kubecontainer
.
Mount
,
*
kubecontainer
.
Mount
,
error
)
{
hostsPath
:=
filepath
.
Join
(
opts
.
PodContainerDir
,
"etc-hosts"
)
mountHosts
,
mountResolvConf
:=
true
,
true
resolvPath
:=
filepath
.
Join
(
opts
.
PodContainerDir
,
"etc-resolv-conf"
)
for
_
,
mnt
:=
range
opts
.
Mounts
{
switch
mnt
.
ContainerPath
{
if
err
:=
copyfile
(
"/etc/hosts"
,
hostsPath
);
err
!=
nil
{
case
etcHostsPath
:
return
nil
,
nil
,
err
mountHosts
=
false
}
case
etcResolvConfPath
:
if
err
:=
copyfile
(
"/etc/resolv.conf"
,
resolvPath
);
err
!=
nil
{
mountResolvConf
=
false
return
nil
,
nil
,
err
}
}
}
hostsMount
:=
kubecontainer
.
Mount
{
var
hostsMount
,
resolvMount
kubecontainer
.
Mount
Name
:
"kubernetes-hostnetwork-hosts-conf"
,
if
mountHosts
{
ContainerPath
:
"/etc/hosts"
,
hostsPath
:=
filepath
.
Join
(
opts
.
PodContainerDir
,
"etc-hosts"
)
HostPath
:
hostsPath
,
if
err
:=
copyfile
(
etcHostsPath
,
hostsPath
);
err
!=
nil
{
return
nil
,
nil
,
err
}
hostsMount
=
kubecontainer
.
Mount
{
Name
:
"kubernetes-hostnetwork-hosts-conf"
,
ContainerPath
:
etcHostsPath
,
HostPath
:
hostsPath
,
}
opts
.
Mounts
=
append
(
opts
.
Mounts
,
hostsMount
)
}
}
resolvMount
:=
kubecontainer
.
Mount
{
Name
:
"kubernetes-hostnetwork-resolv-conf"
,
if
mountResolvConf
{
ContainerPath
:
"/etc/resolv.conf"
,
resolvPath
:=
filepath
.
Join
(
opts
.
PodContainerDir
,
"etc-resolv-conf"
)
HostPath
:
resolvPath
,
if
err
:=
copyfile
(
etcResolvConfPath
,
resolvPath
);
err
!=
nil
{
return
nil
,
nil
,
err
}
resolvMount
=
kubecontainer
.
Mount
{
Name
:
"kubernetes-hostnetwork-resolv-conf"
,
ContainerPath
:
etcResolvConfPath
,
HostPath
:
resolvPath
,
}
opts
.
Mounts
=
append
(
opts
.
Mounts
,
resolvMount
)
}
}
opts
.
Mounts
=
append
(
opts
.
Mounts
,
hostsMount
,
resolvMount
)
return
&
hostsMount
,
&
resolvMount
,
nil
return
&
hostsMount
,
&
resolvMount
,
nil
}
}
...
...
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