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
df4c1ccd
Commit
df4c1ccd
authored
Jan 22, 2016
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't apply net plugins to net=host pods
parent
458eb528
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
40 deletions
+59
-40
manager.go
pkg/kubelet/dockertools/manager.go
+54
-35
manager_test.go
pkg/kubelet/dockertools/manager_test.go
+3
-3
cni.go
pkg/kubelet/network/cni/cni.go
+2
-2
No files found.
pkg/kubelet/dockertools/manager.go
View file @
df4c1ccd
...
@@ -77,6 +77,11 @@ const (
...
@@ -77,6 +77,11 @@ const (
minimumGracePeriodInSeconds
=
2
minimumGracePeriodInSeconds
=
2
DockerNetnsFmt
=
"/proc/%v/ns/net"
DockerNetnsFmt
=
"/proc/%v/ns/net"
// String used to detect docker host mode for various namespaces (e.g.
// networking). Must match the value returned by docker inspect -f
// '{{.HostConfig.NetworkMode}}'.
namespaceModeHost
=
"host"
)
)
// DockerManager implements the Runtime interface.
// DockerManager implements the Runtime interface.
...
@@ -925,8 +930,8 @@ func (dm *DockerManager) podInfraContainerChanged(pod *api.Pod, podInfraContaine
...
@@ -925,8 +930,8 @@ func (dm *DockerManager) podInfraContainerChanged(pod *api.Pod, podInfraContaine
if
dockerPodInfraContainer
.
HostConfig
!=
nil
{
if
dockerPodInfraContainer
.
HostConfig
!=
nil
{
networkMode
=
dockerPodInfraContainer
.
HostConfig
.
NetworkMode
networkMode
=
dockerPodInfraContainer
.
HostConfig
.
NetworkMode
}
}
if
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostNetwork
{
if
usesHostNetwork
(
pod
)
{
if
networkMode
!=
"host"
{
if
networkMode
!=
namespaceModeHost
{
glog
.
V
(
4
)
.
Infof
(
"host: %v, %v"
,
pod
.
Spec
.
SecurityContext
.
HostNetwork
,
networkMode
)
glog
.
V
(
4
)
.
Infof
(
"host: %v, %v"
,
pod
.
Spec
.
SecurityContext
.
HostNetwork
,
networkMode
)
return
true
,
nil
return
true
,
nil
}
}
...
@@ -946,6 +951,11 @@ func (dm *DockerManager) podInfraContainerChanged(pod *api.Pod, podInfraContaine
...
@@ -946,6 +951,11 @@ func (dm *DockerManager) podInfraContainerChanged(pod *api.Pod, podInfraContaine
return
podInfraContainerStatus
.
Hash
!=
kubecontainer
.
HashContainer
(
expectedPodInfraContainer
),
nil
return
podInfraContainerStatus
.
Hash
!=
kubecontainer
.
HashContainer
(
expectedPodInfraContainer
),
nil
}
}
// pod must not be nil
func
usesHostNetwork
(
pod
*
api
.
Pod
)
bool
{
return
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostNetwork
}
// dockerVersion implementes kubecontainer.Version interface by implementing
// dockerVersion implementes kubecontainer.Version interface by implementing
// Compare() and String() (which is implemented by the underlying semver.Version)
// Compare() and String() (which is implemented by the underlying semver.Version)
// TODO: this code is the same as rktVersion and may make sense to be moved to
// TODO: this code is the same as rktVersion and may make sense to be moved to
...
@@ -1326,12 +1336,19 @@ func (dm *DockerManager) killPodWithSyncResult(pod *api.Pod, runningPod kubecont
...
@@ -1326,12 +1336,19 @@ func (dm *DockerManager) killPodWithSyncResult(pod *api.Pod, runningPod kubecont
result
.
AddSyncResult
(
containerResult
)
result
.
AddSyncResult
(
containerResult
)
}
}
if
networkContainer
!=
nil
{
if
networkContainer
!=
nil
{
teardownNetworkResult
:=
kubecontainer
.
NewSyncResult
(
kubecontainer
.
TeardownNetwork
,
kubecontainer
.
BuildPodFullName
(
runningPod
.
Name
,
runningPod
.
Namespace
))
ins
,
err
:=
dm
.
client
.
InspectContainer
(
networkContainer
.
ID
.
ID
)
result
.
AddSyncResult
(
teardownNetworkResult
)
if
err
!=
nil
{
if
err
:=
dm
.
networkPlugin
.
TearDownPod
(
runningPod
.
Namespace
,
runningPod
.
Name
,
kubecontainer
.
DockerID
(
networkContainer
.
ID
.
ID
));
err
!=
nil
{
glog
.
Errorf
(
"Error inspecting container %v: %v"
,
networkContainer
.
ID
.
ID
,
err
)
message
:=
fmt
.
Sprintf
(
"Failed to teardown network for pod %q using network plugins %q: %v"
,
runningPod
.
ID
,
dm
.
networkPlugin
.
Name
(),
err
)
return
teardownNetworkResult
.
Fail
(
kubecontainer
.
ErrTeardownNetwork
,
message
)
}
glog
.
Error
(
message
)
if
ins
.
HostConfig
!=
nil
&&
ins
.
HostConfig
.
NetworkMode
!=
namespaceModeHost
{
teardownNetworkResult
:=
kubecontainer
.
NewSyncResult
(
kubecontainer
.
TeardownNetwork
,
kubecontainer
.
BuildPodFullName
(
runningPod
.
Name
,
runningPod
.
Namespace
))
result
.
AddSyncResult
(
teardownNetworkResult
)
if
err
:=
dm
.
networkPlugin
.
TearDownPod
(
runningPod
.
Namespace
,
runningPod
.
Name
,
kubecontainer
.
DockerID
(
networkContainer
.
ID
.
ID
));
err
!=
nil
{
message
:=
fmt
.
Sprintf
(
"Failed to teardown network for pod %q using network plugins %q: %v"
,
runningPod
.
ID
,
dm
.
networkPlugin
.
Name
(),
err
)
teardownNetworkResult
.
Fail
(
kubecontainer
.
ErrTeardownNetwork
,
message
)
glog
.
Error
(
message
)
}
}
}
killContainerResult
:=
kubecontainer
.
NewSyncResult
(
kubecontainer
.
KillContainer
,
networkContainer
.
Name
)
killContainerResult
:=
kubecontainer
.
NewSyncResult
(
kubecontainer
.
KillContainer
,
networkContainer
.
Name
)
result
.
AddSyncResult
(
killContainerResult
)
result
.
AddSyncResult
(
killContainerResult
)
...
@@ -1512,8 +1529,8 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
...
@@ -1512,8 +1529,8 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
}
}
utsMode
:=
""
utsMode
:=
""
if
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostNetwork
{
if
usesHostNetwork
(
pod
)
{
utsMode
=
"host"
utsMode
=
namespaceModeHost
}
}
id
,
err
:=
dm
.
runContainer
(
pod
,
container
,
opts
,
ref
,
netMode
,
ipcMode
,
utsMode
,
pidMode
,
restartCount
)
id
,
err
:=
dm
.
runContainer
(
pod
,
container
,
opts
,
ref
,
netMode
,
ipcMode
,
utsMode
,
pidMode
,
restartCount
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -1578,7 +1595,7 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
...
@@ -1578,7 +1595,7 @@ func (dm *DockerManager) runContainerInPod(pod *api.Pod, container *api.Containe
// This resolv.conf file is shared by all containers of the same pod, and needs to be modified only once per pod.
// This resolv.conf file is shared by all containers of the same pod, and needs to be modified only once per pod.
// we modify it when the pause container is created since it is the first container created in the pod since it holds
// we modify it when the pause container is created since it is the first container created in the pod since it holds
// the networking namespace.
// the networking namespace.
if
container
.
Name
==
PodInfraContainerName
&&
utsMode
!=
"host"
{
if
container
.
Name
==
PodInfraContainerName
&&
utsMode
!=
namespaceModeHost
{
err
=
addNDotsOption
(
containerInfo
.
ResolvConfPath
)
err
=
addNDotsOption
(
containerInfo
.
ResolvConfPath
)
}
}
...
@@ -1630,8 +1647,8 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubecontainer.Do
...
@@ -1630,8 +1647,8 @@ func (dm *DockerManager) createPodInfraContainer(pod *api.Pod) (kubecontainer.Do
netNamespace
=
"none"
netNamespace
=
"none"
}
}
if
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostNetwork
{
if
usesHostNetwork
(
pod
)
{
netNamespace
=
"host"
netNamespace
=
namespaceModeHost
}
else
{
}
else
{
// Docker only exports ports from the pod infra container. Let's
// Docker only exports ports from the pod infra container. Let's
// collect all of the relevant ports and export them.
// collect all of the relevant ports and export them.
...
@@ -1887,24 +1904,26 @@ func (dm *DockerManager) syncPodWithSyncResult(pod *api.Pod, _ api.PodStatus, po
...
@@ -1887,24 +1904,26 @@ func (dm *DockerManager) syncPodWithSyncResult(pod *api.Pod, _ api.PodStatus, po
setupNetworkResult
:=
kubecontainer
.
NewSyncResult
(
kubecontainer
.
SetupNetwork
,
kubecontainer
.
GetPodFullName
(
pod
))
setupNetworkResult
:=
kubecontainer
.
NewSyncResult
(
kubecontainer
.
SetupNetwork
,
kubecontainer
.
GetPodFullName
(
pod
))
result
.
AddSyncResult
(
setupNetworkResult
)
result
.
AddSyncResult
(
setupNetworkResult
)
// Call the networking plugin
if
!
usesHostNetwork
(
pod
)
{
err
=
dm
.
networkPlugin
.
SetUpPod
(
pod
.
Namespace
,
pod
.
Name
,
podInfraContainerID
)
// Call the networking plugin
if
err
!=
nil
{
err
=
dm
.
networkPlugin
.
SetUpPod
(
pod
.
Namespace
,
pod
.
Name
,
podInfraContainerID
)
// TODO: (random-liu) There shouldn't be "Skipping pod" in sync result message
if
err
!=
nil
{
message
:=
fmt
.
Sprintf
(
"Failed to setup network for pod %q using network plugins %q: %v; Skipping pod"
,
format
.
Pod
(
pod
),
dm
.
networkPlugin
.
Name
(),
err
)
// TODO: (random-liu) There shouldn't be "Skipping pod" in sync result message
setupNetworkResult
.
Fail
(
kubecontainer
.
ErrSetupNetwork
,
message
)
message
:=
fmt
.
Sprintf
(
"Failed to setup network for pod %q using network plugins %q: %v; Skipping pod"
,
format
.
Pod
(
pod
),
dm
.
networkPlugin
.
Name
(),
err
)
glog
.
Error
(
message
)
setupNetworkResult
.
Fail
(
kubecontainer
.
ErrSetupNetwork
,
message
)
glog
.
Error
(
message
)
// Delete infra container
killContainerResult
:=
kubecontainer
.
NewSyncResult
(
kubecontainer
.
KillContainer
,
PodInfraContainerName
)
// Delete infra container
result
.
AddSyncResult
(
killContainerResult
)
killContainerResult
:=
kubecontainer
.
NewSyncResult
(
kubecontainer
.
KillContainer
,
PodInfraContainerName
)
if
delErr
:=
dm
.
KillContainerInPod
(
kubecontainer
.
ContainerID
{
result
.
AddSyncResult
(
killContainerResult
)
ID
:
string
(
podInfraContainerID
),
if
delErr
:=
dm
.
KillContainerInPod
(
kubecontainer
.
ContainerID
{
Type
:
"docker"
},
nil
,
pod
,
message
);
delErr
!=
nil
{
ID
:
string
(
podInfraContainerID
),
killContainerResult
.
Fail
(
kubecontainer
.
ErrKillContainer
,
delErr
.
Error
())
Type
:
"docker"
},
nil
,
pod
,
message
);
delErr
!=
nil
{
glog
.
Warningf
(
"Clear infra container failed for pod %q: %v"
,
format
.
Pod
(
pod
),
delErr
)
killContainerResult
.
Fail
(
kubecontainer
.
ErrKillContainer
,
delErr
.
Error
())
glog
.
Warningf
(
"Clear infra container failed for pod %q: %v"
,
format
.
Pod
(
pod
),
delErr
)
}
return
}
}
return
}
}
// Setup the host interface unless the pod is on the host's network (FIXME: move to networkPlugin when ready)
// Setup the host interface unless the pod is on the host's network (FIXME: move to networkPlugin when ready)
...
@@ -1915,7 +1934,7 @@ func (dm *DockerManager) syncPodWithSyncResult(pod *api.Pod, _ api.PodStatus, po
...
@@ -1915,7 +1934,7 @@ func (dm *DockerManager) syncPodWithSyncResult(pod *api.Pod, _ api.PodStatus, po
result
.
Fail
(
err
)
result
.
Fail
(
err
)
return
return
}
}
if
!
(
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostNetwork
)
{
if
!
usesHostNetwork
(
pod
)
{
if
err
=
hairpin
.
SetUpContainer
(
podInfraContainer
.
State
.
Pid
,
"eth0"
);
err
!=
nil
{
if
err
=
hairpin
.
SetUpContainer
(
podInfraContainer
.
State
.
Pid
,
"eth0"
);
err
!=
nil
{
glog
.
Warningf
(
"Hairpin setup failed for pod %q: %v"
,
format
.
Pod
(
pod
),
err
)
glog
.
Warningf
(
"Hairpin setup failed for pod %q: %v"
,
format
.
Pod
(
pod
),
err
)
}
}
...
@@ -2080,7 +2099,7 @@ func (dm *DockerManager) doBackOff(pod *api.Pod, container *api.Container, podSt
...
@@ -2080,7 +2099,7 @@ func (dm *DockerManager) doBackOff(pod *api.Pod, container *api.Container, podSt
func
getPidMode
(
pod
*
api
.
Pod
)
string
{
func
getPidMode
(
pod
*
api
.
Pod
)
string
{
pidMode
:=
""
pidMode
:=
""
if
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostPID
{
if
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostPID
{
pidMode
=
"host"
pidMode
=
namespaceModeHost
}
}
return
pidMode
return
pidMode
}
}
...
@@ -2089,13 +2108,13 @@ func getPidMode(pod *api.Pod) string {
...
@@ -2089,13 +2108,13 @@ func getPidMode(pod *api.Pod) string {
func
getIPCMode
(
pod
*
api
.
Pod
)
string
{
func
getIPCMode
(
pod
*
api
.
Pod
)
string
{
ipcMode
:=
""
ipcMode
:=
""
if
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostIPC
{
if
pod
.
Spec
.
SecurityContext
!=
nil
&&
pod
.
Spec
.
SecurityContext
.
HostIPC
{
ipcMode
=
"host"
ipcMode
=
namespaceModeHost
}
}
return
ipcMode
return
ipcMode
}
}
// GetNetN
s
returns the network namespace path for the given container
// GetNetN
S
returns the network namespace path for the given container
func
(
dm
*
DockerManager
)
GetNetN
s
(
containerID
kubecontainer
.
ContainerID
)
(
string
,
error
)
{
func
(
dm
*
DockerManager
)
GetNetN
S
(
containerID
kubecontainer
.
ContainerID
)
(
string
,
error
)
{
inspectResult
,
err
:=
dm
.
client
.
InspectContainer
(
containerID
.
ID
)
inspectResult
,
err
:=
dm
.
client
.
InspectContainer
(
containerID
.
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Error inspecting container: '%v'"
,
err
)
glog
.
Errorf
(
"Error inspecting container: '%v'"
,
err
)
...
...
pkg/kubelet/dockertools/manager_test.go
View file @
df4c1ccd
...
@@ -1020,7 +1020,7 @@ func TestSyncPodWithRestartPolicy(t *testing.T) {
...
@@ -1020,7 +1020,7 @@ func TestSyncPodWithRestartPolicy(t *testing.T) {
api
.
RestartPolicyNever
,
api
.
RestartPolicyNever
,
[]
string
{
[]
string
{
// Check the pod infra container.
// Check the pod infra container.
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
"inspect_container"
,
// Stop the last pod infra container.
// Stop the last pod infra container.
"stop"
,
"stop"
,
},
},
...
@@ -1037,10 +1037,10 @@ func TestSyncPodWithRestartPolicy(t *testing.T) {
...
@@ -1037,10 +1037,10 @@ func TestSyncPodWithRestartPolicy(t *testing.T) {
verifyCalls
(
t
,
fakeDocker
,
tt
.
calls
)
verifyCalls
(
t
,
fakeDocker
,
tt
.
calls
)
if
err
:=
fakeDocker
.
AssertCreated
(
tt
.
created
);
err
!=
nil
{
if
err
:=
fakeDocker
.
AssertCreated
(
tt
.
created
);
err
!=
nil
{
t
.
Errorf
(
"
%d
: %v"
,
i
,
err
)
t
.
Errorf
(
"
case [%d]
: %v"
,
i
,
err
)
}
}
if
err
:=
fakeDocker
.
AssertStopped
(
tt
.
stopped
);
err
!=
nil
{
if
err
:=
fakeDocker
.
AssertStopped
(
tt
.
stopped
);
err
!=
nil
{
t
.
Errorf
(
"
%d
: %v"
,
i
,
err
)
t
.
Errorf
(
"
case [%d]
: %v"
,
i
,
err
)
}
}
}
}
}
}
...
...
pkg/kubelet/network/cni/cni.go
View file @
df4c1ccd
...
@@ -106,7 +106,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec
...
@@ -106,7 +106,7 @@ func (plugin *cniNetworkPlugin) SetUpPod(namespace string, name string, id kubec
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"CNI execution called on non-docker runtime"
)
return
fmt
.
Errorf
(
"CNI execution called on non-docker runtime"
)
}
}
netns
,
err
:=
runtime
.
GetNetN
s
(
id
.
ContainerID
())
netns
,
err
:=
runtime
.
GetNetN
S
(
id
.
ContainerID
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -125,7 +125,7 @@ func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id ku
...
@@ -125,7 +125,7 @@ func (plugin *cniNetworkPlugin) TearDownPod(namespace string, name string, id ku
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"CNI execution called on non-docker runtime"
)
return
fmt
.
Errorf
(
"CNI execution called on non-docker runtime"
)
}
}
netns
,
err
:=
runtime
.
GetNetN
s
(
id
.
ContainerID
())
netns
,
err
:=
runtime
.
GetNetN
S
(
id
.
ContainerID
())
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
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