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
c341cee6
Commit
c341cee6
authored
Feb 06, 2016
by
Lantao Liu
Committed by
Random-Liu
Feb 10, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix network configuration
parent
4a386f88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
25 deletions
+38
-25
manager.go
pkg/kubelet/dockertools/manager.go
+38
-25
No files found.
pkg/kubelet/dockertools/manager.go
View file @
c341cee6
...
...
@@ -643,15 +643,6 @@ func (dm *DockerManager) runContainer(
PodUID
:
pod
.
UID
,
ContainerName
:
container
.
Name
,
}
exposedPorts
,
portBindings
:=
makePortsAndBindings
(
opts
.
PortMappings
)
// TODO(vmarmol): Handle better.
// Cap hostname at 63 chars (specification is 64bytes which is 63 chars and the null terminating char).
const
hostnameMaxLen
=
63
containerHostname
:=
pod
.
Name
if
len
(
containerHostname
)
>
hostnameMaxLen
{
containerHostname
=
containerHostname
[
:
hostnameMaxLen
]
}
// Pod information is recorded on the container as labels to preserve it in the event the pod is deleted
// while the Kubelet is down and there is no information available to recover the pod.
...
...
@@ -707,13 +698,13 @@ func (dm *DockerManager) runContainer(
binds
=
append
(
binds
,
b
)
}
}
hc
:=
&
docker
.
HostConfig
{
PortBindings
:
portBindings
,
Binds
:
binds
,
NetworkMode
:
netMode
,
IpcMode
:
ipcMode
,
UTSMode
:
utsMode
,
PidMode
:
pidMode
,
Binds
:
binds
,
NetworkMode
:
netMode
,
IpcMode
:
ipcMode
,
UTSMode
:
utsMode
,
PidMode
:
pidMode
,
// Memory and CPU are set here for newer versions of Docker (1.6+).
Memory
:
memoryLimit
,
MemorySwap
:
-
1
,
...
...
@@ -728,12 +719,6 @@ func (dm *DockerManager) runContainer(
hc
.
CPUPeriod
=
cpuPeriod
}
if
len
(
opts
.
DNS
)
>
0
{
hc
.
DNS
=
opts
.
DNS
}
if
len
(
opts
.
DNSSearch
)
>
0
{
hc
.
DNSSearch
=
opts
.
DNSSearch
}
if
len
(
opts
.
CgroupParent
)
>
0
{
hc
.
CgroupParent
=
opts
.
CgroupParent
}
...
...
@@ -741,10 +726,8 @@ func (dm *DockerManager) runContainer(
dockerOpts
:=
docker
.
CreateContainerOptions
{
Name
:
containerName
,
Config
:
&
docker
.
Config
{
Env
:
makeEnvList
(
opts
.
Envs
),
ExposedPorts
:
exposedPorts
,
Hostname
:
containerHostname
,
Image
:
container
.
Image
,
Env
:
makeEnvList
(
opts
.
Envs
),
Image
:
container
.
Image
,
// Memory and CPU are set here for older versions of Docker (pre-1.6).
Memory
:
memoryLimit
,
MemorySwap
:
-
1
,
...
...
@@ -759,6 +742,11 @@ func (dm *DockerManager) runContainer(
HostConfig
:
hc
,
}
// Set network configuration for infra-container
if
container
.
Name
==
PodInfraContainerName
{
setInfraContainerNetworkConfig
(
pod
,
netMode
,
opts
,
dockerOpts
)
}
setEntrypointAndCommand
(
container
,
opts
,
&
dockerOpts
)
glog
.
V
(
3
)
.
Infof
(
"Container %v/%v/%v: setting entrypoint
\"
%v
\"
and command
\"
%v
\"
"
,
pod
.
Namespace
,
pod
.
Name
,
container
.
Name
,
dockerOpts
.
Config
.
Entrypoint
,
dockerOpts
.
Config
.
Cmd
)
...
...
@@ -783,6 +771,31 @@ func (dm *DockerManager) runContainer(
return
kubecontainer
.
DockerID
(
dockerContainer
.
ID
)
.
ContainerID
(),
nil
}
// setInfraContainerNetworkConfig sets the network configuration for the infra-container. We only set network configuration for infra-container, all
// the user containers will share the same network namespace with infra-container.
func
setInfraContainerNetworkConfig
(
pod
*
api
.
Pod
,
netMode
string
,
opts
*
kubecontainer
.
RunContainerOptions
,
dockerOpts
docker
.
CreateContainerOptions
)
{
exposedPorts
,
portBindings
:=
makePortsAndBindings
(
opts
.
PortMappings
)
dockerOpts
.
Config
.
ExposedPorts
=
exposedPorts
dockerOpts
.
HostConfig
.
PortBindings
=
portBindings
if
netMode
!=
namespaceModeHost
{
// TODO(vmarmol): Handle better.
// Cap hostname at 63 chars (specification is 64bytes which is 63 chars and the null terminating char).
const
hostnameMaxLen
=
63
containerHostname
:=
pod
.
Name
if
len
(
containerHostname
)
>
hostnameMaxLen
{
containerHostname
=
containerHostname
[
:
hostnameMaxLen
]
}
dockerOpts
.
Config
.
Hostname
=
containerHostname
if
len
(
opts
.
DNS
)
>
0
{
dockerOpts
.
HostConfig
.
DNS
=
opts
.
DNS
}
if
len
(
opts
.
DNSSearch
)
>
0
{
dockerOpts
.
HostConfig
.
DNSSearch
=
opts
.
DNSSearch
}
}
}
func
setEntrypointAndCommand
(
container
*
api
.
Container
,
opts
*
kubecontainer
.
RunContainerOptions
,
dockerOpts
*
docker
.
CreateContainerOptions
)
{
command
,
args
:=
kubecontainer
.
ExpandContainerCommandAndArgs
(
container
,
opts
.
Envs
)
...
...
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